src/server/safs/nametrans.c

changeset 136
9b48a1427aef
parent 117
a94cf2e94492
child 137
ca0cf1016a8b
equal deleted inserted replaced
135:471e28cca288 136:9b48a1427aef
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2013 Olaf Wintermann. All rights reserved. 4 * Copyright 2016 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
156 156
157 return REQ_PROCEED; 157 return REQ_PROCEED;
158 } 158 }
159 159
160 160
161 /*
162 * provisional rewrite saf
163 */
164 int simple_rewrite(pblock *pb, Session *sn, Request *rq) {
165 char *from = pblock_findval("from", pb);
166 char *root = pblock_findval("root", pb);
167 char *path = pblock_findval("path", pb);
168 char *name = pblock_findval("name", pb);
169
170 if(!from || !path || !root) {
171 log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)");
172 return REQ_ABORTED;
173 }
174
175 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
176 sstr_t u = sstr(uri);
177 sstr_t f = sstr(from);
178 if(sstrprefix(u, f)) {
179 sstr_t suf = sstrsubs(u, f.length);
180 sstr_t ppath = sstrcat(2, sstr(path), suf);
181
182 request_set_path(sstr(root), ppath, rq->vars);
183 free(ppath.ptr);
184
185 if(name) {
186 // add object to rq->vars
187 pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
188 }
189 }
190
191 return REQ_NOACTION;
192 }

mercurial