Mercurial > hg > nginx-vendor-0-7
comparison src/http/modules/ngx_http_rewrite_module.c @ 184:71ff1e2b484a NGINX_0_3_39
nginx 0.3.39
*) Feature: the "uninitialized_variable_warn" directive; the logging
level of the "uninitialized variable" message was lowered from
"alert" to "warn".
*) Feature: the "override_charset" directive.
*) Change: now if the unknown variable is used in the "echo" and "if
expr='$name'" SSI-commands, then the "unknown variable" message is
not logged.
*) Bugfix: the active connection counter increased on the exceeding of
the connection limit specified by the "worker_connections"
directive; bug appeared in 0.2.0.
*) Bugfix: the limit rate might not work on some condition; bug
appeared in 0.3.38.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 17 Apr 2006 00:00:00 +0400 |
parents | 4cd3e70c4d60 |
children | 54aabf2b0bc6 |
comparison
equal
deleted
inserted
replaced
183:f4b38f37ca5b | 184:71ff1e2b484a |
---|---|
14 | 14 |
15 ngx_uint_t captures; | 15 ngx_uint_t captures; |
16 ngx_uint_t stack_size; | 16 ngx_uint_t stack_size; |
17 | 17 |
18 ngx_flag_t log; | 18 ngx_flag_t log; |
19 ngx_flag_t uninitialized_variable_warn; | |
19 } ngx_http_rewrite_loc_conf_t; | 20 } ngx_http_rewrite_loc_conf_t; |
20 | 21 |
21 | 22 |
22 static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf); | 23 static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf); |
23 static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, | 24 static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, |
89 NGX_HTTP_LOC_CONF_OFFSET, | 90 NGX_HTTP_LOC_CONF_OFFSET, |
90 0, | 91 0, |
91 NULL }, | 92 NULL }, |
92 | 93 |
93 { ngx_string("rewrite_log"), | 94 { ngx_string("rewrite_log"), |
94 NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF | 95 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF |
95 |NGX_CONF_TAKE1, | 96 |NGX_HTTP_LIF_CONF|NGX_CONF_FLAG, |
96 ngx_conf_set_flag_slot, | 97 ngx_conf_set_flag_slot, |
97 NGX_HTTP_LOC_CONF_OFFSET, | 98 NGX_HTTP_LOC_CONF_OFFSET, |
98 offsetof(ngx_http_rewrite_loc_conf_t, log), | 99 offsetof(ngx_http_rewrite_loc_conf_t, log), |
100 NULL }, | |
101 | |
102 { ngx_string("uninitialized_variable_warn"), | |
103 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF | |
104 |NGX_HTTP_LIF_CONF|NGX_CONF_FLAG, | |
105 ngx_conf_set_flag_slot, | |
106 NGX_HTTP_LOC_CONF_OFFSET, | |
107 offsetof(ngx_http_rewrite_loc_conf_t, uninitialized_variable_warn), | |
99 NULL }, | 108 NULL }, |
100 | 109 |
101 ngx_null_command | 110 ngx_null_command |
102 }; | 111 }; |
103 | 112 |
136 static ngx_int_t | 145 static ngx_int_t |
137 ngx_http_rewrite_handler(ngx_http_request_t *r) | 146 ngx_http_rewrite_handler(ngx_http_request_t *r) |
138 { | 147 { |
139 ngx_http_script_code_pt code; | 148 ngx_http_script_code_pt code; |
140 ngx_http_script_engine_t *e; | 149 ngx_http_script_engine_t *e; |
141 ngx_http_rewrite_loc_conf_t *cf; | 150 ngx_http_rewrite_loc_conf_t *rlcf; |
142 | 151 |
143 cf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module); | 152 rlcf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module); |
144 | 153 |
145 if (cf->codes == NULL) { | 154 if (rlcf->codes == NULL) { |
146 return NGX_DECLINED; | 155 return NGX_DECLINED; |
147 } | 156 } |
148 | 157 |
149 e = ngx_pcalloc(r->pool, sizeof(ngx_http_script_engine_t)); | 158 e = ngx_pcalloc(r->pool, sizeof(ngx_http_script_engine_t)); |
150 if (e == NULL) { | 159 if (e == NULL) { |
151 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 160 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
152 } | 161 } |
153 | 162 |
154 e->sp = ngx_pcalloc(r->pool, | 163 e->sp = ngx_pcalloc(r->pool, |
155 cf->stack_size * sizeof(ngx_http_variable_value_t)); | 164 rlcf->stack_size * sizeof(ngx_http_variable_value_t)); |
156 if (e->sp == NULL) { | 165 if (e->sp == NULL) { |
157 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 166 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
158 } | 167 } |
159 | 168 |
160 if (cf->captures) { | 169 if (rlcf->captures) { |
161 e->captures = ngx_palloc(r->pool, cf->captures * sizeof(int)); | 170 e->captures = ngx_palloc(r->pool, rlcf->captures * sizeof(int)); |
162 if (e->captures == NULL) { | 171 if (e->captures == NULL) { |
163 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 172 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
164 } | 173 } |
165 | 174 |
166 } else { | 175 } else { |
167 e->captures = NULL; | 176 e->captures = NULL; |
168 } | 177 } |
169 | 178 |
170 e->ip = cf->codes->elts; | 179 e->ip = rlcf->codes->elts; |
171 e->request = r; | 180 e->request = r; |
172 e->quote = 1; | 181 e->quote = 1; |
173 e->log = cf->log; | 182 e->log = rlcf->log; |
174 e->status = NGX_DECLINED; | 183 e->status = NGX_DECLINED; |
175 | 184 |
176 while (*(uintptr_t *) e->ip) { | 185 while (*(uintptr_t *) e->ip) { |
177 code = *(ngx_http_script_code_pt *) e->ip; | 186 code = *(ngx_http_script_code_pt *) e->ip; |
178 code(e); | 187 code(e); |
184 | 193 |
185 static ngx_int_t | 194 static ngx_int_t |
186 ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, | 195 ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
187 uintptr_t data) | 196 uintptr_t data) |
188 { | 197 { |
189 ngx_http_variable_t *var; | 198 ngx_http_variable_t *var; |
190 ngx_http_core_main_conf_t *cmcf; | 199 ngx_http_core_main_conf_t *cmcf; |
200 ngx_http_rewrite_loc_conf_t *rlcf; | |
201 | |
202 rlcf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module); | |
203 | |
204 if (rlcf->uninitialized_variable_warn == 0) { | |
205 *v = ngx_http_variable_null_value; | |
206 return NGX_OK; | |
207 } | |
191 | 208 |
192 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 209 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
193 | 210 |
194 var = cmcf->variables.elts; | 211 var = cmcf->variables.elts; |
195 | 212 |
197 * the ngx_http_rewrite_module sets variables directly in r->variables, | 214 * the ngx_http_rewrite_module sets variables directly in r->variables, |
198 * and they should be handled by ngx_http_get_indexed_variable(), | 215 * and they should be handled by ngx_http_get_indexed_variable(), |
199 * so the handler is called only if the variable is not initialized | 216 * so the handler is called only if the variable is not initialized |
200 */ | 217 */ |
201 | 218 |
202 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 219 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, |
203 "using uninitialized \"%V\" variable", &var[data].name); | 220 "using uninitialized \"%V\" variable", &var[data].name); |
204 | 221 |
205 *v = ngx_http_variable_null_value; | 222 *v = ngx_http_variable_null_value; |
206 | 223 |
207 return NGX_OK; | 224 return NGX_OK; |
218 return NGX_CONF_ERROR; | 235 return NGX_CONF_ERROR; |
219 } | 236 } |
220 | 237 |
221 conf->stack_size = NGX_CONF_UNSET_UINT; | 238 conf->stack_size = NGX_CONF_UNSET_UINT; |
222 conf->log = NGX_CONF_UNSET; | 239 conf->log = NGX_CONF_UNSET; |
240 conf->uninitialized_variable_warn = NGX_CONF_UNSET; | |
223 | 241 |
224 return conf; | 242 return conf; |
225 } | 243 } |
226 | 244 |
227 | 245 |
232 ngx_http_rewrite_loc_conf_t *conf = child; | 250 ngx_http_rewrite_loc_conf_t *conf = child; |
233 | 251 |
234 uintptr_t *code; | 252 uintptr_t *code; |
235 | 253 |
236 ngx_conf_merge_value(conf->log, prev->log, 0); | 254 ngx_conf_merge_value(conf->log, prev->log, 0); |
255 ngx_conf_merge_value(conf->uninitialized_variable_warn, | |
256 prev->uninitialized_variable_warn, 1); | |
237 ngx_conf_merge_unsigned_value(conf->stack_size, prev->stack_size, 10); | 257 ngx_conf_merge_unsigned_value(conf->stack_size, prev->stack_size, 10); |
238 | 258 |
239 if (conf->codes == NULL) { | 259 if (conf->codes == NULL) { |
240 return NGX_CONF_OK; | 260 return NGX_CONF_OK; |
241 } | 261 } |