summaryrefslogtreecommitdiff
path: root/src/mod_redirect.c
Commit message (Collapse)AuthorAgeFilesLines
* [build] _WIN32 __declspec(dllexport) *_plugin_initGlenn Strauss2023-05-031-0/+1
| | | | _WIN32 __declspec(dllexport) on mod_*_plugin_init()
* [multiple] employ ck_calloc, ck_malloc shared codeGlenn Strauss2022-12-101-1/+1
| | | | | employ ck_calloc(), ck_malloc() shared code to slightly reduce code size (centralize the ck_assert() to check that memory allocation succeeded)
* [multiple] mark mod_*_plugin_init() funcs coldGlenn Strauss2022-12-071-0/+2
|
* [core] allocate one fewer cond_match_t, if neededGlenn Strauss2021-11-221-1/+1
| | | | allocate one fewer cond_match_t in r->cond_match_data, if any are needed
* [core] use stack w/ pcre_exec unless save capturesGlenn Strauss2021-11-201-2/+0
| | | | | | | | | | | | | | use stack w/ pcre_exec unless saving captures from config conditions reduce memory allocations per request where lighttpd.conf does not contain url.redirect or url.rewrite rules where replacements reference a match of the enclosing lighttpd.conf condition (e.g. %0, %1, %2 ...) move cond_cache_t 'patterncount' to cond_match_t 'captures' While cond_match_t is no longer sized power-2, it is generally expected to be used much less frequently than before (which was all the time), since it is now used only with url.redirect or url.rewrite with references %0, %1, %2, ...
* [core] save config regex captures only if usedGlenn Strauss2021-11-191-4/+15
| | | | | | | | | | | | | | | | save config regex captures separately only if used by url.redirect or url.rewrite replacement directives within the condition (or for conditions containing directives from any other module which calls config_capture() for its directives during init) keep pointer to match data (cond_match_t *) in r->cond_match[] rather than cond_match_t to reduce data copying in h2_init_stream(). h2_init_stream() copies the results for already-evaluated conditions to avoid re-evaluating connection-level conditions for each and every stream. When conditions are reset, then the pointer in r->cond_match[] is updated when the condition is re-evaluated. (This all assumes that HTTP/2 connection-level conditions are not unset or re-evaluated once HTTP/2 streams begin.)
* [multiple] check feature flags funcs; code reuseGlenn Strauss2021-09-301-5/+1
| | | | | config_feature_bool() config_feature_int()
* [multiple] reduce redundant NULL buffer checksGlenn Strauss2021-08-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is a large set of code changes and results in removal of hundreds, perhaps thousands, of CPU instructions, a portion of which are on hot code paths. Most (buffer *) used by lighttpd are not NULL, especially since buffers were inlined into numerous larger structs such as request_st and chunk. In the small number of instances where that is not the case, a NULL check is often performed earlier in a function where that buffer is later used with a buffer_* func. In the handful of cases that remained, a NULL check was added, e.g. with r->http_host and r->conf.server_tag. - check for empty strings at config time and set value to NULL if blank string will be ignored at runtime; at runtime, simple pointer check for NULL can be used to check for a value that has been set and is not blank ("") - use buffer_is_blank() instead of buffer_string_is_empty(), and use buffer_is_unset() instead of buffer_is_empty(), where buffer is known not to be NULL so that NULL check can be skipped - use buffer_clen() instead of buffer_string_length() when buffer is known not to be NULL (to avoid NULL check at runtime) - use buffer_truncate() instead of buffer_string_set_length() to truncate string, and use buffer_extend() to extend Examples where buffer known not to be NULL: - cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL (though we might set it to NULL if buffer_is_blank(cpv->v.b)) - address of buffer is arg (&foo) (compiler optimizer detects this in most, but not all, cases) - buffer is checked for NULL earlier in func - buffer is accessed in same scope without a NULL check (e.g. b->ptr) internal behavior change: callers must not pass a NULL buffer to some funcs. - buffer_init_buffer() requires non-null args - buffer_copy_buffer() requires non-null args - buffer_append_string_buffer() requires non-null args - buffer_string_space() requires non-null arg
* [multiple] PCRE w/ PCRE_STUDY_JIT_COMPILE (fixes #2361)Glenn Strauss2021-03-221-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | enabled by default disable using server.feature-flags += ("server.pcre_jit" => "disable") Available since pcre-8.20 (2011), and improved in pcre-8.32 (2012), PCRE_STUDY_JIT_COMPILE can greatly speed up repeated execution of PCRE patterns. (https://zherczeg.github.io/sljit/pcre.html) lighttpd continues to use pcre_exec() instead of pcre_jit_exec(), even though doing so does not realize all of the performance increase potentially available with PCRE_STUDY_JIT_COMPILE and pcre_jit_exec(). pcre_jit_exec() is available with PCRE 8.32 and later, if PCRE is compiled with --enable-jit, but lighttpd does not currently use pcre_jit_exec() since the PCRE library might not have been compiled with --enable-jit (though this could be solved with a weak symbol). Similarly, lighttpd does not currently configure the pcre_jit_stack. (Using pcre_jit_exec() may be revisited in the future.) x-ref: "add support for pcre JIT" https://redmine.lighttpd.net/issues/2361
* [core] remove r->uri.path_raw; generate as neededGlenn Strauss2020-07-081-1/+1
| | | | (r->uri.path_raw previously duplicated from r->target, minus query-part)
* [multiple] split con, request (very large change)Glenn Strauss2020-07-081-19/+19
| | | | | | | | | | | | | | | | NB: r->tmp_buf == srv->tmp_buf (pointer is copied for quicker access) NB: request read and write chunkqueues currently point to connection chunkqueues; per-request and per-connection chunkqueues are not distinct from one another con->read_queue == r->read_queue con->write_queue == r->write_queue NB: in the future, a separate connection config may be needed for connection-level module hooks. Similarly, might need to have per-request chunkqueues separate from per-connection chunkqueues. Should probably also have a request_reset() which is distinct from connection_reset().
* [multiple] copy small struct instead of memcpy()Glenn Strauss2020-07-081-1/+2
| | | | when patching config
* [core] store subrequest_handler instead of modeGlenn Strauss2020-07-081-1/+1
| | | | store pointer to module in handler_module instead of con->mode id
* [core] move addtl request-specific struct membersGlenn Strauss2020-07-081-5/+6
|
* [core] move addtl request-specific struct membersGlenn Strauss2020-07-081-1/+1
|
* [multiple] store srv->tmp_buf in tb varGlenn Strauss2020-07-081-2/+3
| | | | rather than using srv->tmp_buf directly in code modifying temp buf (tb)
* [multiple] generic config array type checkingGlenn Strauss2020-07-081-8/+1
|
* [multiple] connection hooks no longer get (srv *)Glenn Strauss2020-07-081-2/+3
| | | | (explicit (server *) not passed; available in con->srv)
* [multiple] prefer (connection *) to (srv *)Glenn Strauss2020-07-081-3/+3
| | | | | | | | convert all log_error_write() to log_error() and pass (log_error_st *) use con->errh in preference to srv->errh (even though currently same) avoid passing (server *) when previously used only for logging (errh)
* [core] split cond cache from cond matchesGlenn Strauss2020-07-081-3/+6
|
* [multiple] plugin.c handles common FREE_FUNC codeGlenn Strauss2020-07-081-14/+2
| | | | (simpler for modules; less boilerplate to cut-n-paste)
* [mod_redirect] use config_plugin_values_init()Glenn Strauss2020-07-081-116/+134
|
* [core] const char *name in struct pluginGlenn Strauss2020-05-231-3/+1
| | | | | | | | put void *data (always used) as first member of struct plugin add int nconfig member to PLUGIN_DATA calloc() inits p->data to NULL
* [mod_redirect,mod_rewrite] store context_ndxGlenn Strauss2020-05-231-5/+5
| | | | store config context_ndx instead of data_config *dc
* [core] simpler config_check_cond()Glenn Strauss2020-05-231-3/+2
| | | | | | | optimize for common case where condition has been evaluated for the request and a cached result exists (also: begin isolating data_config)
* [core] inline array as part of data_array valueGlenn Strauss2020-02-241-3/+3
| | | | (instead of value being (array *))
* [core] inline buffer as part of data_string valueGlenn Strauss2020-02-241-2/+2
| | | | (instead of value being (buffer *))
* [core] inline buffer key for *_patch_connection()Glenn Strauss2020-02-241-2/+2
| | | | | handle buffer key as part of DATA_UNSET in *_patch_connection() (instead of key being (buffer *))
* [core] inline buffer as part of DATA_UNSET keyGlenn Strauss2020-02-241-3/+3
| | | | (instead of key being (buffer *))
* [core] differentiate array_get_* for ro and rwGlenn Strauss2020-02-241-4/+4
| | | | | | array_get_element_klen() is now intended for read-only access array_get_data_unset() is used by config processing for r/w access array_get_buf_ptr() is used for r/w access to ds->value (string buffer)
* [multiple] cleaner calloc use in SETDEFAULTS_FUNCMohammed Sadiq2019-04-201-1/+1
| | | | | | | | github: closes #99 x-ref: "cleaner calloc use in SETDEFAULTS_FUNC" https://github.com/lighttpd/lighttpd1.4/pull/99
* [mod_redirect,mod_rewrite] use server_nameGlenn Strauss2018-11-181-0/+2
| | | | | use server_name for authority if Host not provided (Host is not required in HTTP/1.0)
* [core] abstraction layer for HTTP header manipGlenn Strauss2018-09-231-3/+4
| | | | | | http_header.[ch] convert existing calls to manip request/response headers convert existing calls to manip environment array (often header-related)
* [mod_redirect,mod_rewrite] encoding options (fixes #443, fixes #911)Glenn Strauss2018-08-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Provide means to encode redirect and rewrite backreference substitutions In addition to $1 and %1, the following modifiers are now supported, followed by the number for the backreference, e.g. ${esc:1} ${noesc:...} no escaping ${esc:...} escape all non-alphanumeric - . _ ~ incl double-escape % ${escape:...} escape all non-alphanumeric - . _ ~ incl double-escape % ${escnde:...} escape all non-alphanumeric - . _ ~ but no double-esc % ${tolower:...} ${toupper:...} %{noesc:...} %{esc:...} %{escape:...} %{escnde:...} %{tolower:...} %{toupper:...} Provide means to substitute URI parts without needing a regex match (and can be preceded by encoding modifier, e.g. ${tolower:url.authority}) ${url.scheme} ${url.authority} ${url.port} ${url.path} ${url.query} ${qsa} appends query string, if not empty x-ref: "[PATCH] mod_redirect: Add support for url-encoding backreferences, map %%n->%n, $$n->$n" https://redmine.lighttpd.net/issues/443 "Need for URL encoding in mod_redirect and possibly mod_rewrite" https://redmine.lighttpd.net/issues/911
* [mod_redirect,mod_rewrite] pass request URI infoGlenn Strauss2018-08-121-0/+7
|
* [mod_redirect,mod_rewrite] short-circuit earlierGlenn Strauss2018-08-121-0/+1
| | | | short-circuit earlier if there are no rules to be matched
* [core] server.http-parseopts URL normalization opt (fixes #1720)Glenn Strauss2018-08-121-0/+4
| | | | | | | | | | | | | | | | | | | server.http-parseopts = ( ... ) URL normalization options Note: *not applied* to CONNECT method Note: In a future release, URL normalization likely enabled by default (normalize URL, reject control chars, remove . and .. path segments) To prepare for this change, lighttpd.conf configurations should explicitly select desired behavior by enabling or disabling: server.http-parseopts = ( "url-normalize" => "enable", ... ) server.http-parseopts = ( "url-normalize" => "disable" ) x-ref: "lighttpd ... compares URIs to patterns in the (1) url.redirect and (2) url.rewrite configuration settings before performing URL decoding, which might allow remote attackers to bypass intended access restrictions, and obtain sensitive information or possibly modify data." https://www.cvedetails.com/cve/CVE-2008-4359/ "Rewrite/redirect rules and URL encoding" https://redmine.lighttpd.net/issues/1720
* [core] http_kv.[ch] method, status, version strGlenn Strauss2018-08-051-0/+1
| | | | move method, status, version strings from keyvalue.[ch] to http_kv.[ch]
* [mod_redirect, mod_rewrite] code reuse (sharing)Glenn Strauss2018-08-051-91/+35
|
* [core] some header cleanupGlenn Strauss2018-04-081-0/+4
| | | | | | | | | provide standard types in first.h instead of base.h provide lighttpd types in base_decls.h instead of settings.h reduce headers exposed by headers for core data structures do not expose <pcre.h> or <stdlib.h> in headers move stat_cache_entry to stat_cache.h reduce use of "server.h" and "base.h" in headers
* [core] merge redirect/rewrite pattern substitutionGlenn Strauss2018-01-101-56/+7
| | | | merge redirect/rewrite pattern substitution function (share code)
* [config] more specific checks for array listsGlenn Strauss2017-03-081-14/+4
| | | | | | | | | | | | | More specific checks on contents of array lists. Each module using lists now does better checking on the types of values in the list (strings, integers, arrays/lists) This helps prevent misconfiguration of things like cgi.assign, fastcgi.server, and scgi.server, where source code might be served as static files if parenthesis are misplaced. x-ref: https://redmine.lighttpd.net/boards/2/topics/6571
* [mod_redirect,mod-rewrite] short-circuit if blank replacement (fixes #2085)Glenn Strauss2016-04-141-0/+4
| | | | | | x-ref: "null redirects for mod_redirect" https://redmine.lighttpd.net/issues/2085
* consistent inclusion of config.h at top of files (fixes #2073)Glenn Strauss2016-03-191-0/+2
| | | | | | From: Glenn Strauss <gstrauss@gluelogic.com> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3113 152afb58-edef-0310-8abb-c4023f1b3aa9
* [config] check config option scope; warn if server option is given in ↵Stefan Bühler2015-11-071-4/+3
| | | | | | | | conditional From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3049 152afb58-edef-0310-8abb-c4023f1b3aa9
* fix segfaults in many plugins if they failed configurationStefan Bühler2015-05-141-0/+2
| | | | | | From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2988 152afb58-edef-0310-8abb-c4023f1b3aa9
* Use buffer API to read and modify "used" memberStefan Bühler2015-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | - a lot of code tried to handle manually adding terminating zeroes and keeping track of the correct "used" count. Replaced all "external" usages with simple wrapper functions: * buffer_string_is_empty (used <= 1), buffer_is_empty (used == 0); prefer buffer_string_is_empty * buffer_string_set_length * buffer_string_length * CONST_BUF_LEN() macro - removed "static" buffer hacks (buffers pointing to constant/stack memory instead of malloc()ed data) - buffer_append_strftime(): refactor buffer+strftime uses - li_tohex(): no need for a buffer for binary-to-hex conversion: the output data length is easy to predict - remove "-Winline" from extra warnings: the "inline" keyword just supresses the warning about unused but defined (static) functions; don't care whether it actually gets inlined or not. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2979 152afb58-edef-0310-8abb-c4023f1b3aa9
* fix buffer, chunk and http_chunk APIStefan Bühler2015-02-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * remove unused structs and functions (buffer_array, read_buffer) * change return type from int to void for many functions, as the return value (indicating error/success) was never checked, and the function would only fail on programming errors and not on invalid input; changed functions to use force_assert instead of returning an error. * all "len" parameters now are the real size of the memory to be read. the length of strings is given always without the terminating 0. * the "buffer" struct still counts the terminating 0 in ->used, provide buffer_string_length() to get the length of a string in a buffer. unset config "strings" have used == 0, which is used in some places to distinguish unset values from "" (empty string) values. * most buffer usages should now use it as string container. * optimise some buffer copying by "moving" data to other buffers * use (u)intmax_t for generic int-to-string functions * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET * converted BUFFER_APPEND_SLASH to inline function (no macro feature needed) * refactor: create chunkqueue_steal: moving (partial) chunks into another queue * http_chunk: added separate function to terminate chunked body instead of magic handling in http_chunk_append_mem(). http_chunk_append_* now handle empty chunks, and never terminate the chunked body. From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2975 152afb58-edef-0310-8abb-c4023f1b3aa9
* [mod_dirlisting,mod_redirect,mod_rewrite] abort config parsing if ↵Stefan Bühler2014-10-161-0/+1
| | | | | | | | pcre-compile fails or isn't available From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2968 152afb58-edef-0310-8abb-c4023f1b3aa9
* fix/silence bugs reported by ccc-analyzer (clang)Stefan Bühler2013-11-131-1/+1
| | | | | | | | | | | | | | | | | | | | | These should all be non critical: * memory leaks on startup in error cases (which lead to immediate shutdowns anyway) * http_auth/ldap: passing uninitialized "ret" to ldap_err2string * sizeof(T) not matching the target pointer in malloc/calloc calls; those cases were either: * T being the wrong pointer type - shouldn't matter as long as all pointers have same size * T being larger than the type needed * mod_accesslog: direct use after free in cleanup (server shutdown); could crash before "clean" shutdown * some false positives (mod_compress, mod_expire) * assert(srv->config_context->used > 0); - this is always the case, as there is always a global config block From: Stefan Bühler <stbuehler@web.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2920 152afb58-edef-0310-8abb-c4023f1b3aa9