comparison src/http/modules/ngx_http_referer_module.c @ 358:9121a0a91f47 NGINX_0_6_23

nginx 0.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.
author Igor Sysoev <http://sysoev.ru>
date Thu, 27 Dec 2007 00:00:00 +0300
parents b743d290eb3b
children 54fad6c4b555
comparison
equal deleted inserted replaced
357:16d557a75356 358:9121a0a91f47
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11 11
12 #define NGX_HTTP_REFERER_NO_URI_PART ((void *) 4) 12 #define NGX_HTTP_REFERER_NO_URI_PART ((void *) 4)
13 13
14 #if (NGX_PCRE) 14 #if !(NGX_PCRE)
15
16 typedef struct {
17 ngx_regex_t *regex;
18 ngx_str_t name;
19 } ngx_http_referer_regex_t;
20
21 #else
22 15
23 #define ngx_regex_t void 16 #define ngx_regex_t void
24 17
25 #endif 18 #endif
26 19
166 } 159 }
167 160
168 #if (NGX_PCRE) 161 #if (NGX_PCRE)
169 162
170 if (rlcf->regex) { 163 if (rlcf->regex) {
171 ngx_int_t n; 164 ngx_int_t rc;
172 ngx_str_t referer; 165 ngx_str_t referer;
173 ngx_http_referer_regex_t *regex;
174 166
175 referer.len = len - 7; 167 referer.len = len - 7;
176 referer.data = ref; 168 referer.data = ref;
177 169
178 regex = rlcf->regex->elts; 170 rc = ngx_regex_exec_array(rlcf->regex, &referer, r->connection->log);
179 171
180 for (i = 0; i < rlcf->regex->nelts; i++) { 172 if (rc == NGX_OK) {
181 n = ngx_regex_exec(regex[i].regex, &referer, NULL, 0);
182
183 if (n == NGX_REGEX_NO_MATCHED) {
184 continue;
185 }
186
187 if (n < 0) {
188 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
189 ngx_regex_exec_n
190 " failed: %d on \"%V\" using \"%V\"",
191 n, &referer, &regex[i].name);
192 return NGX_ERROR;
193 }
194
195 /* match */
196
197 goto valid; 173 goto valid;
198 } 174 }
175
176 if (rc == NGX_ERROR) {
177 return rc;
178 }
179
180 /* NGX_DECLINED */
199 } 181 }
200 182
201 #endif 183 #endif
202 184
203 invalid: 185 invalid:
240 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_referer_conf_t)); 222 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_referer_conf_t));
241 if (conf == NULL) { 223 if (conf == NULL) {
242 return NGX_CONF_ERROR; 224 return NGX_CONF_ERROR;
243 } 225 }
244 226
227 #if (NGX_PCRE)
228 conf->regex = NGX_CONF_UNSET_PTR;
229 #endif
230
245 conf->no_referer = NGX_CONF_UNSET; 231 conf->no_referer = NGX_CONF_UNSET;
246 conf->blocked_referer = NGX_CONF_UNSET; 232 conf->blocked_referer = NGX_CONF_UNSET;
247 233
248 return conf; 234 return conf;
249 } 235 }
258 ngx_hash_init_t hash; 244 ngx_hash_init_t hash;
259 245
260 if (conf->keys == NULL) { 246 if (conf->keys == NULL) {
261 conf->hash = prev->hash; 247 conf->hash = prev->hash;
262 248
249 ngx_conf_merge_ptr_value(conf->regex, prev->regex, NULL);
263 ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0); 250 ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
264 ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0); 251 ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0);
265 252
266 return NGX_CONF_OK; 253 return NGX_CONF_OK;
267 } 254 }
333 } 320 }
334 321
335 conf->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash; 322 conf->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash;
336 } 323 }
337 324
325 ngx_conf_merge_ptr_value(conf->regex, prev->regex, NULL);
326
338 if (conf->no_referer == NGX_CONF_UNSET) { 327 if (conf->no_referer == NGX_CONF_UNSET) {
339 conf->no_referer = 0; 328 conf->no_referer = 0;
340 } 329 }
341 330
342 if (conf->blocked_referer == NGX_CONF_UNSET) { 331 if (conf->blocked_referer == NGX_CONF_UNSET) {
507 static char * 496 static char *
508 ngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf, 497 ngx_http_add_regex_referer(ngx_conf_t *cf, ngx_http_referer_conf_t *rlcf,
509 ngx_str_t *name, ngx_regex_t *regex) 498 ngx_str_t *name, ngx_regex_t *regex)
510 { 499 {
511 #if (NGX_PCRE) 500 #if (NGX_PCRE)
512 ngx_str_t err; 501 ngx_str_t err;
513 ngx_http_referer_regex_t *rr; 502 ngx_regex_elt_t *re;
514 u_char errstr[NGX_MAX_CONF_ERRSTR]; 503 u_char errstr[NGX_MAX_CONF_ERRSTR];
515 504
516 if (rlcf->regex == NULL) { 505 if (rlcf->regex == NGX_CONF_UNSET_PTR) {
517 rlcf->regex = ngx_array_create(cf->pool, 2, 506 rlcf->regex = ngx_array_create(cf->pool, 2, sizeof(ngx_regex_elt_t));
518 sizeof(ngx_http_referer_regex_t));
519 if (rlcf->regex == NULL) { 507 if (rlcf->regex == NULL) {
520 return NGX_CONF_ERROR; 508 return NGX_CONF_ERROR;
521 } 509 }
522 } 510 }
523 511
524 rr = ngx_array_push(rlcf->regex); 512 re = ngx_array_push(rlcf->regex);
525 if (rr == NULL) { 513 if (re == NULL) {
526 return NGX_CONF_ERROR; 514 return NGX_CONF_ERROR;
527 } 515 }
528 516
529 if (regex) { 517 if (regex) {
530 rr->regex = regex; 518 re->regex = regex;
531 rr->name = *name; 519 re->name = name->data;
532 520
533 return NGX_CONF_OK; 521 return NGX_CONF_OK;
534 } 522 }
535 523
536 err.len = NGX_MAX_CONF_ERRSTR; 524 err.len = NGX_MAX_CONF_ERRSTR;
537 err.data = errstr; 525 err.data = errstr;
538 526
539 name->len--; 527 name->len--;
540 name->data++; 528 name->data++;
541 529
542 rr->regex = ngx_regex_compile(name, NGX_REGEX_CASELESS, cf->pool, &err); 530 re->regex = ngx_regex_compile(name, NGX_REGEX_CASELESS, cf->pool, &err);
543 531
544 if (rr->regex == NULL) { 532 if (re->regex == NULL) {
545 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); 533 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
546 return NGX_CONF_ERROR; 534 return NGX_CONF_ERROR;
547 } 535 }
548 536
549 rr->name = *name; 537 re->name = name->data;
550 538
551 return NGX_CONF_OK; 539 return NGX_CONF_OK;
552 540
553 #else 541 #else
554 542