Fri, 29 Nov 2024 18:10:26 +0100
fix wrong column name usage by pg prop extensions
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2022 Olaf Wintermann. All rights reserved. |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "webdav.h" |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
30 | #include "vfs.h" |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
31 | #include "config.h" |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
32 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
33 | #include "../../util/util.h" |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
34 | #include "../../util/pblock.h" |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
35 | |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
36 | #include "../../daemon/http.h" // etag |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
37 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
38 | #include <cx/buffer.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
39 | #include <cx/utils.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
40 | #include <cx/printf.h> |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
41 | #include <libxml/tree.h> |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
43 | |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | static WebdavBackend pg_webdav_backend = { |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | pg_dav_propfind_init, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | pg_dav_propfind_do, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | pg_dav_propfind_finish, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | pg_dav_proppatch_do, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | pg_dav_proppatch_finish, |
479
2a42ba73ecdd
add new xattr based webdav backend (unimplemented)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
50 | NULL, // opt_mkcol |
2a42ba73ecdd
add new xattr based webdav backend (unimplemented)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
51 | NULL, // opt_mkcol_finish |
2a42ba73ecdd
add new xattr based webdav backend (unimplemented)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
52 | NULL, // opt_delete |
2a42ba73ecdd
add new xattr based webdav backend (unimplemented)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
53 | NULL, // opt_delete_finish |
2a42ba73ecdd
add new xattr based webdav backend (unimplemented)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
54 | 0, // settings |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
55 | NULL, |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | NULL |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | }; |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
59 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
60 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
61 | /* |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
62 | * SQL query components |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
63 | */ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
64 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
65 | /* |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
66 | * PROPFIND queries are build from components: |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
67 | * |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
68 | * cte cte_recursive or empty |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
69 | * select |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
70 | * ppath ppath column |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
71 | * cols list of columns |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
72 | * ext_cols* list of extension columns |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
73 | * from from [table] / from cte |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
74 | * prop_join join with property table, allprop or plist |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
75 | * ext_join* extension table join |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
76 | * where different where clauses for depth0 and depth1 |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
77 | * order depth0 doesn't need order |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
78 | */ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
79 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
80 | static const char *sql_propfind_cte_recursive = "\ |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
81 | with recursive resolvepath as (\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
82 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
83 | '' as ppath,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
84 | *\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
85 | from Resource\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
86 | where resource_id = $1 \n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
87 | union\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
88 | select\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
89 | p.ppath || '/' || r.nodename,\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
90 | r.*\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
91 | from Resource r\n\ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
92 | inner join resolvepath p on r.parent_id = p.resource_id\n\ |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
93 | )\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
94 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
95 | static const char *sql_propfind_select = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
96 | select\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
97 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
98 | static const char *sql_propfind_ppath_depth0 = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
99 | $2::text as ppath,\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
100 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
101 | static const char *sql_propfind_ppath_depth1 = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
102 | case when r.resource_id = $1 then $2\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
103 | else $2 || '/' || r.nodename\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
104 | end as ppath,\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
105 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
106 | static const char *sql_propfind_ppath_depth_infinity = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
107 | case when r.resource_id = $1 then $2\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
108 | else $2 || r.ppath\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
109 | end as ppath,\n"; |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
110 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
111 | static const char *sql_propfind_cols = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
112 | r.resource_id,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
113 | r.parent_id,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
114 | r.nodename,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
115 | r.iscollection,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
116 | r.lastmodified,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
117 | r.creationdate,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
118 | r.contentlength,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
119 | r.etag,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
120 | p.prefix,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
121 | p.xmlns,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
122 | p.pname,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
123 | p.lang,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
124 | p.nsdeflist,\n\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
125 | p.pvalue\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
126 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
127 | static const char *sql_propfind_from_table = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
128 | from Resource r\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
129 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
130 | static const char *sql_propfind_from_cte = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
131 | from resolvepath r\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
132 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
133 | static const char *sql_propfind_propjoin_allprop = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
134 | left join Property p on r.resource_id = p.resource_id\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
135 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
136 | static const char *sql_propfind_propjoin_plist = "\ |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
137 | left join (\n\ |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
138 | select p.* from Property p\ |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
139 | 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
|
140 | on p.xmlns = n.xmlns and p.pname = n.pname\n\ |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
141 | ) p on r.resource_id = p.resource_id\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
142 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
143 | static const char *sql_propfind_where_depth0 = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
144 | where r.resource_id = $1\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
145 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
146 | static const char *sql_propfind_where_depth1 = "\ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
147 | where r.resource_id = $1 or r.parent_id = $1\n"; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
148 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
149 | static const char *sql_propfind_order_depth1 = "\ |
401
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
150 | order by case when r.resource_id = $1 then 0 else 1 end, r.nodename, r.resource_id"; |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
151 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
152 | static const char *sql_propfind_order_depth_infinity = "\ |
401
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
153 | order by replace(ppath, '/', chr(1)), r.resource_id"; |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
154 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
155 | /* |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
156 | * SQL Queries |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
157 | */ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
158 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
159 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
160 | // proppatch: set property |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
161 | // params: $1: resource_id |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
162 | // $2: xmlns prefix |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
163 | // $3: xmlns href |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
164 | // $4: property name |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
165 | // $5: lang attribute value |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
166 | // $6: namespace list string |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
167 | // $7: property value |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
168 | static const char *sql_proppatch_set = "\ |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
169 | 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
|
170 | 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
|
171 | on conflict (resource_id, xmlns, pname) do\n\ |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
172 | 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
|
173 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
174 | // proppatch: remove property |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
175 | // params: $1: resource_id |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
176 | // $2: xmlns href |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
177 | // $3: property name |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
178 | static const char *sql_proppatch_remove = "\ |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
179 | 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
|
180 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
181 | |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
182 | void* pg_webdav_init(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config) { |
372
1d2538a1ba8f
add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
183 | return pg_init_repo(cfg, pool, config); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
184 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
185 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
186 | WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb, void *initData) { |
370
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
187 | PgRepository *repo = initData; |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
188 | |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
189 | char *resource_pool; |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
190 | if(repo) { |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
191 | resource_pool = repo->resourcepool.ptr; |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
192 | } else { |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
193 | // resourcepool is required |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
194 | resource_pool = pblock_findval("resourcepool", pb); |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
195 | if(!resource_pool) { |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
196 | log_ereport(LOG_MISCONFIG, "pg_webdav_create: missing resourcepool parameter"); |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
197 | return NULL; |
d6d8c86c95c3
adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
198 | } |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
199 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
200 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
201 | // 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
|
202 | 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
|
203 | if(!resdata) { |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
204 | 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
|
205 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
206 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
207 | |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
208 | return pg_webdav_create_from_resdata(sn, rq, repo, resdata); |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
209 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
210 | |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
211 | WebdavBackend* pg_webdav_create_from_resdata(Session *sn, Request *rq, PgRepository *repo, ResourceData *resdata) { |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
212 | WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend)); |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
213 | if(!webdav) { |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
214 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
215 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
216 | *webdav = pg_webdav_backend; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
217 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
218 | 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
|
219 | if(!instance) { |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
220 | pool_free(sn->pool, webdav); |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
221 | return NULL; |
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 | webdav->instance = instance; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
224 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
225 | instance->pg_resource = resdata; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
226 | instance->connection = resdata->data; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
227 | |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
228 | instance->repository = repo; |
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
229 | snprintf(instance->root_resource_id_str, 32, "%" PRId64, repo->root_resource_id); |
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
230 | |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
231 | return webdav; |
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 | |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
234 | 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
|
235 | return NULL; |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
236 | } |
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
237 | |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
238 | /* |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
239 | * adds str to the buffer |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
240 | * some characters will be escaped: \,{} |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
241 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
242 | static void buf_addstr_escaped(CxBuffer *buf, const char *str) { |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
243 | size_t len = strlen(str); |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
244 | 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
|
245 | char c = str[i]; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
246 | if(c == '{' || c == '}' || c == ',' || c == '\\') { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
247 | cxBufferPut(buf, '\\'); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
248 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
249 | cxBufferPut(buf, c); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
250 | } |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
251 | } |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
252 | |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
253 | /* |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
254 | * 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
|
255 | * array format: {elm1,elm2,elm3} |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
256 | * xmlns: buffer for the xmlns array |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
257 | * 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
|
258 | * |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
259 | * returns 0 on success, 1 otherwise |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
260 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
261 | int pg_create_property_param_arrays(WebdavPList *plist, CxBuffer *xmlns, CxBuffer *pname) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
262 | cxBufferPut(xmlns, '{'); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
263 | cxBufferPut(pname, '{'); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
264 | while(plist) { |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
265 | WebdavProperty *property = plist->property; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | if(plist->next) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
270 | cxBufferPut(xmlns, ','); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
271 | cxBufferPut(pname, ','); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
272 | } |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
273 | } |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
274 | plist = plist->next; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
275 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
276 | int r1 = cxBufferWrite("}\0", 2, 1, xmlns) == 0; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
277 | int r2 = cxBufferWrite("}\0", 2, 1, pname) == 0; |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
278 | return r1+r2 != 0; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
279 | } |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
280 | |
303
ad9ba51c8634
add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
300
diff
changeset
|
281 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
282 | static int propfind_ext_cmp(const void *f1, const void *f2) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
283 | const PgPropfindExtCol *e1 = f1; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
284 | const PgPropfindExtCol *e2 = f2; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
285 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
286 | if(e1->ext->tableindex != e2->ext->tableindex) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
287 | return e1->ext->tableindex < e2->ext->tableindex ? -1 : 1; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
288 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
289 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
290 | return 0; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
291 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
292 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
293 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
294 | static int pg_create_propfind_query( |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
295 | WebdavPropfindRequest *rq, |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
296 | WSBool iscollection, |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
297 | PgPropfindExtCol *ext, |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
298 | size_t numext, |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
299 | CxBuffer *sql) |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
300 | { |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
301 | PgWebdavBackend *pgdav = rq->dav->instance; |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
302 | PgRepository *repo = pgdav->repository; |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
303 | int depth = !iscollection ? 0 : rq->depth; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
304 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
305 | /* |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
306 | * PROPFIND queries are build from components: |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
307 | * |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
308 | * cte cte_recursive or empty |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
309 | * select |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
310 | * ppath ppath column |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
311 | * cols list of columns |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
312 | * ext_cols* list of extension columns |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
313 | * from from [table] / from cte |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
314 | * prop_join join with property table, allprop or plist |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
315 | * ext_join* extension table join |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
316 | * where different where clauses for depth0 and depth1 |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
317 | * order depth0 doesn't need order |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
318 | */ |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
319 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
320 | // CTE |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
321 | if(depth == -1) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
322 | cxBufferPutString(sql, sql_propfind_cte_recursive); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
323 | } |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
324 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
325 | // select |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
326 | cxBufferPutString(sql, sql_propfind_select); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
327 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
328 | // ppath |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
329 | switch(depth) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
330 | case 0: cxBufferPutString(sql, sql_propfind_ppath_depth0); break; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
331 | case 1: cxBufferPutString(sql, sql_propfind_ppath_depth1); break; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
332 | case -1: cxBufferPutString(sql, sql_propfind_ppath_depth_infinity); break; |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
333 | } |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
334 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
335 | // cols |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
336 | cxBufferPutString(sql, sql_propfind_cols); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
337 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
338 | // ext_cols |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
339 | if(ext) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
340 | if(rq->allprop) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
341 | for(int i=0;i<repo->ntables;i++) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
342 | cx_bprintf(sql, ",x%d.*\n", i); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
343 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
344 | } else { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
345 | for(int i=0;i<numext;i++) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
346 | PgPropfindExtCol e = ext[i]; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
347 | cx_bprintf(sql, ",x%d.%s\n", e.ext->tableindex, e.ext->column); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
348 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
349 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
350 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
351 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
352 | // from |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
353 | cxBufferPutString(sql, depth == -1 ? sql_propfind_from_cte : sql_propfind_from_table); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
354 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
355 | // prop join |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
356 | cxBufferPutString(sql, rq->allprop ? sql_propfind_propjoin_allprop : sql_propfind_propjoin_plist); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
357 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
358 | // ext_join |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
359 | if(ext) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
360 | if(rq->allprop) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
361 | for(int i=0;i<repo->ntables;i++) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
362 | cx_bprintf(sql, "left join %s x%d on r.resource_id = x%d.resource_id\n", repo->tables[i].table, i, i); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
363 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
364 | } else { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
365 | int tab = -1; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
366 | for(int i=0;i<numext;i++) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
367 | PgPropfindExtCol e = ext[i]; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
368 | if(e.ext->tableindex != tab) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
369 | tab = e.ext->tableindex; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
370 | cx_bprintf(sql, "left join %s x%d on r.resource_id = x%d.resource_id\n", repo->tables[tab].table, tab, tab); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
371 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
372 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
373 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
374 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
375 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
376 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
377 | // where |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
378 | if(depth == 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
379 | cxBufferPutString(sql, sql_propfind_where_depth0); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
380 | } else if(depth == 1) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
381 | cxBufferPutString(sql, sql_propfind_where_depth1); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
382 | } |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
383 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
384 | // order |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
385 | if(depth == 1) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
386 | cxBufferPutString(sql, sql_propfind_order_depth1); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
387 | } else if(depth == -1) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
388 | cxBufferPutString(sql, sql_propfind_order_depth_infinity); |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
389 | } |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
390 | |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
391 | // end |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
392 | cxBufferWrite(";\0", 1, 2, sql); |
401
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
393 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
394 | return 0; |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
395 | } |
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
396 | |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | int pg_dav_propfind_init( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | WebdavPropfindRequest *rq, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | const char *path, |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
400 | const char *href, |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | WebdavPList **outplist) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
403 | PgWebdavBackend *pgdav = rq->dav->instance; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
404 | CxAllocator *a = pool_allocator(rq->sn->pool); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
405 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
406 | // first, check if the resource exists |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
407 | // if it doesn't exist, we can return immediately |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
408 | int64_t parent_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
409 | int64_t resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
410 | const char *resourcename; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
411 | WSBool iscollection; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
412 | int res_errno = 0; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
413 | int err = pg_resolve_path( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
414 | pgdav->connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
415 | path, |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
416 | pgdav->root_resource_id_str, |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
417 | &parent_id, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
418 | &resource_id, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
419 | NULL, // OID |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
420 | &resourcename, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
421 | &iscollection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
422 | NULL, // stat |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
423 | NULL, // etag |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
424 | &res_errno); |
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 | if(err) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
427 | if(res_errno == ENOENT) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
428 | 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
|
429 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
430 | return 1; |
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 | |
380
0f85d9bde309
pg propfind stores resource_id in rq->vars
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
433 | // store resource_id in rq->vars, maybe some other modules |
0f85d9bde309
pg propfind stores resource_id in rq->vars
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
434 | // like to use it |
0f85d9bde309
pg propfind stores resource_id in rq->vars
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
435 | char resource_id_str[32]; |
0f85d9bde309
pg propfind stores resource_id in rq->vars
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
436 | snprintf(resource_id_str, 32, "%" PRId64, resource_id); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
437 | pblock_nvinsert("resource_id", resource_id_str, rq->rq->vars); |
380
0f85d9bde309
pg propfind stores resource_id in rq->vars
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
438 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
439 | // create a list of requsted extended properties |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
440 | PgPropfindExtCol *ext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
441 | size_t numext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
442 | if(pgdav->repository->ntables == 0) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
443 | // no property extensions configured |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
444 | ext = NULL; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
445 | numext = 0; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
446 | } else { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
447 | numext = pgdav->repository->prop_ext->size; |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
448 | ext = pool_calloc(rq->sn->pool, numext, sizeof(PgPropfindExtCol)); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
449 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
450 | if(rq->allprop) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
451 | // the map pgdav->repository->prop_ext contains all property extensions |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
452 | // we can just convert the map to an array |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
453 | CxIterator i = cxMapIteratorValues(pgdav->repository->prop_ext); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
454 | int j = 0; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
455 | cx_foreach(PgPropertyStoreExt *, cfg_ext, i) { |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
456 | PgPropfindExtCol extcol; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
457 | extcol.ext = cfg_ext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
458 | extcol.field_num = -1; // get the field_num after the PQexec |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
459 | ext[j++] = extcol; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
460 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
461 | } else { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
462 | WebdavPListIterator i = webdav_plist_iterator(outplist); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
463 | WebdavPList *cur; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
464 | int j = 0; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
465 | while(webdav_plist_iterator_next(&i, &cur)) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
466 | WSNamespace *ns = cur->property->namespace; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
467 | if(ns) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
468 | CxHashKey pkey = webdav_property_key((const char*)ns->href, cur->property->name); |
490 | 469 | if(!pkey.data) { |
470 | return 1; | |
471 | } | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
472 | PgPropertyStoreExt *cfg_ext = cxMapGet(pgdav->repository->prop_ext, pkey); |
490 | 473 | free((void*)pkey.data); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
474 | if(cfg_ext) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
475 | PgPropfindExtCol extcol; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
476 | extcol.ext = cfg_ext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
477 | extcol.field_num = -1; // get the field_num after the PQexec |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
478 | ext[j++] = extcol; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
479 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
480 | webdav_plist_iterator_remove_current(&i); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
481 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
482 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
483 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
484 | numext = j; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
485 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
486 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
487 | qsort(ext, numext, sizeof(PgPropfindExtCol), propfind_ext_cmp); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
488 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
489 | |
375
32b8017f5308
build pg propfind query from components
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
490 | // create sql query |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
491 | const char *query = NULL; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
492 | CxBuffer sql; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
493 | if(cxBufferInit(&sql, NULL, 2048, a, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
494 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
495 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
496 | |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
497 | if(pg_create_propfind_query(rq, iscollection, ext, numext, &sql)) { |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
498 | cxBufferDestroy(&sql); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
499 | return 1; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
500 | } |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
501 | query = sql.space; |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
502 | log_ereport(LOG_DEBUG, "pg_dav_propfind_init query: %.*s\n", (int)sql.size, sql.space); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
503 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
504 | // get all resources and properties |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
505 | size_t href_len = strlen(href); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
506 | 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
|
507 | memcpy(href_param, href, href_len); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
508 | if(href_param[href_len-1] == '/') { |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
509 | href_len--; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
510 | } |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
511 | href_param[href_len] = '\0'; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
512 | |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
513 | // if allprop is false, create array pair for xmlns/property names |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
514 | CxBuffer xmlns_buf; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
515 | CxBuffer pname_buf; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
516 | WSBool buf_initialized = FALSE; |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
517 | char *xmlns_param = NULL; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
518 | char *pname_param = NULL; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
519 | int nparam = 2; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
520 | if(!rq->allprop) { |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
521 | size_t bufsize = rq->propcount < 200 ? 8 + rq->propcount * 32 : 4096; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
522 | if(cxBufferInit(&xmlns_buf, NULL, bufsize, a, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
523 | return 1; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
524 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
525 | if(cxBufferInit(&pname_buf, NULL, bufsize, a, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
526 | cxBufferDestroy(&sql); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
527 | cxBufferDestroy(&xmlns_buf); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
528 | return 1; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
529 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
530 | if(pg_create_property_param_arrays(*outplist, &xmlns_buf, &pname_buf)) { |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
531 | cxBufferDestroy(&sql); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
532 | cxBufferDestroy(&xmlns_buf); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
533 | cxBufferDestroy(&pname_buf); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
534 | return 1; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
535 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
536 | buf_initialized = TRUE; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
537 | xmlns_param = xmlns_buf.space; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
538 | pname_param = pname_buf.space; |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
539 | nparam = 4; |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
540 | } |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
541 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
542 | |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
543 | |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
544 | 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
|
545 | PGresult *result = PQexecParams( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
546 | pgdav->connection, |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
547 | query, |
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
548 | nparam, // number of parameters |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
549 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
550 | params, // parameter value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
551 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
552 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
553 | 0); // 0: result in text format |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
554 | int nrows = PQntuples(result); |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
555 | pool_free(rq->sn->pool, href_param); |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
556 | cxBufferDestroy(&sql); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
557 | if(buf_initialized) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
558 | cxBufferDestroy(&xmlns_buf); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
559 | cxBufferDestroy(&pname_buf); |
315
b608b7aa43a6
fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
560 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
561 | if(nrows < 1) { |
401
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
562 | // we resolved the path, so the resource exists and nrows should |
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
563 | // be >= 1 |
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
564 | if(PQresultStatus(result) != PGRES_TUPLES_OK) { |
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
565 | log_ereport(LOG_FAILURE, "pg_dav_propfind_init: %s", PQerrorMessage(pgdav->connection)); |
d2bfd11d3f8f
fix invalid propfind pg queries created for allprop requests on collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
384
diff
changeset
|
566 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
567 | PQclear(result); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
568 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
569 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
570 | |
300
0e3f275b2492
add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
571 | 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
|
572 | rq->userdata = pg; |
0e3f275b2492
add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
573 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
574 | pg->path = path; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
575 | pg->resource_id = resource_id; |
331
ab26980faad6
implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
324
diff
changeset
|
576 | pg->vfsproperties = webdav_vfs_properties(outplist, TRUE, rq->allprop, 0); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
577 | pg->result = result; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
578 | pg->nrows = nrows; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
579 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
580 | pg->ext = ext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
581 | pg->numext = numext; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
582 | if(ext) { |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
583 | // build a map of all ext field names (excluding first fields from |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
584 | // the resource and property table) |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
585 | int nfields = PQnfields(result); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
586 | CxMap *fieldmap = cxHashMapCreate(pool_allocator(rq->sn->pool), sizeof(int), nfields); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
587 | if(!fieldmap) { |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
588 | PQclear(result); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
589 | return 1; |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
590 | } |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
591 | // start with index 15 (see pg_dav_propfind_do for first column nums) |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
592 | for(int i=15;i<nfields;i++) { |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
593 | char *name = PQfname(result, i); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
594 | if(name) { |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
595 | if(cxMapPut(fieldmap, name, &i)) { |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
596 | PQclear(result); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
597 | return 1; |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
598 | } |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
599 | } |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
600 | } |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
601 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
602 | // get field_nums for all property extensions |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
603 | for(int i=0;i<numext;i++) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
604 | PgPropfindExtCol *c = &ext[i]; |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
605 | //c->field_num = PQfnumber(result, c->ext->column); |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
606 | int *fieldnum = cxMapGet(fieldmap, c->ext->column); |
564
f19fd264c69c
fix wrong column name usage by pg prop extensions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
562
diff
changeset
|
607 | if(fieldnum) { |
f19fd264c69c
fix wrong column name usage by pg prop extensions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
562
diff
changeset
|
608 | c->field_num = *fieldnum; |
f19fd264c69c
fix wrong column name usage by pg prop extensions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
562
diff
changeset
|
609 | } |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
610 | } |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
611 | |
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
612 | cxMapDestroy(fieldmap); |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
613 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
614 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
615 | return 0; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618 | int pg_dav_propfind_do( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | WebdavPropfindRequest *rq, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | WebdavResponse *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621 | VFS_DIR parent, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622 | WebdavResource *resource, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623 | struct stat *s) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624 | { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
625 | PgPropfind *pg = rq->userdata; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
626 | pool_handle_t *pool = rq->sn->pool; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
627 | PGresult *result = pg->result; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
628 | WebdavVFSProperties vfsprops = pg->vfsproperties; |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
629 | |
313
3ad0b65ec838
test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
630 | WSBool vfsprops_set = 0; // are live properties added to the response? |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
631 | WSBool extprops_set = 0; // are extended properties added to the response? |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
632 | 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
|
633 | 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
|
634 | // columns: |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
635 | // 0: path |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
636 | // 1: resource_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
637 | // 2: parent_id |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
638 | // 3: nodename |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
639 | // 4: iscollection |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
640 | // 5: lastmodified |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
641 | // 6: creationdate |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
642 | // 7: contentlength |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
643 | // 8: etag |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
644 | // 9: property prefix |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
645 | // 10: property xmlns |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
646 | // 11: property name |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
647 | // 12: property lang |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
648 | // 13: property nsdeflist |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
649 | // 14: property value |
562
69fc4ecc5f60
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
553
diff
changeset
|
650 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
651 | char *path = PQgetvalue(result, r, 0); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
652 | 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
|
653 | char *iscollection_str = PQgetvalue(result, r, 4); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
654 | 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
|
655 | int64_t resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
656 | if(!util_strtoint(res_id, &resource_id)) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
657 | 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
|
658 | return 1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
659 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
660 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
661 | if(resource_id != current_resource_id) { |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
662 | // 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
|
663 | // 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
|
664 | size_t pathlen = strlen(path); |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
665 | if(pathlen == 0) { |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
666 | 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
|
667 | return 1; |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
668 | } |
356
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
669 | if(pathlen > PG_MAX_PATH_LEN) { |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
670 | log_ereport(LOG_FAILURE, "pg_dav_propfind_do: path too long: resource_id: %s", res_id); |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
671 | return 1; |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
672 | } |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
673 | char *newres_href = pool_malloc(pool, (pathlen*3)+2); |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
674 | util_uri_escape(newres_href, path); |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
675 | if(iscollection && path[pathlen-1] != '/') { |
356
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
676 | size_t newres_href_len = strlen(newres_href); |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
677 | newres_href[newres_href_len] = '/'; |
eebc3d32c7c1
escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
348
diff
changeset
|
678 | newres_href[newres_href_len+1] = '\0'; |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
679 | } |
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
680 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
681 | // new resource |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
682 | resource = response->addresource(response, newres_href); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
683 | vfsprops_set = FALSE; |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
684 | extprops_set = FALSE; |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
685 | current_resource_id = resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
686 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
687 | |
313
3ad0b65ec838
test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
688 | // standard webdav live properties |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
689 | if(!vfsprops_set) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
690 | if(vfsprops.getresourcetype) { |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
691 | if(iscollection) { |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
692 | resource->addproperty(resource, webdav_resourcetype_collection(), 200); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
693 | } else { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
694 | resource->addproperty(resource, webdav_resourcetype_empty(), 200); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
695 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
696 | } |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
697 | |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
698 | char *lastmodified = PQgetvalue(result, r, 5); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
699 | char *contentlength = PQgetvalue(result, r, 7); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
700 | time_t t = pg_convert_timestamp(lastmodified); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
701 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
702 | if(vfsprops.getlastmodified) { |
311
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
703 | struct tm tm; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
704 | gmtime_r(&t, &tm); |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
705 | |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
706 | char buf[HTTP_DATE_LEN+1]; |
e676ed461b5b
implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
309
diff
changeset
|
707 | 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
|
708 | 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
|
709 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
710 | if(vfsprops.creationdate) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
711 | 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
|
712 | 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
|
713 | } |
314
6b1a6066ee43
fix pg propfind for getlastmodified property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
313
diff
changeset
|
714 | if(vfsprops.getcontentlength && !iscollection) { |
309
fc021bd576d4
implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
307
diff
changeset
|
715 | 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
|
716 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
717 | if(vfsprops.getetag) { |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
718 | char *etag = PQgetvalue(result, r, 8); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
719 | if(!PQgetisnull(result, r, 8)) { |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
720 | webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag)); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
721 | } else { |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
722 | int64_t ctlen; |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
723 | if(util_strtoint(contentlength, &ctlen)) { |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
724 | char etag[MAX_ETAG]; |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
725 | http_format_etag(rq->sn, rq->rq, etag, MAX_ETAG, ctlen, t); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
726 | webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag)); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
727 | } |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
728 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
729 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
730 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
731 | vfsprops_set = TRUE; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
732 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
733 | |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
734 | if(!extprops_set) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
735 | // extended properties |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
736 | if(pg->ext) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
737 | for(int extc=0;extc<pg->numext;extc++) { |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
738 | PgPropfindExtCol ext = pg->ext[extc]; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
739 | int fieldnum = ext.field_num; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
740 | |
564
f19fd264c69c
fix wrong column name usage by pg prop extensions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
562
diff
changeset
|
741 | if(fieldnum >= 0 && !PQgetisnull(result, r, fieldnum)) { |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
742 | char *ext_value = PQgetvalue(result, r, fieldnum); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
743 | int ext_value_len = PQgetlength(result, r, fieldnum); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
744 | char ext_xmlns_prefix[32]; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
745 | snprintf(ext_xmlns_prefix, 32, "x%d", ext.ext->tableindex); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
746 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
747 | WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
748 | property->lang = NULL; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
749 | property->name = pool_strdup(pool, ext.ext->name); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
750 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
751 | xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs)); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
752 | memset(namespace, 0, sizeof(struct _xmlNs)); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
753 | namespace->href = (xmlChar*)pool_strdup(pool, ext.ext->ns); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
754 | namespace->prefix = (xmlChar*)pool_strdup(pool, ext_xmlns_prefix); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
755 | property->namespace = namespace; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
756 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
757 | char *content = pool_malloc(pool, ext_value_len+1); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
758 | memcpy(content, ext_value, ext_value_len); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
759 | content[ext_value_len] = '\0'; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
760 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
761 | WebdavNSList *nslist = pool_malloc(pool, sizeof(WebdavNSList)); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
762 | nslist->namespace = namespace; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
763 | nslist->prev = NULL; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
764 | nslist->next = NULL; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
765 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
766 | property->vtype = WS_VALUE_XML_DATA; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
767 | property->value.data.data = content; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
768 | property->value.data.length = ext_value_len; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
769 | property->value.data.namespaces = nslist; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
770 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
771 | resource->addproperty(resource, property, 200); |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
772 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
773 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
774 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
775 | |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
776 | extprops_set = TRUE; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
777 | } |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
778 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
779 | // dead properties |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
780 | if(!PQgetisnull(result, r, 9)) { |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
781 | char *prefix = PQgetvalue(result, r, 9); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
782 | char *xmlns = PQgetvalue(result, r, 10); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
783 | char *pname = PQgetvalue(result, r, 11); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
784 | char *lang = PQgetvalue(result, r, 12); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
785 | char *nsdef = PQgetvalue(result, r, 13); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
786 | char *pvalue = PQgetvalue(result, r, 14); |
317
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
787 | |
348
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
788 | int pvalue_len = PQgetlength(result, r, 14); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
789 | WSBool lang_isnull = PQgetisnull(result, r, 12); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
790 | WSBool nsdef_isnull = PQgetisnull(result, r, 13); |
bdd31584141f
implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
346
diff
changeset
|
791 | WSBool pvalue_isnull = PQgetisnull(result, r, 14); |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
792 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
793 | WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty)); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
794 | property->lang = NULL; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
795 | property->name = pool_strdup(pool, pname); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
796 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
797 | xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs)); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
798 | memset(namespace, 0, sizeof(struct _xmlNs)); |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
799 | 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
|
800 | 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
|
801 | property->namespace = namespace; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
802 | |
317
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
803 | if(!lang_isnull) { |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
804 | property->lang = pool_strdup(pool, lang); |
317
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
805 | } |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
806 | |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
807 | if(!pvalue_isnull) { |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
808 | 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
|
809 | memcpy(content, pvalue, pvalue_len); |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
810 | content[pvalue_len] = '\0'; |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
811 | |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
812 | if(nsdef_isnull) { |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
813 | property->vtype = WS_VALUE_TEXT; |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
814 | property->value.text.str = content; |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
815 | property->value.text.length = pvalue_len; |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
816 | } else { |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
817 | WebdavNSList *nslist = wsxml_string2nslist(pool, nsdef); |
324
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
818 | property->vtype = WS_VALUE_XML_DATA; |
376
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
819 | property->value.data.data = content; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
820 | property->value.data.length = pvalue_len; |
61d481d3c2e4
Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
375
diff
changeset
|
821 | property->value.data.namespaces = nslist; |
324
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
822 | |
317
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
823 | } |
09676b559091
store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
315
diff
changeset
|
824 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
825 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
826 | resource->addproperty(resource, property, 200); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
827 | } |
313
3ad0b65ec838
test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
312
diff
changeset
|
828 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
829 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
830 | return 0; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | int pg_dav_propfind_finish(WebdavPropfindRequest *rq) { |
312
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
834 | PgPropfind *pg = rq->userdata; |
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
835 | pool_handle_t *pool = rq->sn->pool; |
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
836 | PGresult *result = pg->result; |
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
837 | |
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
838 | PQclear(result); |
f7544e220a0f
add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
311
diff
changeset
|
839 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
303
diff
changeset
|
840 | return 0; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
843 | enum PgDavProp { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
844 | PG_DAV_PROPPATCH_NOT_ALLOWED = 0, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
845 | PG_DAV_CREATIONDATE, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
846 | PG_DAV_DISPLAYNAME, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
847 | PG_DAV_DEADPROP |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
848 | }; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
849 | /* |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
850 | * checks if the property can be manipulated |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
851 | */ |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
852 | 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
|
853 | if(!strcmp(name, "getlastmodified")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
854 | return PG_DAV_PROPPATCH_NOT_ALLOWED; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
855 | } else if(!strcmp(name, "getcontentlength")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
856 | return PG_DAV_PROPPATCH_NOT_ALLOWED; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
857 | } else if(!strcmp(name, "resourcetype")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
858 | return PG_DAV_PROPPATCH_NOT_ALLOWED; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
859 | } else if(!strcmp(name, "getetag")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
860 | return PG_DAV_PROPPATCH_NOT_ALLOWED; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
861 | } else if(!strcmp(name, "creationdate")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
862 | return PG_DAV_CREATIONDATE; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
863 | } else if(!strcmp(name, "displayname")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
864 | return PG_DAV_DISPLAYNAME; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
865 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
866 | return PG_DAV_DEADPROP; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
867 | } |
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 | typedef struct { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
870 | WebdavProperty *creationdate; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
871 | WebdavProperty *displayname; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
872 | int error; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
873 | } PgProppatchOpResult; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
874 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
875 | 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
|
876 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
877 | /* |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
878 | * This function iterates the property list 'plist', |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
879 | * 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
|
880 | * and calls opfunc for the each property |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
881 | * |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
882 | * 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
|
883 | * 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
|
884 | */ |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
885 | static PgProppatchOpResult pg_proppatch_op( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
886 | PgWebdavBackend *pgdav, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
887 | WebdavProppatchRequest *request, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
888 | WebdavResource *response, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
889 | WebdavPList **plist, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
890 | enum PgDavProp forbidden_extra, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
891 | pg_proppatch_func opfunc, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
892 | void *op_userdata) |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
893 | { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
894 | PgProppatchOpResult result; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
895 | result.creationdate = NULL; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
896 | result.displayname = NULL; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
897 | result.error = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
898 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
899 | WebdavPListIterator i = webdav_plist_iterator(plist); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
900 | WebdavPList *cur; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
901 | while(webdav_plist_iterator_next(&i, &cur)) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
902 | WebdavProperty *property = cur->property; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
903 | WSNamespace *ns = property->namespace; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
904 | if(!ns) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
905 | continue; // maybe we should abort |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
906 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
907 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
908 | // 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
|
909 | // handling |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
910 | // get* properties can't be manipulated |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
911 | // some properties can't be removed |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
912 | if(!strcmp((const char*)ns->href, "DAV:")) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
913 | const char *name = property->name; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
914 | enum PgDavProp davprop = proppatch_check_dav_prop(name); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
915 | if(davprop != PG_DAV_DEADPROP) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
916 | 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
|
917 | response->addproperty(response, property, 409); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
918 | } else if(davprop == PG_DAV_CREATIONDATE) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
919 | result.creationdate = property; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
920 | } else if(davprop == PG_DAV_DISPLAYNAME) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
921 | result.displayname = property; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
922 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
923 | webdav_plist_iterator_remove_current(&i); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
924 | continue; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
925 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
926 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
927 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
928 | // call op func (set, remove specific code) |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
929 | if(opfunc(pgdav, request, response, property, op_userdata)) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
930 | result.error = 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
931 | break; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
932 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
933 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
934 | webdav_plist_iterator_remove_current(&i); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
935 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
936 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
937 | return result; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
938 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
939 | |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
940 | |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
941 | static PgPropertyStoreExt* pg_proppatch_prop_get_ext(PgWebdavBackend *pgdav, WebdavProperty *property) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
942 | CxHashKey pkey = webdav_property_key((const char*)property->namespace->href, property->name); |
490 | 943 | if(!pkey.data) { |
944 | return NULL; | |
945 | } | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
946 | PgPropertyStoreExt *ext = cxMapGet(pgdav->repository->prop_ext, pkey); |
490 | 947 | free((void*)pkey.data); |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
948 | return ext; |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
949 | } |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
950 | |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
951 | #define PG_PROPPATCH_EXT_SET 0 |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
952 | #define PG_PROPPATCH_EXT_REMOVE 1 |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
953 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
954 | static int pg_proppatch_add_ext_prop( |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
955 | pool_handle_t *pool, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
956 | PgWebdavBackend *pgdav, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
957 | PgProppatch *proppatch, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
958 | WebdavProperty *property, |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
959 | PgPropertyStoreExt *ext, |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
960 | int proppatch_op) |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
961 | { |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
962 | PgProppatchExtProp *ext_prop = pool_malloc(pool, sizeof(PgProppatchExtProp)); |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
963 | if(!ext_prop) { |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
964 | return 1; |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
965 | } |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
966 | ext_prop->column = ext; |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
967 | ext_prop->property = property; |
553
a166a15f7b74
fix pg ext uninitialized memory acces - fixes #420
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
968 | ext_prop->next = NULL; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
969 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
970 | CxAllocator *a = pool_allocator(pool); |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
971 | proppatch->ext[ext->tableindex].isused = TRUE; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
972 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
973 | PgProppatchExtProp **list_begin; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
974 | PgProppatchExtProp **list_end; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
975 | if(proppatch_op == PG_PROPPATCH_EXT_SET) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
976 | list_begin = &proppatch->ext[ext->tableindex].set_begin; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
977 | list_end = &proppatch->ext[ext->tableindex].set_end; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
978 | } else { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
979 | list_begin = &proppatch->ext[ext->tableindex].remove_begin; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
980 | list_end = &proppatch->ext[ext->tableindex].remove_end; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
981 | } |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
982 | |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
983 | cx_linked_list_add((void**)list_begin, (void**)list_end, -1, offsetof(PgProppatchExtProp, next), ext_prop); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
984 | |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
985 | proppatch->extensions_used = TRUE; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
986 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
987 | return 0; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
988 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
989 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
990 | static int pg_dav_set_property( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
991 | PgWebdavBackend *pgdav, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
992 | WebdavProppatchRequest *request, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
993 | WebdavResource *response, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
994 | WebdavProperty *property, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
995 | void *userdata) |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
996 | { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
997 | pool_handle_t *pool = request->sn->pool; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
998 | PgProppatch *proppatch = request->userdata; |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
999 | WSNamespace *ns = property->namespace; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1000 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1001 | // check if the property belongs to an extension |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1002 | if(proppatch->ext && ns) { |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1003 | PgPropertyStoreExt *ext = pg_proppatch_prop_get_ext(pgdav, property); |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1004 | if(ext) { |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1005 | return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, ext, PG_PROPPATCH_EXT_SET); |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1006 | } // else: property is not stored in an extension table, continue with normal property store |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1007 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1008 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1009 | char *resource_id_str = userdata; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1010 | int ret = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1011 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1012 | // convert the property value to WSXmlData |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1013 | // 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
|
1014 | WSXmlData *property_value = property->vtype == WS_VALUE_XML_NODE ? wsxml_node2data(pool, property->value.node) : NULL; |
324
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1015 | char *value_str = NULL; |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1016 | char *nsdef_str = NULL; |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1017 | if(property_value) { |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1018 | value_str = property_value->data; |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1019 | if(property_value->namespaces) { |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1020 | nsdef_str = wsxml_nslist2string(pool, property_value->namespaces); |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1021 | if(!nsdef_str) { |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1022 | return 1; // OOM |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1023 | } |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1024 | } |
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1025 | } |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1026 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1027 | // exec sql |
324
44cf877b3d9f
add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1028 | const char* params[7] = { resource_id_str, (const char*)ns->prefix, (const char*)ns->href, property->name, NULL, nsdef_str, value_str}; |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1029 | PGresult *result = PQexecParams( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1030 | pgdav->connection, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1031 | sql_proppatch_set, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1032 | 7, // number of parameters |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1033 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1034 | params, // parameter value |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1035 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1036 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1037 | 0); // 0: result in text format |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1038 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1039 | if(PQresultStatus(result) != PGRES_COMMAND_OK) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1040 | response->addproperty(response, property, 500); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1041 | //printf(PQerrorMessage(pgdav->connection)); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1042 | //fflush(stdout); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1043 | ret = 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1044 | } else { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1045 | response->addproperty(response, property, 200); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1046 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1047 | PQclear(result); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1048 | if(value_str) pool_free(pool, value_str); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1049 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1050 | return ret; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1051 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1052 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1053 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1054 | static int pg_dav_remove_property( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1055 | PgWebdavBackend *pgdav, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1056 | WebdavProppatchRequest *request, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1057 | WebdavResource *response, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1058 | WebdavProperty *property, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1059 | void *userdata) |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1060 | { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1061 | pool_handle_t *pool = request->sn->pool; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1062 | PgProppatch *proppatch = request->userdata; |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1063 | WSNamespace *ns = property->namespace; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1064 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1065 | // check if the property belongs to an extension |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1066 | if(proppatch->ext && ns) { |
402
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1067 | PgPropertyStoreExt *ext = pg_proppatch_prop_get_ext(pgdav, property); |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1068 | if(ext) { |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1069 | return pg_proppatch_add_ext_prop(pool, pgdav, proppatch, property, ext, PG_PROPPATCH_EXT_REMOVE); |
712aca08da7f
pg: fix proppatch not working for normal dead properties if extensions are enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
401
diff
changeset
|
1070 | } // else: property is not stored in an extension table, continue with normal property store |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1071 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1072 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1073 | char *resource_id_str = userdata; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1074 | int ret = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1075 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1076 | // exec sql |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1077 | 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
|
1078 | PGresult *result = PQexecParams( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1079 | pgdav->connection, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1080 | sql_proppatch_remove, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1081 | 3, // number of parameters |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1082 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1083 | params, // parameter value |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1084 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1085 | NULL, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1086 | 0); // 0: result in text format |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1087 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1088 | if(PQresultStatus(result) != PGRES_COMMAND_OK) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1089 | response->addproperty(response, property, 500); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1090 | //printf(PQerrorMessage(pgdav->connection)); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1091 | //fflush(stdout); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1092 | ret = 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1093 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1094 | PQclear(result); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1095 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1096 | return ret; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1097 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1098 | |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1099 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1100 | /* |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1101 | * Creates an SQL query for inserting a new row to an extension table |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1102 | * A parameter list for PQexecParams will also be generated, however |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1103 | * params[0] will be empty (resource_id str) |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1104 | * |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1105 | * Query: insert into <table> (resource_id, col1, ...) values ($1, $2 ...); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1106 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1107 | static CxBuffer* ext_row_create_insert_query(WebdavProppatchRequest *request, PgProppatchExt *ext, PgExtTable *table, char *** params, size_t *nparams) { |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1108 | pool_handle_t *pool = request->sn->pool; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1109 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1110 | CxBuffer *sql = pool_malloc(pool, sizeof(CxBuffer)); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1111 | if(!sql) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1112 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1113 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1114 | if(cxBufferInit(sql, NULL, 1024, pool_allocator(pool), CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1115 | pool_free(pool, sql); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1116 | return NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1117 | } |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1118 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1119 | size_t pg_nparams = cx_linked_list_size(ext->set_begin, offsetof(PgProppatchExtProp, next)) + 1; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1120 | char** pg_params = pool_calloc(pool, pg_nparams, sizeof(char*)); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1121 | if(!pg_params) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1122 | cxBufferDestroy(sql); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1123 | pool_free(pool, sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1124 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1125 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1126 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1127 | cxBufferPutString(sql, "insert into "); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1128 | cxBufferPutString(sql, table->table); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1129 | cxBufferPutString(sql, "(resource_id"); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1130 | for(PgProppatchExtProp *prop=ext->set_begin;prop;prop=prop->next) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1131 | cx_bprintf(sql, ",%s", prop->column->name); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1132 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1133 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1134 | cxBufferPutString(sql, ") values ($1\n"); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1135 | int i = 1; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1136 | for(PgProppatchExtProp *prop=ext->set_begin;prop;prop=prop->next) { |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1137 | WebdavProperty *property = prop->property; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1138 | // convert the property value to WSXmlData |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1139 | // property->vtype == WS_VALUE_XML_NODE should always be true |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1140 | WSXmlData *property_value = property->vtype == WS_VALUE_XML_NODE ? wsxml_node2data(pool, property->value.node) : NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1141 | char *value_str = NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1142 | //char *nsdef_str = NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1143 | if(property_value) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1144 | value_str = property_value->data; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1145 | if(property_value->namespaces) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1146 | // currently only text data is supported |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1147 | pool_free(pool, params); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1148 | cxBufferDestroy(sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1149 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1150 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1151 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1152 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1153 | pg_params[i] = value_str; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1154 | cx_bprintf(sql, ",$%d", ++i); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1155 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1156 | cxBufferPutString(sql, ");"); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1157 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1158 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1159 | //printf("\n\n%.*s\n\n", (int)sql->size, sql->space); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1160 | //fflush(stdout); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1161 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1162 | *params = pg_params; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1163 | *nparams = pg_nparams; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1164 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1165 | return sql; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1166 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1167 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1168 | /* |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1169 | * Creates an SQL query for updating an extension table row |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1170 | * A parameter list for PQexecParams will also be generated, however |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1171 | * params[0] will be empty (resource_id str) |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1172 | * |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1173 | * Query: update <table> set |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1174 | * col1 = $2, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1175 | * col2 = $3, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1176 | * ... |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1177 | * where resource_id = $1 ; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1178 | */ |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1179 | static CxBuffer* ext_row_create_update_query(WebdavProppatchRequest *request, PgProppatchExt *ext, PgExtTable *table, char *** params, size_t *nparams) { |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1180 | pool_handle_t *pool = request->sn->pool; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1181 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1182 | CxBuffer *sql = pool_malloc(pool, sizeof(CxBuffer)); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1183 | if(!sql) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1184 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1185 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1186 | if(cxBufferInit(sql, NULL, 1024, pool_allocator(pool), CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1187 | pool_free(pool, sql); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1188 | return NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1189 | } |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1190 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1191 | cxBufferPutString(sql, "update "); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1192 | cxBufferPutString(sql, table->table); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1193 | cxBufferPutString(sql, " set\n"); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1194 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1195 | size_t pg_nparams = cx_linked_list_size(ext->set_begin, offsetof(PgProppatchExtProp, next)) + 1; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1196 | char** pg_params = pool_calloc(pool, pg_nparams, sizeof(char*)); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1197 | if(!pg_params) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1198 | cxBufferDestroy(sql); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1199 | pool_free(pool, sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1200 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1201 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1202 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1203 | int i = 1; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1204 | for(PgProppatchExtProp *prop=ext->set_begin;prop;prop=prop->next) { |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1205 | WebdavProperty *property = prop->property; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1206 | // convert the property value to WSXmlData |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1207 | // property->vtype == WS_VALUE_XML_NODE should always be true |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1208 | WSXmlData *property_value = property->vtype == WS_VALUE_XML_NODE ? wsxml_node2data(pool, property->value.node) : NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1209 | char *value_str = NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1210 | //char *nsdef_str = NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1211 | if(property_value) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1212 | value_str = property_value->data; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1213 | if(property_value->namespaces) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1214 | // currently only text data is supported |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1215 | pool_free(pool, params); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1216 | cxBufferDestroy(sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1217 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1218 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1219 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1220 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1221 | pg_params[i] = value_str; |
564
f19fd264c69c
fix wrong column name usage by pg prop extensions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
562
diff
changeset
|
1222 | cx_bprintf(sql, " %s = $%d,\n", prop->column->column, ++i); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1223 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1224 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1225 | for(PgProppatchExtProp *prop=ext->remove_begin;prop;prop=prop->next) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1226 | cx_bprintf(sql, " %s = NULL,\n", prop->column->name); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1227 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1228 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1229 | // check if any write worked |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1230 | if(sql->pos == 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1231 | cxBufferDestroy(sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1232 | pool_free(pool, pg_params); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1233 | return NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1234 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1235 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1236 | // last line should end with ',' '\n' |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1237 | // replace ',' with space |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1238 | if(sql->space[sql->pos-2] == ',') { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1239 | sql->space[sql->pos-2] = ' '; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1240 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1241 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1242 | cxBufferPutString(sql, "where resource_id = $1 ;"); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1243 | cxBufferPut(sql, '\0'); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1244 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1245 | //printf("\n\n%.*s\n\n", (int)sql->size, sql->space); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1246 | //fflush(stdout); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1247 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1248 | *params = pg_params; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1249 | *nparams = pg_nparams; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1250 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1251 | return sql; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1252 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1253 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1254 | /* |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1255 | * Executes an SQL insert for the extension table |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1256 | */ |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1257 | int ext_row_insert(WebdavProppatchRequest *request, PgProppatchExt *ext, PgExtTable *table) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1258 | PgWebdavBackend *pgdav = request->dav->instance; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1259 | PgProppatch *proppatch = request->userdata; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1260 | pool_handle_t *pool = request->sn->pool; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1261 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1262 | char **params; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1263 | size_t nparam; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1264 | CxBuffer *sql = ext_row_create_insert_query(request, ext, table, ¶ms, &nparam); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1265 | if(!sql) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1266 | return 1; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1267 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1268 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1269 | char resource_id_str[32]; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1270 | snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1271 | params[0] = resource_id_str; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1272 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1273 | PGresult *result = PQexecParams( |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1274 | pgdav->connection, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1275 | sql->space, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1276 | nparam, // number of parameters |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1277 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1278 | ( const char *const *)params, // parameter value |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1279 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1280 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1281 | 0); // 0: result in text format |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1282 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1283 | cxBufferDestroy(sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1284 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1285 | int ret = 1; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1286 | if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1287 | // command ok, check if any row was updated |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1288 | char *nrows_affected = PQcmdTuples(result); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1289 | if(nrows_affected[0] == '1') { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1290 | ret = 0; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1291 | } else { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1292 | log_ereport(LOG_FAILURE, "pg: extension row insert failed"); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1293 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1294 | } else { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1295 | log_ereport(LOG_FAILURE, "pg: extension row insert failed: %s", PQresultErrorMessage(result)); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1296 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1297 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1298 | PQclear(result); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1299 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1300 | return ret; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1301 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1302 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1303 | /* |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1304 | * Executes an SQL update for the extension table |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1305 | */ |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1306 | int ext_row_update(WebdavProppatchRequest *request, PgProppatchExt *ext, PgExtTable *table) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1307 | PgWebdavBackend *pgdav = request->dav->instance; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1308 | PgProppatch *proppatch = request->userdata; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1309 | pool_handle_t *pool = request->sn->pool; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1310 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1311 | char **params; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1312 | size_t nparam; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1313 | CxBuffer *sql = ext_row_create_update_query(request, ext, table, ¶ms, &nparam); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1314 | if(!sql) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1315 | return 1; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1316 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1317 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1318 | char resource_id_str[32]; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1319 | snprintf(resource_id_str, 32, "%" PRId64, proppatch->resource_id); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1320 | params[0] = resource_id_str; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1321 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1322 | PGresult *result = PQexecParams( |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1323 | pgdav->connection, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1324 | sql->space, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1325 | nparam, // number of parameters |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1326 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1327 | ( const char *const *)params, // parameter value |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1328 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1329 | NULL, |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1330 | 0); // 0: result in text format |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1331 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
1332 | cxBufferDestroy(sql); |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1333 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1334 | int ret = 1; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1335 | if(PQresultStatus(result) == PGRES_COMMAND_OK) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1336 | // command ok, check if any row was updated |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1337 | char *nrows_affected = PQcmdTuples(result); |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1338 | if(nrows_affected[0] == '1') { |
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1339 | ret = 0; |
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1340 | } else if(nrows_affected[0] == '0') { |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1341 | // no rows affected, that means we have to insert a new row |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1342 | // in the extension table for this resource |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1343 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1344 | // TODO: cleanup params |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1345 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1346 | ret = ext_row_insert(request, ext, table); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1347 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1348 | } else { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1349 | log_ereport(LOG_FAILURE, "pg: extension row update failed: %s", PQresultErrorMessage(result)); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1350 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1351 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1352 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1353 | PQclear(result); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1354 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1355 | return ret; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1356 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1357 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1358 | static int pg_dav_update_extension_tables(WebdavProppatchRequest *request) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1359 | PgWebdavBackend *pgdav = request->dav->instance; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1360 | PgProppatch *proppatch = request->userdata; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1361 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1362 | for(int i=0;i<proppatch->numext;i++) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1363 | if(proppatch->ext[i].isused) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1364 | if(ext_row_update(request, &proppatch->ext[i], &pgdav->repository->tables[i])) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1365 | // extension proppatch failed |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1366 | return 1; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1367 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1368 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1369 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1370 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1371 | return 0; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1372 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1373 | |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1374 | int pg_dav_proppatch_do( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1375 | WebdavProppatchRequest *request, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1376 | WebdavResource *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1377 | VFSFile *file, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1378 | WebdavPList **out_set, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1379 | WebdavPList **out_remove) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1380 | { |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1381 | PgWebdavBackend *pgdav = request->dav->instance; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1382 | pool_handle_t *pool = request->sn->pool; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1383 | 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
|
1384 | |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1385 | PgProppatch proppatch; |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1386 | proppatch.extensions_used = FALSE; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1387 | if(pgdav->repository->ntables == 0) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1388 | proppatch.ext = NULL; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1389 | proppatch.numext = 0; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1390 | } else { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1391 | // some properties are stored in additional tables |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1392 | // for each table we create a PgProppatchExt record |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1393 | // which stores data about, which tables are used |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1394 | // and which properties (columns) should be updated |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1395 | // |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1396 | // proppatch.ext[i] should contain the data for repository->tables[i] |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1397 | proppatch.numext = pgdav->repository->ntables; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1398 | proppatch.ext = pool_calloc(request->sn->pool, proppatch.numext, sizeof(PgProppatchExt)); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1399 | if(!proppatch.ext) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1400 | return 1; // OOM |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1401 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1402 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1403 | request->userdata = &proppatch; |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1404 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1405 | // 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
|
1406 | int64_t parent_id; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1407 | int64_t resource_id; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1408 | const char *resourcename; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1409 | WSBool iscollection; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1410 | int res_errno = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1411 | int err = pg_resolve_path( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1412 | pgdav->connection, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1413 | path, |
374
77506ec632a4
use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
1414 | pgdav->root_resource_id_str, |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1415 | &parent_id, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1416 | &resource_id, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1417 | NULL, // OID |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1418 | &resourcename, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1419 | &iscollection, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1420 | NULL, // stat |
346
784b24381bed
extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
331
diff
changeset
|
1421 | NULL, // etag |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1422 | &res_errno); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1423 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1424 | if(err) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1425 | return 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1426 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1427 | |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1428 | proppatch.resource_id = resource_id; |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1429 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1430 | // 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
|
1431 | // 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
|
1432 | // we need the possibility to reverse all changes |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1433 | // we use a transaction savepoint for this |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1434 | PGresult *result = PQexec(pgdav->connection, "savepoint proppatch;"); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1435 | ExecStatusType execStatus = PQresultStatus(result); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1436 | PQclear(result); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1437 | if(execStatus != PGRES_COMMAND_OK) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1438 | return 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1439 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1440 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1441 | char resource_id_str[32]; |
378
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1442 | snprintf(resource_id_str, 32, "%" PRId64, resource_id); |
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1443 | // store the resource_id in rq->vars, because it could be useful later |
0344108db255
make original proppatch property list available to all backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
377
diff
changeset
|
1444 | pblock_nvinsert("resource_id", resource_id_str, request->rq->vars); |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1445 | |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1446 | int ret = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1447 | PgProppatchOpResult set_res = pg_proppatch_op( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1448 | pgdav, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1449 | request, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1450 | response, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1451 | out_set, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1452 | PG_DAV_PROPPATCH_NOT_ALLOWED, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1453 | pg_dav_set_property, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1454 | resource_id_str); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1455 | if(set_res.error) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1456 | return 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1457 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1458 | PgProppatchOpResult rm_res = pg_proppatch_op( |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1459 | pgdav, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1460 | request, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1461 | response, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1462 | out_remove, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1463 | PG_DAV_CREATIONDATE, // creationdate can't be removed |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1464 | pg_dav_remove_property, |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1465 | resource_id_str); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1466 | if(rm_res.error) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1467 | return 1; |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1468 | } |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1469 | |
377
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1470 | // if extensions are in use and pg_proppatch_op found any |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1471 | // properties, that should be stored in extension tables |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1472 | // we do the update/insert now |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1473 | if(proppatch.extensions_used) { |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1474 | ret = pg_dav_update_extension_tables(request); |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1475 | } |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1476 | |
c011bc2b3143
Add support for extended properties in pg proppatch
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
376
diff
changeset
|
1477 | |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1478 | return ret; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1479 | } |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1480 | |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1481 | int pg_dav_proppatch_finish( |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1482 | WebdavProppatchRequest *request, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1483 | WebdavResource *response, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1484 | VFSFile *file, |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1485 | WSBool commit) |
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1486 | { |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1487 | PgWebdavBackend *pgdav = request->dav->instance; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1488 | int ret = 0; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1489 | if(!commit) { |
382
9e2289c77b04
disable pg large object IO functions for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
380
diff
changeset
|
1490 | log_ereport(LOG_VERBOSE, "proppatch: rollback"); |
318
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1491 | 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
|
1492 | if(PQresultStatus(result) != PGRES_COMMAND_OK) { |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1493 | 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
|
1494 | ret = 1; |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1495 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1496 | PQclear(result); |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1497 | } |
60870dbac94f
add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
1498 | return ret; |
299
f927ef81a12b
add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1499 | } |