Mon, 25 Apr 2022 18:33:03 +0200
remove createtestdb from build
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" |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
33 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
34 | #include <libxml/tree.h> |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | static WebdavBackend pg_webdav_backend = { |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | pg_dav_propfind_init, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | pg_dav_propfind_do, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | pg_dav_propfind_finish, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | pg_dav_proppatch_do, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | pg_dav_proppatch_finish, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | NULL, // opt_mkcol |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | NULL, // opt_mkcol_finish |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | NULL, // opt_delete |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | NULL, // opt_delete_finish |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | 0, |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
47 | NULL, |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | NULL |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | }; |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
51 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
52 | /* |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
53 | * SQL Queries |
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 | // propfind with depth = 0 |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
57 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
58 | static const char *sql_propfind_allprop_depth0 = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
59 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
60 | $2::text as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
61 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
62 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
63 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
64 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
65 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
66 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
67 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
68 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
69 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
70 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
71 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
72 | 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
|
73 | where r.resource_id = $1;"; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
74 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
75 | // propfind with depth = 0 for specific properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
76 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
77 | static const char *sql_propfind_depth0 = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
78 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
79 | $2::text as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
80 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
81 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
82 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
83 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
84 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
85 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
86 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
87 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
88 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
89 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
90 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
91 | left join Property p on r.resource_id = p.resource_id\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
92 | inner join (select unnest($3::text[]) as xmlns, unnest($4::text[]) as pname) n\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
93 | on ( p.xmlns = n.xmlns and p.pname = n.pname ) or p.property_id is null\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
94 | where r.resource_id = $1;"; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
95 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
96 | // propfind with depth = 1 |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
97 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
98 | static const char *sql_propfind_allprop_depth1 = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
99 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
100 | 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
|
101 | else $2 || '/' || r.nodename\n\ |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
102 | end as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
103 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
104 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
105 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
106 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
107 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
108 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
109 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
110 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
111 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
112 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
113 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
114 | 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
|
115 | where r.resource_id = $1 or r.parent_id = $1\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
116 | order by order by case when resource_id = $1 then 0 else 1 end, nodename, resource_id;"; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
117 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
118 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
119 | // propfind with depth = 1 for specific properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
120 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
121 | static const char *sql_propfind_depth1 = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
122 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
123 | 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
|
124 | else $2 || '/' || r.nodename\n\ |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
125 | end as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
126 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
127 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
128 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
129 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
130 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
131 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
132 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
133 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
134 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
135 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
136 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
137 | left join Property p on r.resource_id = p.resource_id\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
138 | inner join (select unnest($3::text[]) as xmlns, unnest($4::text[]) as pname) n\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
139 | on ( p.xmlns = n.xmlns and p.pname = n.pname ) or p.property_id is null\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
140 | where r.resource_id = $1 or r.parent_id = $1\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
141 | order by order by case when resource_id = $1 then 0 else 1 end, nodename, resource_id;"; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
142 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
143 | // recursive propfind |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
144 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
145 | static const char *sql_propfind_allprop_recursive = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
146 | with recursive resolvepath as (\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
147 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
148 | '' as ppath,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
149 | *\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
150 | from Resource\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
151 | where resource_id = $1 \n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
152 | union\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
153 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
154 | p.ppath || '/' || r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
155 | r.*\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
156 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
157 | 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
|
158 | )\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
159 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
160 | 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
|
161 | else $2 || r.ppath\n\ |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
162 | end as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
163 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
164 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
165 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
166 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
167 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
168 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
169 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
170 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
171 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
172 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
173 | from resolvepath r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
174 | 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
|
175 | 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
|
176 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
177 | // recursive propfind for specific properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
178 | // params: $1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
179 | // $2: array of property xmlns |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
180 | // $3: array of property names |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
181 | static const char *sql_propfind_recursive = "\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
182 | with recursive resolvepath as (\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
183 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
184 | '' as ppath,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
185 | *\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
186 | from Resource\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
187 | where resource_id = $1 \n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
188 | union\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
189 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
190 | p.ppath || '/' || r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
191 | r.*\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
192 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
193 | 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
|
194 | )\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
195 | select\n\ |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
196 | 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
|
197 | else $2 || '/' || r.ppath\n\ |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
198 | end as ppath,\n\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
199 | r.resource_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
200 | r.parent_id,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
201 | r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
202 | r.iscollection,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
203 | r.lastmodified,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
204 | r.creationdate,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
205 | r.contentlength,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
206 | p.xmlns,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
207 | p.pname,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
208 | p.pvalue\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
209 | from resolvepath r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
210 | 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
|
211 | inner join (select unnest($2::text[]) as xmlns, unnest($3::text[]) as pname) n\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
212 | on ( p.xmlns = n.xmlns and p.pname = n.pname ) or p.property_id is null\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
213 | 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
|
214 | |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
215 | 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
|
216 | // resourcepool is required |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
217 | char *resource_pool = pblock_findval("resourcepool", pb); |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
218 | if(!resource_pool) { |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
219 | 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
|
220 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
221 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
222 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
223 | // 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
|
224 | 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
|
225 | if(!resdata) { |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
226 | 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
|
227 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
228 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
229 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
230 | 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
|
231 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
232 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
233 | 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
|
234 | WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend)); |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
235 | if(!webdav) { |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
236 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
237 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
238 | *webdav = pg_webdav_backend; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
239 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
240 | 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
|
241 | if(!instance) { |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
242 | pool_free(sn->pool, webdav); |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
243 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
244 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
245 | webdav->instance = instance; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
246 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
247 | instance->pg_resource = resdata; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
248 | instance->connection = resdata->data; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
249 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
250 | return webdav; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
251 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
252 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
253 | 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
|
254 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
255 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
256 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
257 | |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | int pg_dav_propfind_init( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | WebdavPropfindRequest *rq, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | const char *path, |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
261 | const char *href, |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | WebdavPList **outplist) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
264 | PgWebdavBackend *pgdav = rq->dav->instance; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
265 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
266 | // check if the resource exists |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
267 | int64_t parent_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
268 | int64_t resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
269 | const char *resourcename; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
270 | WSBool iscollection; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
271 | int res_errno = 0; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
272 | int err = pg_resolve_path( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
273 | pgdav->connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
274 | path, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
275 | &parent_id, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
276 | &resource_id, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
277 | NULL, // OID |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
278 | &resourcename, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
279 | &iscollection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
280 | NULL, // stat |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
281 | &res_errno); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
282 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
283 | if(err) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
284 | if(res_errno == ENOENT) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
285 | 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
|
286 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
287 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
288 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
289 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
290 | // choose sql query |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
291 | const char *query = NULL; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
292 | if(!iscollection || rq->depth == 0) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
293 | 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
|
294 | } else if(rq->depth == 1) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
295 | 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
|
296 | } else if(rq->depth == -1) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
297 | 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
|
298 | } else { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
299 | 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
|
300 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
301 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
302 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
303 | // get all resources and properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
304 | char resource_id_str[32]; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
305 | 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
|
306 | |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
307 | size_t href_len = strlen(href); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
308 | 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
|
309 | memcpy(href_param, href, href_len); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
310 | if(href_param[href_len-1] == '/') { |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
311 | href_len--; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
312 | } |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
313 | href_param[href_len] = '\0'; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
314 | |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
315 | |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
316 | const char* params[2] = { resource_id_str, href_param }; |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
317 | PGresult *result = PQexecParams( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
318 | pgdav->connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
319 | sql_propfind_allprop_recursive, |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
320 | 2, // number of parameters |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
321 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
322 | params, // parameter value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
323 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
324 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
325 | 0); // 0: result in text format |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
326 | int nrows = PQntuples(result); |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
327 | pool_free(rq->sn->pool, href_param); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
328 | if(nrows < 1) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
329 | PQclear(result); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
330 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
331 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
332 | |
300
0e3f275b2492
add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
333 | 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
|
334 | rq->userdata = pg; |
0e3f275b2492
add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
335 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
336 | pg->path = path; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
337 | pg->resource_id = resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
338 | 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
|
339 | pg->result = result; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
340 | pg->nrows = nrows; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
341 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
342 | return 0; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | int pg_dav_propfind_do( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | WebdavPropfindRequest *rq, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | WebdavResponse *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | VFS_DIR parent, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | WebdavResource *resource, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | struct stat *s) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
352 | PgPropfind *pg = rq->userdata; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
353 | pool_handle_t *pool = rq->sn->pool; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
354 | PGresult *result = pg->result; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
355 | WebdavVFSProperties vfsprops = pg->vfsproperties; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
356 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
357 | WSBool vfsprops_set = 0; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
358 | 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
|
359 | 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
|
360 | // columns: |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
361 | // 0: path |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
362 | // 1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
363 | // 2: parent_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
364 | // 3: nodename |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
365 | // 4: iscollection |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
366 | // 5: lastmodified |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
367 | // 6: creationdate |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
368 | // 7: contentlength |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
369 | // 8: property xmlns |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
370 | // 9: property name |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
371 | // 10: property value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
372 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
373 | char *path = PQgetvalue(result, r, 0); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
374 | 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
|
375 | char *iscollection_str = PQgetvalue(result, r, 4); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
376 | 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
|
377 | int64_t resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
378 | if(!util_strtoint(res_id, &resource_id)) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
379 | 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
|
380 | return 1; |
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 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
383 | char *nodename = PQgetvalue(result, r, 3); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
384 | if(resource_id != current_resource_id) { |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
385 | // 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
|
386 | // 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
|
387 | size_t pathlen = strlen(path); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
388 | if(pathlen == 0) { |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
389 | 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
|
390 | return 1; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
391 | } |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
392 | 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
|
393 | memcpy(newres_href, path, pathlen); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
394 | if(iscollection && path[pathlen-1] != '/') { |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
395 | newres_href[pathlen++] = '/'; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
396 | } |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
397 | newres_href[pathlen] = '\0'; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
398 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
399 | // new resource |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
400 | resource = response->addresource(response, newres_href); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
401 | vfsprops_set = FALSE; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
402 | current_resource_id = resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
403 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
404 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
405 | // standard webdav properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
406 | if(!vfsprops_set) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
407 | if(vfsprops.getresourcetype) { |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
408 | if(iscollection) { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
409 | resource->addproperty(resource, webdav_resourcetype_collection(), 200); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
410 | } else { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
411 | resource->addproperty(resource, webdav_resourcetype_empty(), 200); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
412 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
413 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
414 | if(vfsprops.getlastmodified) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
415 | char *lastmodified = PQgetvalue(result, r, 5); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
416 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
417 | if(vfsprops.creationdate) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
418 | char *creationdate = PQgetvalue(result, r, 6); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
419 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
420 | if(vfsprops.getcontentlength) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
421 | char *contentlength = PQgetvalue(result, r, 7); |
309
fc021bd576d4
implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
307
diff
changeset
|
422 | 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
|
423 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
424 | if(vfsprops.getetag) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
425 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
426 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
427 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
428 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
429 | vfsprops_set = TRUE; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
430 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
431 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
432 | // dead properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
433 | if(!PQgetisnull(result, r, 9)) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
434 | char *xmlns = PQgetvalue(result, r, 8); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
435 | char *pname = PQgetvalue(result, r, 9); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
436 | char *pvalue = PQgetvalue(result, r, 10); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
437 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
438 | WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
439 | property->lang = NULL; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
440 | property->name = pool_strdup(pool, pname); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
441 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
442 | xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs)); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
443 | memset(namespace, 0, sizeof(struct _xmlNs)); |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
444 | namespace->href = (xmlChar*)pool_strdup(pool, xmlns); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
445 | namespace->prefix = (xmlChar*)"zx1"; // TODO |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
446 | property->namespace = namespace; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
447 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
448 | property->vtype = WS_VALUE_TEXT; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
449 | property->value.text.str = pool_strdup(pool, pvalue); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
450 | property->value.text.length = strlen(pvalue); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
451 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
452 | resource->addproperty(resource, property, 200); |
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 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
455 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
456 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
457 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
458 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
459 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
460 | return 0; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | int pg_dav_propfind_finish(WebdavPropfindRequest *rq) { |
306
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_proppatch_do( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | WebdavProppatchRequest *request, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | WebdavResource *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | VFSFile *file, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | WebdavPList **out_set, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | WebdavPList **out_remove) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | { |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | return 1; |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | int pg_dav_proppatch_finish( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | WebdavProppatchRequest *request, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | WebdavResource *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | VFSFile *file, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | WSBool commit) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | { |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | return 1; |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | } |