src/server/safs/nametrans.c

Sun, 15 Sep 2024 09:47:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Sep 2024 09:47:36 +0200
changeset 558
0e79e17c70e2
parent 490
d218607f5a7e
permissions
-rw-r--r--

improve sessionhandler trace logging

14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
4 * Copyright 2016 Olaf Wintermann. All rights reserved.
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b8bf95b39952 New source folder layout
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
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "nametrans.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
31 #include "../daemon/log.h"
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
32 #include "../daemon/request.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../util/pblock.h"
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
34 #include "../util/util.h"
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
35 #include "../public/webdav.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
37 #include "../daemon/session.h"
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
38 #include "../daemon/config.h"
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
39
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
40 #include "../public/vfs.h"
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
41
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
42 static int initialize_dav_repo(pblock *pb, Session *sn, Request *rq, WebdavRepository *repo) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
43 if(repo->vfs) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
44 VFS *vfs = repo->vfs->create(sn, rq, pb, repo->vfsInitData);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
45 if(!vfs) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
46 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
47 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
48 rq->vfs = vfs;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
49 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
50
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
51 void *backend_first = NULL;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
52 void *backend_last = NULL;
490
d218607f5a7e update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
53 CxIterator i = cxListIterator(repo->davBackends);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
54 cx_foreach(WebdavBackendInitData *, davInit, i) {
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
55 WebdavBackend *backend = davInit->davType->create(sn, rq, pb, davInit->davInitData);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
56 if(!backend) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
57 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
58 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
59 cx_linked_list_add(&backend_first, &backend_last, -1, offsetof(WebdavBackend, next), backend);
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
60 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
61 rq->davCollection = backend_first;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
62
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
63 return 0;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
64 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
65
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
66 static int nametrans_set_dav_repository(pblock *pb, Session *sn, Request *rq) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
67 char *dav = pblock_findkeyval(pb_key_dav, pb);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
68 if(!dav) return 0;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
69
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
70 ServerConfiguration *config = session_get_config(sn);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
71 WebdavRepository *repo = cxMapGet(config->dav, cx_hash_key_str(dav));
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
72
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
73 if(!repo) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
74 log_ereport(LOG_MISCONFIG, "nametrans: unknown dav repository '%s'", dav);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
75 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
76 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
77
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
78 return initialize_dav_repo(pb, sn, rq, repo);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
79 }
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
80
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
81 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
82 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
83 if(!vfsclass) return 0;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
84
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
85 VFS *vfs = vfs_create(sn, rq, vfsclass, pb, NULL);
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
86 if(!vfs) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
87 return 1;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
88 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
89 rq->vfs = vfs;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
90 return 0;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
91 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
92
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
93 static int nametrans_set_dav(pblock *pb, Session *sn, Request *rq) {
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
94 char *davclass = pblock_findkeyval(pb_key_davclass, pb);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
95 if(!davclass) return 0;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
96
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 325
diff changeset
97 WebdavBackend *dav = webdav_create(sn, rq, davclass, pb, NULL);
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
98
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
99 rq->davCollection = dav;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
100 return 0;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
101 }
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
102
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 /*
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 * assign_name
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 * Assigns the name specified by the name parameter if the uri has the
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 * specified prefix.
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 *
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 * pblock parameter:
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 * name object name
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 * from optional uri prefix
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 int assign_name(pblock *pb, Session *sn, Request *rq) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 /* TODO: expression instead of simple prefix */
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 char *name = pblock_findkeyval(pb_key_name, pb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 char *from = pblock_findkeyval(pb_key_from, pb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 if(!name) {
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
120 log_ereport(LOG_MISCONFIG, "assign-name: missing name parameter");
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 protocol_status(sn, rq, 500, NULL);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 return REQ_ABORTED;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 if(from) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 char c;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 int i = 0;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 while((c = from[i]) != 0) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 if(c != uri[i]) {
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 return REQ_NOACTION;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 i++;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
136
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
137 if(nametrans_set_dav_repository(pb, sn, rq)) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
138 log_ereport(LOG_FAILURE, "assign-name: cannot create dav repository: name=%s from=%s", name, from);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
139 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
140 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
141 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
142 log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
143 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
144 }
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
145 if(nametrans_set_dav(pb, sn, rq)) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
146 log_ereport(LOG_FAILURE, "assign-name: cannot create Webdav Backend: name=%s from=%s", name, from);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
147 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
148 }
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
150 // add object to rq->vars
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 return REQ_NOACTION;
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 }
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
155
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
156 /*
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
157 * document_root
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
158 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
159 * Specifies the document root directory.
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
160 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
161 * pblock parameter:
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
162 * root path to document root
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
163 */
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
164 int document_root(pblock *pb, Session *sn, Request *rq) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
165 char *root = pblock_findkeyval(pb_key_root, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
166 if(!root) {
97
09fbefc0e6a9 added ldap group support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
167 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter");
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
168 protocol_status(sn, rq, 500, NULL);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
169 return REQ_ABORTED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
170 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
171
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
172 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
173 log_ereport(LOG_FAILURE, "document-root: cannot create VFS");
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
174 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
175 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
176
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
177 cxstring root_str = cx_str(root);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
178 cxstring uri_str = cx_str(pblock_findkeyval(pb_key_uri, rq->reqpb));
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
179
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
180 request_set_path(root_str, uri_str, rq->vars);
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
181
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
182 return REQ_PROCEED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
183 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
184
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
185 /*
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
186 * pfx2dir
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
187 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
188 * ...
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
189 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
190 * pblock parameter:
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
191 * from prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
192 * dir file system directory
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
193 * name (optional) object name
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
194 * dav (optional) dav repository name
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
195 * vfsclass (optional) vfs name
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
196 * davclass (optional) dav backend
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
197 *
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
198 */
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
199 int pfx2dir(pblock *pb, Session *sn, Request *rq) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
200 char *from = pblock_findkeyval(pb_key_from, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
201 char *dir = pblock_findkeyval(pb_key_dir, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
202 char *name = pblock_findkeyval(pb_key_name, pb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
203
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
204 if(!from || !dir) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
205 if(!from && dir) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
206 log_ereport(LOG_MISCONFIG, "pfx2dir: missing from parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
207 } else if(!dir && from) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
208 log_ereport(LOG_MISCONFIG, "pfx2dir: missing dir parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
209 } else {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
210 log_ereport(
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
211 LOG_MISCONFIG,
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
212 "pfx2dir: missing from and dir parameter");
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
213 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
214 protocol_status(sn, rq, 500, NULL);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
215 return REQ_ABORTED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
216 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
217
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
218 // check prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
219 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
220 char fc;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
221 char uc;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
222 int i = 0;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
223 while((fc = from[i]) != 0) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
224 uc = uri[i];
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
225 if(fc != uc) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
226 return REQ_NOACTION;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
227 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
228 i++;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
229 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
230
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
231 // url has the specified prefix
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
232
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
233 uri = uri + i;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
234 if(uri[0] == '/') {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
235 uri++;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
236 }
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
237
369
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
238 if(nametrans_set_dav_repository(pb, sn, rq)) {
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
239 log_ereport(LOG_FAILURE, "pfx2dir: cannot create dav repository: from=%s dir=%s name=%s", from, dir, name);
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
240 return REQ_ABORTED;
e28ee9875a90 add support for named dav repositories in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
241 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
242 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
243 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
244 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
245 }
325
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
246 if(nametrans_set_dav(pb, sn, rq)) {
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
247 log_ereport(LOG_FAILURE, "pfx2dir: cannot create Webdav Backend: from=%s dir=%s name=%s", from, dir, name);
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
248 return REQ_ABORTED;
2d14055c3543 add davclass parameter to pfx2dir for setting the webdav backend
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 277
diff changeset
249 }
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
250
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
251 request_set_path(cx_str(dir), cx_str(uri), rq->vars);
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
252
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
253 if(name) {
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
254 // add object to rq->vars
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
255 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
256 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
257
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
258 return REQ_PROCEED;
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
259 }
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
260
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
261
137
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
262 int redirect(pblock *pb, Session *sn, Request *rq) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
263 char *from = pblock_findval("from", pb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
264 char *url = pblock_findval("url", pb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
265
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
266 if(!from || !url) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
267 log_ereport(LOG_MISCONFIG, "redirect: missing parameter (from, url)");
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
268 return REQ_ABORTED;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
269 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
270
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
271 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
272 if(!strcmp(uri, from)) {
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
273 pblock_nvinsert("location", url, rq->srvhdrs);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
274
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
275 protocol_status(sn, rq, 302, NULL);
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
276 return REQ_ABORTED;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
277 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
278
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
279 return REQ_NOACTION;
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
280 }
ca0cf1016a8b adds redirect saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
281
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
282 /*
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
283 * provisional rewrite saf
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
284 */
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
285 int simple_rewrite(pblock *pb, Session *sn, Request *rq) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
286 char *from = pblock_findval("from", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
287 char *root = pblock_findval("root", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
288 char *path = pblock_findval("path", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
289 char *name = pblock_findval("name", pb);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
290
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
291 if(!from || !path || !root) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
292 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)");
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
293 return REQ_ABORTED;
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
294 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
295
277
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
296 if(nametrans_set_vfs(pb, sn, rq)) {
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
297 log_ereport(LOG_FAILURE, "simple-rewrite: cannot create VFS: from=%s root=%s path=%s name=%s", from, root, path, name);
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
298 return REQ_ABORTED;
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
299 }
7608af69739f add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
300
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
301 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
302 cxstring u = cx_str(uri);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
303 cxstring f = cx_str(from);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
304 if(cx_strprefix(u, f)) {
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
305 cxstring suf = cx_strsubs(u, f.length);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
306 cxmutstr ppath = cx_strcat(2, cx_str(path), suf);
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
307
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
308 request_set_path(cx_str(root), (cxstring){ppath.ptr, ppath.length}, rq->vars);
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
309 free(ppath.ptr);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
310
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
311 if(name) {
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
312 // add object to rq->vars
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
313 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
314 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
315 }
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
316
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
317 return REQ_NOACTION;
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
318 }

mercurial