src/server/plugins/postgresql/config.c

Sat, 24 Sep 2022 16:19:24 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 24 Sep 2022 16:19:24 +0200
branch
webdav
changeset 384
f9e9f2b3e299
parent 376
61d481d3c2e4
child 415
d938228c382e
permissions
-rw-r--r--

remove debug code

366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47bc686fafe4 add new dav config element
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
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "config.h"
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "../../util/util.h"
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
33 #include <libxml/tree.h>
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
34
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
35 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
36
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
37 static int pg_load_ext_dav_config(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
38 ServerConfiguration *cfg,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
39 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
40 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
41 const char *file);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
42
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
43
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
44 static const char *sql_get_repository_root = "select resource_id from Resource where parent_id is NULL and nodename = $1 ;";
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
45
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
46
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
47 // Uses a PGconn to lookup the resource id of the specified root node
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
48 // if the lookup succeeds, the resource id is written to rootid
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
49 // in case of an error, an error message will be logged
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
50 // returns: 0 success, 1 error
374
77506ec632a4 use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
51 int pg_lookup_root(ResourceData *res, const char *rootnode, int64_t *rootid) {
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
52 PGconn *connection = res->data;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
53
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
54 PGresult *result = PQexecParams(
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
55 connection,
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
56 sql_get_repository_root,
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
57 1, // number of parameters
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
58 NULL,
374
77506ec632a4 use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
59 &rootnode, // parameter value
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
60 NULL,
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
61 NULL,
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
62 0); // 0: result in text format
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
63
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
64 if(!result) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
65 log_ereport(LOG_FAILURE, "pg: root lookup failed: %s", PQerrorMessage(connection));
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
66 return 1;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
67 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
68
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
69 int ret = 0;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
70
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
71 int nrows = PQntuples(result);
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
72 if(nrows == 1) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
73 char *resource_id_str = PQgetvalue(result, 0, 0);
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
74 if(resource_id_str) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
75 if(!util_strtoint(resource_id_str, rootid)) {
374
77506ec632a4 use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
76 log_ereport(LOG_FAILURE, "pg: unexpected result for column resource_id", rootnode);
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
77 ret = 1;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
78 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
79 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
80 } else {
374
77506ec632a4 use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
81 log_ereport(LOG_FAILURE, "pg: cannot find root resource '%s'", rootnode);
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
82 ret = 1;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
83 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
84 PQclear(result);
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
85
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
86 return ret;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
87 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
88
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
89 PgRepository* pg_init_repo(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config) {
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 UcxAllocator a = util_pool_allocator(pool);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 ConfigNode *pg = serverconfig_get_node(config, CONFIG_NODE_OBJECT, SC("Postgresql"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 if(!pg) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 log_ereport(LOG_MISCONFIG, "pg_init_repo: missing postgresql config object");
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 return NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 scstr_t cfg_respool = serverconfig_directive_value(pg, SC("ResourcePool"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 scstr_t cfg_rootid = serverconfig_directive_value(pg, SC("RootId"));
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
100 scstr_t cfg_rootnode = serverconfig_directive_value(pg, SC("RootNode"));
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 scstr_t cfg_dav = serverconfig_directive_value(pg, SC("PGDavConfig"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 // minimum requirement is a resource pool
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 if(cfg_respool.length == 0) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 return NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 // check rootid
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 int64_t root_id = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 if(cfg_rootid.length > 0) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 if(!util_strtoint(cfg_rootid.ptr, &root_id)) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 log_ereport(LOG_MISCONFIG, "pg_init_repo: RootId parameter is not an integer: %s", cfg_rootid.ptr);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 return NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
117 // warn if RootId and RootNode are specified
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
118 if(cfg_rootid.length > 0 && cfg_rootnode.length > 0) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
119 log_ereport(LOG_WARN, "log_init_repo: RootId and RootNode specified, RootNode ignored");
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
120 } else if(cfg_rootnode.length > 0) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
121 // check root node
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
122
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
123 // resolve rootnode
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
124 // therefore we first need to get a connection from the resourcepool
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
125 ResourceData *res = resourcepool_cfg_lookup(cfg, cfg_respool.ptr, 0);
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
126 if(!res) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
127 log_ereport(LOG_MISCONFIG, "pg_init_repo: resource lookup failed");
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
128 return NULL;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
129 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
130 // do lookup, if successful, root_id will be set
374
77506ec632a4 use configured root node from PgRepository in pg vfs/webdav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 373
diff changeset
131 int lookup_err = pg_lookup_root(res, cfg_rootnode.ptr, &root_id);
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
132 // we don't need the connection anymore
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
133 resourcepool_free(NULL, NULL, res);
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
134 if(lookup_err) {
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
135 // no logging required, pg_lookup_root will log the error
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
136 return NULL;
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
137 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
138 }
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
139
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 PgRepository *repo = pool_malloc(pool, sizeof(PgRepository));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 ZERO(repo, sizeof(PgRepository));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 repo->resourcepool = sstrdup_a(&a, cfg_respool);
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
144 repo->root_resource_id = root_id;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
145
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
146 // check for extended pg dav config
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
147 if(cfg_dav.length > 0) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
148 // load extended config from config file
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
149 char *cfg_file_path = cfg_config_file_path(cfg_dav.ptr);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
150 if(pg_load_ext_dav_config(cfg, pool, repo, cfg_file_path)) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
151 // error
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
152 repo = NULL; // no need to cleanup because everything is from the pool
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
153 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
154 free(cfg_file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
155 }
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 return repo;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
159
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
160 static int pg_ext_get_config(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
161 ServerConfiguration *cfg,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
162 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
163 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
164 const char *file_path,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
165 xmlNode *root);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
166 static int pg_ext_get_extension(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
167 PgExtParser *ext,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
168 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
169 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
170 const char *file_path,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
171 xmlNode *ext_node);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
172
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
173 static const char* pg_util_xml_get_text(const xmlNode *elm) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
174 xmlNode *node = elm->children;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
175 while(node) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
176 if(node->type == XML_TEXT_NODE) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
177 return (const char*)node->content;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
178 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
179 node = node->next;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
180 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
181 return NULL;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
182 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
183
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
184 // load additional postgresql webdav config from the specified xml file
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
185 static int pg_load_ext_dav_config(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
186 ServerConfiguration *cfg,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
187 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
188 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
189 const char *file_path)
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
190 {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
191 UcxAllocator a = util_pool_allocator(pool);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
192
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
193 // check if the file exists and can be accessed
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
194 struct stat s;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
195 if(stat(file_path, &s)) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
196 if(errno == ENOENT) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
197 log_ereport(LOG_FAILURE, "pg: config file %s not found", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
198 } else {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
199 log_ereport(LOG_FAILURE, "pg: cannot access config file %s", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
200 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
201
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
202 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
203 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
204
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
205 // prepare PgRepository
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
206 repo->prop_ext = ucx_map_new_a(&a, 8);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
207 if(!repo->prop_ext) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
208 log_ereport(LOG_FAILURE, "pg: cannot load config file: OOM");
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
209 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
210 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
211
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
212 // load xml document
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
213 xmlDoc *doc = xmlReadFile(file_path, NULL, 0);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
214 if(!doc) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
215 log_ereport(LOG_FAILURE, "pg: cannot load config file %s", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
216 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
217 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
218
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
219 // the root element must be <repository>
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
220 int ret = 0;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
221 xmlNode *xml_root = xmlDocGetRootElement(doc);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
222 if(xstreq(xml_root->name, "repository")) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
223 // parse config
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
224 ret = pg_ext_get_config(cfg, pool, repo, file_path, xml_root);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
225 } else {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
226 log_ereport(LOG_MISCONFIG, "pg: config %s: root element <repository> expected", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
227 ret = 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
228 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
229 xmlFreeDoc(doc);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
230
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
231 return ret;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
232 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
233
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
234
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
235
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
236
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
237 static int pg_ext_get_config(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
238 ServerConfiguration *cfg,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
239 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
240 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
241 const char *file_path,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
242 xmlNode *root)
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
243 {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
244 xmlNode *node = root->children;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
245 int ret = 0;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
246
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
247 PgExtParser parserData;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
248 parserData.table_lookup = ucx_map_new(8);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
249 parserData.tables = NULL;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
250
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
251 while(node && !ret) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
252 // currently, the only possible config element is <extension>
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
253 if(node->type == XML_ELEMENT_NODE) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
254 if(xstreq(node->name, "extension")) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
255 ret = pg_ext_get_extension(&parserData, pool, repo, file_path, node);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
256 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
257 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
258 node = node->next;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
259 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
260
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
261 // convert parserData
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
262 if(!ret) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
263 size_t ntables = ucx_list_size(parserData.tables);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
264 repo->ntables = ntables;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
265 repo->tables = pool_calloc(pool, ntables, sizeof(PgExtTable));
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
266 if(repo->tables) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
267 int i = 0;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
268 UCX_FOREACH(elm, parserData.tables) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
269 PgExtTable *tab = elm->data;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
270 repo->tables[i++] = *tab;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
271 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
272 } else {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
273 ret = 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
274 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
275
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
276 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
277
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
278 // cleanup parser
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
279 ucx_list_free_content(parserData.tables, free);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
280 ucx_list_free(parserData.tables);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
281 ucx_map_free(parserData.table_lookup);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
282
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
283 return ret;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
284 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
285
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
286 static int pg_ext_get_extension(
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
287 PgExtParser *ext,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
288 pool_handle_t *pool,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
289 PgRepository *repo,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
290 const char *file_path,
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
291 xmlNode *ext_node)
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
292 {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
293 UcxAllocator a = util_pool_allocator(pool);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
294
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
295 xmlNode *node = ext_node->children;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
296
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
297 const char *table = NULL;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
298 UcxList *properties = NULL;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
299
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
300 while(node) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
301 if(node->type == XML_ELEMENT_NODE) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
302 if(xstreq(node->name, "table")) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
303 const char *value = pg_util_xml_get_text(node);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
304 if(!value) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
305 log_ereport(LOG_MISCONFIG, "pg: config %s: table: missing value", file_path, table);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
306 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
307 } else if(table) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
308 log_ereport(LOG_MISCONFIG, "pg: config %s: table %s already set", file_path, table);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
309 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
310 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
311 table = value;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
312 } else if(xstreq(node->name, "properties")) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
313 // add all child elements to the properties list
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
314 xmlNode *ps = node->children;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
315 while(ps) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
316 if(ps->type == XML_ELEMENT_NODE) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
317 // validate
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
318 // required: namespace, value
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
319 if(!ps->ns || !ps->ns->href) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
320 log_ereport(LOG_MISCONFIG, "pg: config %s: property %s: missing namespace", file_path, ps->name);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
321 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
322 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
323 const char *value = pg_util_xml_get_text(ps);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
324 if(!value) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
325 log_ereport(LOG_MISCONFIG, "pg: config %s: no column specified for property %s", file_path, ps->name);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
326 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
327 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
328 properties = ucx_list_append_a(&a, properties, ps);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
329 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
330 ps = ps->next;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
331 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
332 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
333 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
334 node = node->next;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
335 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
336
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
337 // check if anything is missing
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
338 if(!table) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
339 log_ereport(LOG_MISCONFIG, "pg: config %s: missing table value for extension", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
340 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
341 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
342 if(!properties) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
343 log_ereport(LOG_MISCONFIG, "pg: config %s: no properties configured for extension", file_path);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
344 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
345 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
346
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
347 // check if the table was already specified
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
348 if(ucx_map_cstr_get(ext->table_lookup, table)) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
349 log_ereport(LOG_MISCONFIG, "pg: config %s: extension table %s not unique", file_path, table);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
350 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
351 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
352 // mark table as used
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
353 // tabname will be used later, so ist must be allocated in the pool
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
354 char *tabname = pool_strdup(pool, table);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
355 if(!tabname) return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
356
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
357 // exttable is only used temporarily
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
358 PgExtTable *exttable = malloc(sizeof(PgExtTable));
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
359 if(!exttable) return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
360 exttable->table = tabname;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
361 exttable->isused = 0; // not relevant in config
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
362 int tableindex = (int)ucx_list_size(ext->tables);
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
363 ext->tables = ucx_list_append(ext->tables, exttable);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
364
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
365 if(ucx_map_cstr_put(ext->table_lookup, table, table)) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
366 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
367 }
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
368
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
369 UCX_FOREACH(elm, properties) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
370 xmlNode *ps = elm->data;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
371 const char *value = pg_util_xml_get_text(ps);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
372
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
373 PgPropertyStoreExt *ext_col = pool_malloc(pool, sizeof(PgPropertyStoreExt));
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
374 if(!ext_col) {
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
375 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
376 }
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
377 ext_col->tableindex = tableindex;
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
378 ext_col->ns = pool_strdup(pool, (const char*)ps->ns->href);
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
379 ext_col->name = pool_strdup(pool, (const char*)ps->name);
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
380 ext_col->column = pool_strdup(pool, (const char*)value);
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
381 if(!ext_col->ns || !ext_col->name || !ext_col->column) {
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
382 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
383 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
384
376
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
385 UcxKey key = webdav_property_key(ext_col->ns, ext_col->name);
61d481d3c2e4 Add support for extended properties in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
386 int err = ucx_map_put(repo->prop_ext, key, ext_col);
373
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
387 free((void*)key.data);
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
388 if(err) {
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
389 return 1;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
390 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
391 }
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
392
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
393 return 0;
f78a585e1a2f add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 372
diff changeset
394 }

mercurial