src/server/safs/nametrans.c

branch
webdav
changeset 277
7608af69739f
parent 137
ca0cf1016a8b
child 325
2d14055c3543
equal deleted inserted replaced
276:0cb4eda146c4 277:7608af69739f
31 #include "../daemon/log.h" 31 #include "../daemon/log.h"
32 #include "../daemon/request.h" 32 #include "../daemon/request.h"
33 #include "../util/pblock.h" 33 #include "../util/pblock.h"
34 #include "../util/util.h" 34 #include "../util/util.h"
35 35
36 #include "../public/vfs.h"
37
38 static int nametrans_set_vfs(pblock *pb, Session *sn, Request *rq) {
39 char *vfsclass = pblock_findkeyval(pb_key_vfsclass, pb);
40 if(!vfsclass) return 0;
41
42 VFS *vfs = vfs_create(sn, rq, vfsclass, pb);
43 if(!vfs) {
44 return 1;
45 }
46 rq->vfs = vfs;
47 return 0;
48 }
49
36 /* 50 /*
37 * assign_name 51 * assign_name
38 * 52 *
39 * Assigns the name specified by the name parameter if the uri has the 53 * Assigns the name specified by the name parameter if the uri has the
40 * specified prefix. 54 * specified prefix.
64 return REQ_NOACTION; 78 return REQ_NOACTION;
65 } 79 }
66 i++; 80 i++;
67 } 81 }
68 } 82 }
83
84 if(nametrans_set_vfs(pb, sn, rq)) {
85 log_ereport(LOG_FAILURE, "assign-name: cannot create VFS: name=%s from=%s", name, from);
86 return REQ_ABORTED;
87 }
69 88
70 // add object to rq->vars 89 // add object to rq->vars
71 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); 90 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
72 91
73 return REQ_NOACTION; 92 return REQ_NOACTION;
84 int document_root(pblock *pb, Session *sn, Request *rq) { 103 int document_root(pblock *pb, Session *sn, Request *rq) {
85 char *root = pblock_findkeyval(pb_key_root, pb); 104 char *root = pblock_findkeyval(pb_key_root, pb);
86 if(!root) { 105 if(!root) {
87 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter"); 106 log_ereport(LOG_MISCONFIG, "document-root: missing root parameter");
88 protocol_status(sn, rq, 500, NULL); 107 protocol_status(sn, rq, 500, NULL);
108 return REQ_ABORTED;
109 }
110
111 if(nametrans_set_vfs(pb, sn, rq)) {
112 log_ereport(LOG_FAILURE, "document-root: cannot create VFS");
89 return REQ_ABORTED; 113 return REQ_ABORTED;
90 } 114 }
91 115
92 sstr_t root_str = sstr(root); 116 sstr_t root_str = sstr(root);
93 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb)); 117 sstr_t uri_str = sstr(pblock_findkeyval(pb_key_uri, rq->reqpb));
145 uri = uri + i; 169 uri = uri + i;
146 if(uri[0] == '/') { 170 if(uri[0] == '/') {
147 uri++; 171 uri++;
148 } 172 }
149 173
174 if(nametrans_set_vfs(pb, sn, rq)) {
175 log_ereport(LOG_FAILURE, "pfx2dir: cannot create VFS: from=%s dir=%s name=%s", from, dir, name);
176 return REQ_ABORTED;
177 }
178
150 request_set_path(sstr(dir), sstr(uri), rq->vars); 179 request_set_path(sstr(dir), sstr(uri), rq->vars);
151 180
152 if(name) { 181 if(name) {
153 // add object to rq->vars 182 // add object to rq->vars
154 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); 183 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
187 char *path = pblock_findval("path", pb); 216 char *path = pblock_findval("path", pb);
188 char *name = pblock_findval("name", pb); 217 char *name = pblock_findval("name", pb);
189 218
190 if(!from || !path || !root) { 219 if(!from || !path || !root) {
191 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)"); 220 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)");
221 return REQ_ABORTED;
222 }
223
224 if(nametrans_set_vfs(pb, sn, rq)) {
225 log_ereport(LOG_FAILURE, "simple-rewrite: cannot create VFS: from=%s root=%s path=%s name=%s", from, root, path, name);
192 return REQ_ABORTED; 226 return REQ_ABORTED;
193 } 227 }
194 228
195 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); 229 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
196 sstr_t u = sstr(uri); 230 sstr_t u = sstr(uri);

mercurial