summaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_referer_module.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2007-12-27 15:31:36 +0000
committerJonathan Kolb <jon@b0g.us>2007-12-27 15:31:36 +0000
commit37acebc32d2a50b11537edd920af3721b93a1ecc (patch)
tree5338ea420eec0818d8e123a91973ee90308693f5 /src/http/modules/ngx_http_referer_module.c
parent73cd30361418f277067c128cedee4990aa72840b (diff)
downloadnginx-37acebc32d2a50b11537edd920af3721b93a1ecc.tar.gz
Changes with nginx 0.6.23 27 Dec 2007v0.6.23
*) Change: the "off" parameter in the "ssl_session_cache" directive; now this is default parameter. *) Change: the "open_file_cache_retest" directive was renamed to the "open_file_cache_valid". *) Feature: the "open_file_cache_min_uses" directive. *) Feature: the ngx_http_gzip_static_module. *) Feature: the "gzip_disable" directive. *) Feature: the "memcached_pass" directive may be used inside the "if" block. *) Bugfix: a segmentation fault occurred in worker process, if the "memcached_pass" and "if" directives were used in the same location. *) Bugfix: if a "satisfy_any on" directive was used and not all access and auth modules directives were set, then other given access and auth directives were not tested; *) Bugfix: regex parameters in a "valid_referers" directive were not inherited from previous level. *) Bugfix: a "post_action" directive did run if a request was completed with 499 status code. *) Bugfix: optimization of 16K buffer usage in a SSL connection. Thanks to Ben Maurer. *) Bugfix: the STARTTLS in SMTP mode did not work. Thanks to Oleg Motienko. *) Bugfix: in HTTPS mode requests might fail with the "bad write retry" error; bug appeared in 0.5.13.
Diffstat (limited to 'src/http/modules/ngx_http_referer_module.c')
-rw-r--r--src/http/modules/ngx_http_referer_module.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
index 0076e9472..15c935194 100644
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -11,14 +11,7 @@
#define NGX_HTTP_REFERER_NO_URI_PART ((void *) 4)
-#if (NGX_PCRE)
-
-typedef struct {
- ngx_regex_t *regex;
- ngx_str_t name;
-} ngx_http_referer_regex_t;
-
-#else
+#if !(NGX_PCRE)
#define ngx_regex_t void
@@ -168,34 +161,23 @@ ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
#if (NGX_PCRE)
if (rlcf->regex) {
- ngx_int_t n;
- ngx_str_t referer;
- ngx_http_referer_regex_t *regex;
+ ngx_int_t rc;
+ ngx_str_t referer;
referer.len = len - 7;
referer.data = ref;
- regex = rlcf->regex->elts;
-
- for (i = 0; i < rlcf->regex->nelts; i++) {
- n = ngx_regex_exec(regex[i].regex, &referer, NULL, 0);
-
- if (n == NGX_REGEX_NO_MATCHED) {
- continue;
- }
-
- if (n < 0) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- ngx_regex_exec_n
- " failed: %d on \"%V\" using \"%V\"",
- n, &referer, &regex[i].name);
- return NGX_ERROR;
- }
-
- /* match */
+ rc = ngx_regex_exec_array(rlcf->regex, &referer, r->connection->log);
+ if (rc == NGX_OK) {
goto valid;
}
+
+ if (rc == NGX_ERROR) {
+ return rc;
+ }
+
+ /* NGX_DECLINED */
}
#endif
@@ -242,6 +224,10 @@ ngx_http_referer_create_conf(ngx_conf_t *cf)
return NGX_CONF_ERROR;
}
+#if (NGX_PCRE)
+ conf->regex = NGX_CONF_UNSET_PTR;
+#endif
+
conf->no_referer = NGX_CONF_UNSET;
conf->blocked_referer = NGX_CONF_UNSET;
@@ -260,6 +246,7 @@ ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent, void *child)
if (conf->keys == NULL) {
conf->hash = prev->hash;
+ ngx_conf_merge_ptr_value(conf->regex, prev->regex, NULL);
ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0);
@@ -335,6 +322,8 @@ ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent, void *child)
conf->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash;
}
+ ngx_conf_merge_ptr_value(conf->regex, prev->regex, NULL);
+
if (conf->no_referer == NGX_CONF_UNSET) {
conf->no_referer = 0;
}
@@ -509,26 +498,25 @@ ngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf,
ngx_str_t *name, ngx_regex_t *regex)
{
#if (NGX_PCRE)
- ngx_str_t err;
- ngx_http_referer_regex_t *rr;
- u_char errstr[NGX_MAX_CONF_ERRSTR];
+ ngx_str_t err;
+ ngx_regex_elt_t *re;
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
- if (rlcf->regex == NULL) {
- rlcf->regex = ngx_array_create(cf->pool, 2,
- sizeof(ngx_http_referer_regex_t));
+ if (rlcf->regex == NGX_CONF_UNSET_PTR) {
+ rlcf->regex = ngx_array_create(cf->pool, 2, sizeof(ngx_regex_elt_t));
if (rlcf->regex == NULL) {
return NGX_CONF_ERROR;
}
}
- rr = ngx_array_push(rlcf->regex);
- if (rr == NULL) {
+ re = ngx_array_push(rlcf->regex);
+ if (re == NULL) {
return NGX_CONF_ERROR;
}
if (regex) {
- rr->regex = regex;
- rr->name = *name;
+ re->regex = regex;
+ re->name = name->data;
return NGX_CONF_OK;
}
@@ -539,14 +527,14 @@ ngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf,
name->len--;
name->data++;
- rr->regex = ngx_regex_compile(name, NGX_REGEX_CASELESS, cf->pool, &err);
+ re->regex = ngx_regex_compile(name, NGX_REGEX_CASELESS, cf->pool, &err);
- if (rr->regex == NULL) {
+ if (re->regex == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
return NGX_CONF_ERROR;
}
- rr->name = *name;
+ re->name = name->data;
return NGX_CONF_OK;