Tue, 27 Dec 2016 19:36:19 +0100
adds simple rewrite saf
--- a/src/server/daemon/httprequest.c Tue Dec 27 18:42:36 2016 +0100 +++ b/src/server/daemon/httprequest.c Tue Dec 27 19:36:19 2016 +0100 @@ -184,7 +184,14 @@ } else if(!sstrcmp(request->httpv, S("HTTP/1.0"))) { rq->rq.protv_num = PROTOCOL_VERSION_HTTP10; } else { - // TODO: invalid protocol version - abort + // invalid protocol version - abort + log_ereport( + LOG_FAILURE, + "invalid protocol version: %.*s", + (int)request->httpv.length, + request->httpv.ptr); + pool_destroy(pool); + return 1; } /* @@ -240,7 +247,7 @@ rq->rq.reqpb); } else { // TODO: log error - printf("unescape failed\n"); + log_ereport(LOG_WARN, "uri unescape failed"); pblock_kvinsert(pb_key_uri, "/", 1, rq->rq.reqpb); } @@ -605,8 +612,12 @@ if(ret == REQ_NOACTION && ppath == NULL) { sstr_t docroot = rq->vs->document_root; if(docroot.length < 1) { - printf("docroot too short\n"); - return REQ_ABORTED; /* docroot too short */ + log_ereport( + LOG_WARN, + "VirtualServer(%.*s) docroot too short", + (int)rq->vs->name.length, + rq->vs->name.ptr); + return REQ_ABORTED; // docroot too short } // if there is a trailing '/', remove it
--- a/src/server/daemon/ws-fn.c Tue Dec 27 18:42:36 2016 +0100 +++ b/src/server/daemon/ws-fn.c Tue Dec 27 19:36:19 2016 +0100 @@ -47,6 +47,7 @@ { "assign-name", assign_name, NULL, NULL, 0}, { "document-root", document_root, NULL, NULL, 0}, { "pfx2dir", pfx2dir, NULL, NULL, 0}, + { "simple-rewrite", simple_rewrite, NULL, NULL, 0}, { "type-by-extension", object_type_by_extension, NULL, NULL, 0}, { "send-file", send_file, NULL, NULL, 0}, { "common-index", service_index, NULL, NULL, 0},
--- a/src/server/safs/nametrans.c Tue Dec 27 18:42:36 2016 +0100 +++ b/src/server/safs/nametrans.c Tue Dec 27 19:36:19 2016 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2013 Olaf Wintermann. All rights reserved. + * Copyright 2016 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -158,3 +158,35 @@ } +/* + * provisional rewrite saf + */ +int simple_rewrite(pblock *pb, Session *sn, Request *rq) { + char *from = pblock_findval("from", pb); + char *root = pblock_findval("root", pb); + char *path = pblock_findval("path", pb); + char *name = pblock_findval("name", pb); + + if(!from || !path || !root) { + log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)"); + return REQ_ABORTED; + } + + char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); + sstr_t u = sstr(uri); + sstr_t f = sstr(from); + if(sstrprefix(u, f)) { + sstr_t suf = sstrsubs(u, f.length); + sstr_t ppath = sstrcat(2, sstr(path), suf); + + request_set_path(sstr(root), ppath, rq->vars); + free(ppath.ptr); + + if(name) { + // add object to rq->vars + pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars); + } + } + + return REQ_NOACTION; +}
--- a/src/server/safs/nametrans.h Tue Dec 27 18:42:36 2016 +0100 +++ b/src/server/safs/nametrans.h Tue Dec 27 19:36:19 2016 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2013 Olaf Wintermann. All rights reserved. + * Copyright 2016 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -39,6 +39,8 @@ int document_root(pblock *pb, Session *sn, Request *rq); int pfx2dir(pblock *pb, Session *sn, Request *rq); +int simple_rewrite(pblock *pb, Session *sn, Request *rq); + #ifdef __cplusplus } #endif