version 1.1.1.2, 2014/06/15 20:20:06
|
version 1.1.1.3, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "base.h" |
#include "base.h" |
#include "log.h" |
#include "log.h" |
#include "buffer.h" |
#include "buffer.h" |
Line 101 static int rewrite_rule_buffer_append(rewrite_rule_buf
|
Line 103 static int rewrite_rule_buffer_append(rewrite_rule_buf
|
} |
} |
|
|
kvb->ptr[kvb->used]->value = buffer_init(); |
kvb->ptr[kvb->used]->value = buffer_init(); |
buffer_copy_string_buffer(kvb->ptr[kvb->used]->value, value); | buffer_copy_buffer(kvb->ptr[kvb->used]->value, value); |
kvb->ptr[kvb->used]->once = once; |
kvb->ptr[kvb->used]->once = once; |
|
|
kvb->used++; |
kvb->used++; |
Line 146 FREE_FUNC(mod_rewrite_free) {
|
Line 148 FREE_FUNC(mod_rewrite_free) {
|
size_t i; |
size_t i; |
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
plugin_config *s = p->config_storage[i]; |
plugin_config *s = p->config_storage[i]; |
|
|
|
if (NULL == s) continue; |
|
|
rewrite_rule_buffer_free(s->rewrite); |
rewrite_rule_buffer_free(s->rewrite); |
rewrite_rule_buffer_free(s->rewrite_NF); |
rewrite_rule_buffer_free(s->rewrite_NF); |
|
|
Line 191 static int parse_config_entry(server *srv, array *ca,
|
Line 196 static int parse_config_entry(server *srv, array *ca,
|
once)) { |
once)) { |
log_error_write(srv, __FILE__, __LINE__, "sb", |
log_error_write(srv, __FILE__, __LINE__, "sb", |
"pcre-compile failed for", da->value->data[j]->key); |
"pcre-compile failed for", da->value->data[j]->key); |
|
return HANDLER_ERROR; |
} |
} |
} |
} |
} |
} |
Line 248 SETDEFAULTS_FUNC(mod_rewrite_set_defaults) {
|
Line 254 SETDEFAULTS_FUNC(mod_rewrite_set_defaults) {
|
#endif |
#endif |
|
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
array *ca; | data_config const* config = (data_config const*)srv->config_context->data[i]; |
#ifdef HAVE_PCRE_H |
#ifdef HAVE_PCRE_H |
plugin_config *s; |
plugin_config *s; |
|
|
Line 258 SETDEFAULTS_FUNC(mod_rewrite_set_defaults) {
|
Line 264 SETDEFAULTS_FUNC(mod_rewrite_set_defaults) {
|
p->config_storage[i] = s; |
p->config_storage[i] = s; |
#endif |
#endif |
|
|
ca = ((data_config *)srv->config_context->data[i])->value; | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
| |
if (0 != config_insert_values_global(srv, ca, cv)) { | |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
#ifndef HAVE_PCRE_H |
#ifndef HAVE_PCRE_H |
# define parse_config_entry(srv, ca, x, option, y) parse_config_entry(srv, ca, option) |
# define parse_config_entry(srv, ca, x, option, y) parse_config_entry(srv, ca, option) |
#endif |
#endif |
parse_config_entry(srv, ca, s->rewrite, "url.rewrite-once", 1); | parse_config_entry(srv, config->value, s->rewrite, "url.rewrite-once", 1); |
parse_config_entry(srv, ca, s->rewrite, "url.rewrite-final", 1); | parse_config_entry(srv, config->value, s->rewrite, "url.rewrite-final", 1); |
parse_config_entry(srv, ca, s->rewrite_NF, "url.rewrite-if-not-file", 1); | parse_config_entry(srv, config->value, s->rewrite_NF, "url.rewrite-if-not-file", 1); |
parse_config_entry(srv, ca, s->rewrite_NF, "url.rewrite-repeat-if-not-file", 0); | parse_config_entry(srv, config->value, s->rewrite_NF, "url.rewrite-repeat-if-not-file", 0); |
parse_config_entry(srv, ca, s->rewrite, "url.rewrite", 1); | parse_config_entry(srv, config->value, s->rewrite, "url.rewrite", 1); |
parse_config_entry(srv, ca, s->rewrite, "url.rewrite-repeat", 0); | parse_config_entry(srv, config->value, s->rewrite, "url.rewrite-repeat", 0); |
} |
} |
|
|
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
Line 341 URIHANDLER_FUNC(mod_rewrite_con_reset) {
|
Line 345 URIHANDLER_FUNC(mod_rewrite_con_reset) {
|
return HANDLER_GO_ON; |
return HANDLER_GO_ON; |
} |
} |
|
|
static int process_rewrite_rules(server *srv, connection *con, plugin_data *p, rewrite_rule_buffer *kvb) { | static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data *p, rewrite_rule_buffer *kvb) { |
size_t i; |
size_t i; |
handler_ctx *hctx; |
handler_ctx *hctx; |
|
|
Line 358 static int process_rewrite_rules(server *srv, connecti
|
Line 362 static int process_rewrite_rules(server *srv, connecti
|
if (hctx->state == REWRITE_STATE_FINISHED) return HANDLER_GO_ON; |
if (hctx->state == REWRITE_STATE_FINISHED) return HANDLER_GO_ON; |
} |
} |
|
|
buffer_copy_string_buffer(p->match_buf, con->request.uri); | buffer_copy_buffer(p->match_buf, con->request.uri); |
|
|
for (i = 0; i < kvb->used; i++) { |
for (i = 0; i < kvb->used; i++) { |
pcre *match; |
pcre *match; |
Line 371 static int process_rewrite_rules(server *srv, connecti
|
Line 375 static int process_rewrite_rules(server *srv, connecti
|
|
|
match = rule->key; |
match = rule->key; |
pattern = rule->value->ptr; |
pattern = rule->value->ptr; |
pattern_len = rule->value->used - 1; | pattern_len = buffer_string_length(rule->value); |
|
|
if ((n = pcre_exec(match, NULL, p->match_buf->ptr, p->match_buf->used - 1, 0, 0, ovec, 3 * N)) < 0) { | if ((n = pcre_exec(match, NULL, CONST_BUF_LEN(p->match_buf), 0, 0, ovec, 3 * N)) < 0) { |
if (n != PCRE_ERROR_NOMATCH) { |
if (n != PCRE_ERROR_NOMATCH) { |
log_error_write(srv, __FILE__, __LINE__, "sd", |
log_error_write(srv, __FILE__, __LINE__, "sd", |
"execution error while matching: ", n); |
"execution error while matching: ", n); |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
} else if (0 == pattern_len) { |
|
/* short-circuit if blank replacement pattern |
|
* (do not attempt to match against remaining rewrite rules) */ |
|
return HANDLER_GO_ON; |
} else { |
} else { |
const char **list; |
const char **list; |
size_t start; |
size_t start; |
Line 480 URIHANDLER_FUNC(mod_rewrite_uri_handler) {
|
Line 488 URIHANDLER_FUNC(mod_rewrite_uri_handler) {
|
if (!p->conf.rewrite) return HANDLER_GO_ON; |
if (!p->conf.rewrite) return HANDLER_GO_ON; |
|
|
return process_rewrite_rules(srv, con, p, p->conf.rewrite); |
return process_rewrite_rules(srv, con, p, p->conf.rewrite); |
|
|
return HANDLER_GO_ON; |
|
} |
} |
#endif |
#endif |
|
|