nginx-0.3.37-RELEASE import

*) 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.
This commit is contained in:
Igor Sysoev 2006-04-07 14:08:04 +00:00
parent 7469680c6c
commit 94e32ce7f8
19 changed files with 429 additions and 51 deletions

View File

@ -116,6 +116,12 @@ ngx_binout="-Fe"
ngx_objext="obj"
ngx_binext=".exe"
# Borland make
#ngx_long_start='@&&|
# '
#ngx_long_end='|'
# MS nmake
ngx_long_start='@<<
'
ngx_long_end='<<'
@ -123,6 +129,6 @@ ngx_long_regex_cont=' \
'
ngx_long_cont='
'
# MSVC understand / in path
#ngx_regex_dirsep='\\'
#ngx_dirsep="\\"

View File

@ -9,6 +9,47 @@
<title lang="en">nginx changelog</title>
<changes ver="0.3.37" date="07.04.2006">
<change type="feature">
<para lang="ru">
ÄÉÒÅËÔÉ×Á limit_except.
</para>
<para lang="en">
the "limit_except" directive.
</para>
</change>
<change type="feature">
<para lang="ru">
ÄÉÒÅËÔÉ×Á if ÐÏÄÄÅÒÖÉ×ÁÅÔ ÏÐÅÒÁÔÏÒÙ "!~", "!~*", "-f" É "!-f".
</para>
<para lang="en">
the "if" directive supports the "!~", "!~*", "-f", and "!-f" operators.
</para>
</change>
<change type="feature">
<para lang="ru">
ÍÏÄÕÌØ ngx_http_perl_module ÐÏÄÄÅÒÖÉ×ÁÅÔ ÍÅÔÏÄ $r->request_body.
</para>
<para lang="en">
the ngx_http_perl_module supports the $r->request_body method.
</para>
</change>
<change type="bugfix">
<para lang="ru">
× ÍÏÄÕÌÅ ngx_http_addition_filter_module.
</para>
<para lang="en">
in the ngx_http_addition_filter_module.
</para>
</change>
</changes>
<changes ver="0.3.36" date="05.04.2006">
<change type="feature">

View File

@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
#define NGINX_VER "nginx/0.3.36"
#define NGINX_VER "nginx/0.3.37"
#define NGINX_VAR "NGINX"
#define NGX_OLDPID_EXT ".oldbin"

View File

@ -164,10 +164,14 @@ ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts)
return NGX_ERROR;
}
start = nelts / (ngx_cacheline_size / (2 * sizeof(void *)) - 1);
bucket_size = hinit->bucket_size - sizeof(void *);
start = nelts / (bucket_size / (2 * sizeof(void *)) - 1);
start = start ? start : 1;
bucket_size = hinit->bucket_size - sizeof(void *);
if (hinit->max_size > 10000 && hinit->max_size / nelts < 100) {
start = hinit->max_size - 1000;
}
for (size = start; size < hinit->max_size; size++) {

View File

@ -21,8 +21,8 @@
*/
static
ngx_inline size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len)
static ngx_inline size_t
ngx_sprint_uchar(u_char *text, u_char c, size_t len)
{
size_t n;
ngx_uint_t c1, c2;

View File

@ -35,14 +35,16 @@ static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
static ngx_command_t ngx_http_access_commands[] = {
{ ngx_string("allow"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
|NGX_CONF_TAKE1,
ngx_http_access_rule,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("deny"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
|NGX_CONF_TAKE1,
ngx_http_access_rule,
NGX_HTTP_LOC_CONF_OFFSET,
0,

View File

@ -16,8 +16,7 @@ typedef struct {
typedef struct {
unsigned before_body_sent:1;
unsigned after_body_sent:1;
ngx_uint_t before_body_sent;
} ngx_http_addition_ctx_t;
@ -92,6 +91,12 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
if (conf->before_body.len == 0 && conf->after_body.len == 0) {
return ngx_http_next_header_filter(r);
}
if (ngx_strncasecmp(r->headers_out.content_type.data, "text/html",
sizeof("text/html") - 1)
!= 0)
@ -99,12 +104,6 @@ ngx_http_addition_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
if (conf->before_body.len == 0 && conf->after_body.len == 0) {
return ngx_http_next_header_filter(r);
}
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
@ -155,17 +154,14 @@ ngx_http_addition_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
for (cl = in; cl; cl = cl->next) {
if (cl->buf->last_buf) {
cl->buf->last_buf = 0;
cl->buf->sync = 1;
last = 1;
}
}
rc = ngx_http_next_body_filter(r, in);
if (rc == NGX_ERROR
|| !last
|| ctx->after_body_sent
|| conf->after_body.len == 0)
{
if (rc == NGX_ERROR || !last || conf->after_body.len == 0) {
return rc;
}
@ -173,7 +169,7 @@ ngx_http_addition_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_ERROR;
}
ctx->after_body_sent = 1;
ngx_http_set_ctx(r, NULL, ngx_http_addition_filter_module);
return ngx_http_send_special(r, NGX_HTTP_LAST);
}

View File

@ -41,14 +41,16 @@ static ngx_conf_post_handler_pt ngx_http_auth_basic_p = ngx_http_auth_basic;
static ngx_command_t ngx_http_auth_basic_commands[] = {
{ ngx_string("auth_basic"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_basic_loc_conf_t, realm),
&ngx_http_auth_basic_p },
{ ngx_string("auth_basic_user_file"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_basic_loc_conf_t, user_file),
@ -58,7 +60,6 @@ static ngx_command_t ngx_http_auth_basic_commands[] = {
};
ngx_http_module_t ngx_http_auth_basic_module_ctx = {
NULL, /* preconfiguration */
NULL, /* postconfiguration */

View File

@ -217,7 +217,7 @@ ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent, void *child)
}
if ((conf->no_referer == 1 || conf->blocked_referer == 1)
&& conf->keys->keys.nelts == 0 && conf->keys->dns_wildcards.nelts)
&& conf->keys->keys.nelts == 0 && conf->keys->dns_wildcards.nelts == 0)
{
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"the \"none\" or \"blocked\" referers are specified "

View File

@ -578,7 +578,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
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_command_t *cmd, void *conf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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 *cf, ngx_http_rewrite_loc_conf_t *lcf)
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,

View File

@ -261,6 +261,41 @@ header_in(r, key)
RETVAL
SV *
request_body(r)
nginx r
PREINIT:
STRLEN len;
ngx_chain_t *cl;
CODE:
len = 0;
for (cl = r->request_body->bufs; cl; cl = cl->next) {
if (cl->buf->in_file) {
XSRETURN_UNDEF;
}
len += cl->buf->last - cl->buf->pos;
}
if (len == 0) {
XSRETURN_UNDEF;
}
RETVAL = newSV(len);
for (cl = r->request_body->bufs; cl; cl = cl->next) {
sv_catpvn(RETVAL, cl->buf->pos, cl->buf->last - cl->buf->pos);
}
OUTPUT:
RETVAL
int
header_out(r, key, value)
nginx r

View File

@ -595,8 +595,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (rc == NGX_BUSY) {
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
"conflicting server name \"%V\", ignored",
&name[s].name);
"conflicting server name \"%V\" on %s, ignored",
&name[s].name, in_addr[a].listen_conf->addr);
}
}
@ -617,8 +617,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (rc == NGX_BUSY) {
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
"conflicting server name \"%V\", ignored",
&name[s].name);
"conflicting server name \"%V\" on %s, ignored",
&name[s].name, in_addr[a].listen_conf->addr);
}
}

View File

@ -42,7 +42,8 @@ typedef struct {
#define NGX_HTTP_LOC_CONF 0x08000000
#define NGX_HTTP_UPS_CONF 0x10000000
#define NGX_HTTP_SIF_CONF 0x20000000
#define NGX_HTTP_LIF_CONF 0x80000000
#define NGX_HTTP_LIF_CONF 0x40000000
#define NGX_HTTP_LMT_CONF 0x80000000
#define NGX_HTTP_MAIN_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, main_conf)

View File

@ -11,6 +11,12 @@
#include <nginx.h>
typedef struct {
char *name;
uint32_t method;
} ngx_http_method_name_t;
#define NGX_HTTP_LOCATION_EXACT 1
#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
#define NGX_HTTP_LOCATION_NOREGEX 3
@ -48,6 +54,8 @@ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
@ -225,6 +233,13 @@ static ngx_command_t ngx_http_core_commands[] = {
0,
NULL },
{ ngx_string("limit_except"),
NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
ngx_http_core_limit_except,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("client_max_body_size"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
@ -711,6 +726,11 @@ ngx_http_update_location_config(ngx_http_request_t *r)
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (r->method & clcf->limit_except) {
r->loc_conf = clcf->limit_except_loc_conf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
}
r->connection->log->file = clcf->err_log->file;
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
r->connection->log->log_level = clcf->err_log->log_level;
@ -1949,6 +1969,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
* set by ngx_pcalloc():
*
* lcf->root = { 0, NULL };
* lcf->limit_except = 0;
* lcf->post_action = { 0, NULL };
* lcf->types = NULL;
* lcf->default_type = { 0, NULL };
@ -2245,6 +2266,9 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ls->addr = INADDR_ANY;
}
n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
if (cf->args->nelts == 2) {
return NGX_CONF_OK;
}
@ -2480,6 +2504,124 @@ ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
static ngx_http_method_name_t ngx_methods_names[] = {
{ "GET", (uint32_t) ~NGX_HTTP_GET },
{ "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
{ NULL, 0 }
};
static char *
ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *clcf = conf;
char *rv;
void *mconf;
ngx_str_t *value;
ngx_uint_t i;
ngx_conf_t save;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx, *pctx;
ngx_http_method_name_t *name;
ngx_http_core_loc_conf_t *lcf, **clcfp;
if (clcf->limit_except) {
return "duplicate";
}
clcf->limit_except = 0xffffffff;
value = cf->args->elts;
for (i = 1; i < cf->args->nelts; i++) {
for (name = ngx_methods_names; name->name; name++) {
if (ngx_strcasecmp(value[i].data, name->name) == 0) {
clcf->limit_except &= name->method;
goto next;
}
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid method \"%V\"", &value[i]);
return NGX_CONF_ERROR;
next:
continue;
}
if (!(clcf->limit_except & NGX_HTTP_GET)) {
clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
}
ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
if (ctx == NULL) {
return NGX_CONF_ERROR;
}
pctx = cf->ctx;
ctx->main_conf = pctx->main_conf;
ctx->srv_conf = pctx->srv_conf;
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
if (ctx->loc_conf == NULL) {
return NGX_CONF_ERROR;
}
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
continue;
}
module = ngx_modules[i]->ctx;
if (module->create_loc_conf) {
mconf = module->create_loc_conf(cf);
if (mconf == NULL) {
return NGX_CONF_ERROR;
}
ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
}
}
lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
clcf->limit_except_loc_conf = ctx->loc_conf;
lcf->loc_conf = ctx->loc_conf;
lcf->name = clcf->name;
lcf->noname = 1;
if (clcf->locations.elts == NULL) {
if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *))
== NGX_ERROR)
{
return NGX_CONF_ERROR;
}
}
clcfp = ngx_array_push(&clcf->locations);
if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
*clcfp = lcf;
save = *cf;
cf->ctx = ctx;
cf->cmd_type = NGX_HTTP_LMT_CONF;
rv = ngx_conf_parse(cf, NULL);
*cf = save;
return rv;
}
static char *
ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{

View File

@ -28,6 +28,8 @@ typedef struct {
ngx_uint_t deferred_accept;
#endif
u_char addr[INET_ADDRSTRLEN + 6];
} ngx_http_listen_conf_t;
@ -196,6 +198,9 @@ struct ngx_http_core_loc_conf_s {
/* pointer to the modules' loc_conf */
void **loc_conf ;
uint32_t limit_except;
void **limit_except_loc_conf ;
ngx_http_handler_pt handler;
ngx_str_t root; /* root, alias */

View File

@ -410,6 +410,8 @@ void ngx_http_init_request(ngx_event_t *rev)
r->start_time = ngx_time();
r->method = NGX_HTTP_UNKNOWN;
r->headers_in.content_length_n = -1;
r->headers_in.keep_alive_n = -1;
r->headers_out.content_length_n = -1;

View File

@ -19,9 +19,10 @@
#define NGX_HTTP_VERSION_10 1000
#define NGX_HTTP_VERSION_11 1001
#define NGX_HTTP_GET 1
#define NGX_HTTP_HEAD 2
#define NGX_HTTP_POST 3
#define NGX_HTTP_UNKNOWN 1
#define NGX_HTTP_GET 2
#define NGX_HTTP_HEAD 4
#define NGX_HTTP_POST 8
#define NGX_HTTP_CONNECTION_CLOSE 1
#define NGX_HTTP_CONNECTION_KEEP_ALIVE 2

View File

@ -588,8 +588,15 @@ ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
e->ncaptures = 0;
if (code->test) {
e->sp->len = 0;
e->sp->data = (u_char *) "";
if (code->negative_test) {
e->sp->len = 1;
e->sp->data = (u_char *) "1";
} else {
e->sp->len = 0;
e->sp->data = (u_char *) "";
}
e->sp++;
e->ip += sizeof(ngx_http_script_regex_code_t);
@ -618,8 +625,15 @@ ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
e->ncaptures = code->ncaptures;
if (code->test) {
e->sp->len = 1;
e->sp->data = (u_char *) "1";
if (code->negative_test) {
e->sp->len = 0;
e->sp->data = (u_char *) "";
} else {
e->sp->len = 1;
e->sp->data = (u_char *) "1";
}
e->sp++;
e->ip += sizeof(ngx_http_script_regex_code_t);
@ -910,6 +924,69 @@ ngx_http_script_not_equal_code(ngx_http_script_engine_t *e)
}
void
ngx_http_script_file_code(ngx_http_script_engine_t *e)
{
ngx_err_t err;
ngx_file_info_t fi;
ngx_http_variable_value_t *value;
ngx_http_script_file_code_t *code;
value = e->sp - 1;
code = (ngx_http_script_file_code_t *) e->ip;
e->ip += sizeof(ngx_http_script_file_code_t);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http script file op %p", code->op);
if (ngx_file_info(value->data, &fi) == -1) {
err = ngx_errno;
if (err != NGX_ENOENT && err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, e->request->connection->log, err,
ngx_file_info_n " \"%s\" failed", value->data);
}
switch (code->op) {
case ngx_http_script_file_plain:
goto false;
case ngx_http_script_file_not_plain:
goto true;
}
goto false;
}
switch (code->op) {
case ngx_http_script_file_plain:
if (ngx_is_file(&fi)) {
goto true;
}
goto false;
case ngx_http_script_file_not_plain:
if (ngx_is_file(&fi)) {
goto false;
}
goto true;
}
false:
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http script file op false");
*value = ngx_http_variable_null_value;
return;
true:
*value = ngx_http_variable_true_value;
return;
}
void
ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
{

View File

@ -52,7 +52,6 @@ typedef struct {
void *main;
unsigned compile_args:1;
unsigned compile_null:1;
unsigned complete_lengths:1;
unsigned complete_values:1;
@ -94,6 +93,7 @@ typedef struct {
uintptr_t next;
uintptr_t test:1;
uintptr_t negative_test:1;
uintptr_t uri:1;
uintptr_t args:1;
@ -129,6 +129,18 @@ typedef struct {
} ngx_http_script_return_code_t;
typedef enum {
ngx_http_script_file_plain = 0,
ngx_http_script_file_not_plain
} ngx_http_script_file_op_e;
typedef struct {
ngx_http_script_code_pt code;
uintptr_t op;
} ngx_http_script_file_code_t;
typedef struct {
ngx_http_script_code_pt code;
uintptr_t next;
@ -177,6 +189,7 @@ void ngx_http_script_break_code(ngx_http_script_engine_t *e);
void ngx_http_script_if_code(ngx_http_script_engine_t *e);
void ngx_http_script_equal_code(ngx_http_script_engine_t *e);
void ngx_http_script_not_equal_code(ngx_http_script_engine_t *e);
void ngx_http_script_file_code(ngx_http_script_engine_t *e);
void ngx_http_script_complex_value_code(ngx_http_script_engine_t *e);
void ngx_http_script_value_code(ngx_http_script_engine_t *e);
void ngx_http_script_set_var_code(ngx_http_script_engine_t *e);