Mercurial > hg > nginx-ranges
diff src/http/modules/ngx_http_rewrite_module.c @ 180:4cd3e70c4d60 NGINX_0_3_37
nginx 0.3.37
*) Feature: the "limit_except" directive.
*) Feature: the "if" directive supports the "!~", "!~*", "-f", and
"!-f" operators.
*) Feature: the ngx_http_perl_module supports the $r->request_body
method.
*) Bugfix: in the ngx_http_addition_filter_module.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 07 Apr 2006 00:00:00 +0400 |
parents | df17fbafec8f |
children | 71ff1e2b484a |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_rewrite_module.c +++ b/src/http/modules/ngx_http_rewrite_module.c @@ -578,7 +578,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_ elts = lcf->codes->elts; - /* the inside directives must compile to the same code array */ + /* the inner directives must be compiled to the same code array */ nlcf = ctx->loc_conf[ngx_http_rewrite_module.ctx_index]; nlcf->codes = lcf->codes; @@ -629,9 +629,12 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_ static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) { + u_char *p; + size_t len; ngx_str_t *value, err; ngx_uint_t cur, last, n; ngx_http_script_code_pt *code; + ngx_http_script_file_code_t *fop; ngx_http_script_regex_code_t *regex; u_char errstr[NGX_MAX_CONF_ERRSTR]; @@ -667,11 +670,14 @@ ngx_http_rewrite_if_condition(ngx_conf_t value[last].data[value[last].len] = '\0'; } - if (value[cur].len > 1 && value[cur].data[0] == '$') { + len = value[cur].len; + p = value[cur].data; + + if (len > 1 && p[0] == '$') { if (cur != last && cur + 2 != last) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid condition \"%V\"", &value[cur]); + "invalid condition \"%V\"", &value[cur]); return NGX_CONF_ERROR; } @@ -685,7 +691,10 @@ ngx_http_rewrite_if_condition(ngx_conf_t cur++; - if (value[cur].len == 1 && value[cur].data[0] == '=') { + len = value[cur].len; + p = value[cur].data; + + if (len == 1 && p[0] == '=') { if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { return NGX_CONF_ERROR; @@ -702,9 +711,8 @@ ngx_http_rewrite_if_condition(ngx_conf_t return NGX_CONF_OK; } - if (value[cur].len == 2 - && value[cur].data[0] == '!' && value[cur].data[1] == '=') - { + if (len == 2 && p[0] == '!' && p[1] == '=') { + if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { return NGX_CONF_ERROR; } @@ -719,9 +727,10 @@ ngx_http_rewrite_if_condition(ngx_conf_t return NGX_CONF_OK; } - if ((value[cur].len == 1 && value[cur].data[0] == '~') - || (value[cur].len == 2 - && value[cur].data[0] == '~' && value[cur].data[1] == '*')) + if ((len == 1 && p[0] == '~') + || (len == 2 && p[0] == '~' && p[1] == '*') + || (len == 2 && p[0] == '!' && p[1] == '~') + || (len == 3 && p[0] == '!' && p[1] == '~' && p[2] == '*')) { regex = ngx_http_script_start_code(cf->pool, &lcf->codes, sizeof(ngx_http_script_regex_code_t)); @@ -735,8 +744,8 @@ ngx_http_rewrite_if_condition(ngx_conf_t err.data = errstr; regex->regex = ngx_regex_compile(&value[last], - (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0, - cf->pool, &err); + (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0, + cf->pool, &err); if (regex->regex == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); @@ -746,6 +755,9 @@ ngx_http_rewrite_if_condition(ngx_conf_t regex->code = ngx_http_script_regex_start_code; regex->next = sizeof(ngx_http_script_regex_code_t); regex->test = 1; + if (p[0] == '!') { + regex->negative_test = 1; + } regex->name = value[last]; n = ngx_regex_capture_count(regex->regex); @@ -764,6 +776,46 @@ ngx_http_rewrite_if_condition(ngx_conf_t ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"%V\" in condition", &value[cur]); return NGX_CONF_ERROR; + + } else if ((len == 2 && p[0] == '-') + || (len == 3 && p[0] == '!' && p[1] == '-')) + { + if (cur + 1 != last) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid condition \"%V\"", &value[cur]); + return NGX_CONF_ERROR; + } + + value[last].data[value[last].len] = '\0'; + value[last].len++; + + if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { + return NGX_CONF_ERROR; + } + + fop = ngx_http_script_start_code(cf->pool, &lcf->codes, + sizeof(ngx_http_script_file_code_t)); + if (fop == NULL) { + return NGX_CONF_ERROR; + } + + fop->code = ngx_http_script_file_code; + + if (p[1] == 'f') { + fop->op = ngx_http_script_file_plain; + return NGX_CONF_OK; + } + + if (p[0] == '!') { + if (p[2] == 'f') { + fop->op = ngx_http_script_file_not_plain; + return NGX_CONF_OK; + } + } + + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid condition \"%V\"", &value[cur]); + return NGX_CONF_ERROR; } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,