Mercurial > hg > nginx-ranges
comparison src/http/ngx_http_script.c @ 635:e67b227c8dbb default tip
Merge with current.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:07:55 +0400 |
parents | b4dcae568a2a |
children |
comparison
equal
deleted
inserted
replaced
578:f3a9e57d2e17 | 635:e67b227c8dbb |
---|---|
209 | 209 |
210 return NGX_OK; | 210 return NGX_OK; |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 char * | |
215 ngx_http_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
216 { | |
217 char *p = conf; | |
218 | |
219 ngx_str_t *value; | |
220 ngx_http_complex_value_t **cv; | |
221 ngx_http_compile_complex_value_t ccv; | |
222 | |
223 cv = (ngx_http_complex_value_t **) (p + cmd->offset); | |
224 | |
225 if (*cv != NULL) { | |
226 return "duplicate"; | |
227 } | |
228 | |
229 *cv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); | |
230 if (*cv == NULL) { | |
231 return NGX_CONF_ERROR; | |
232 } | |
233 | |
234 value = cf->args->elts; | |
235 | |
236 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
237 | |
238 ccv.cf = cf; | |
239 ccv.value = &value[1]; | |
240 ccv.complex_value = *cv; | |
241 | |
242 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
243 return NGX_CONF_ERROR; | |
244 } | |
245 | |
246 return NGX_CONF_OK; | |
247 } | |
248 | |
249 | |
250 ngx_int_t | |
251 ngx_http_test_predicates(ngx_http_request_t *r, ngx_array_t *predicates) | |
252 { | |
253 ngx_str_t val; | |
254 ngx_uint_t i; | |
255 ngx_http_complex_value_t *cv; | |
256 | |
257 if (predicates == NULL) { | |
258 return NGX_OK; | |
259 } | |
260 | |
261 cv = predicates->elts; | |
262 | |
263 for (i = 0; i < predicates->nelts; i++) { | |
264 if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) { | |
265 return NGX_ERROR; | |
266 } | |
267 | |
268 if (val.len && val.data[0] != '0') { | |
269 return NGX_DECLINED; | |
270 } | |
271 } | |
272 | |
273 return NGX_OK; | |
274 } | |
275 | |
276 | |
277 char * | |
278 ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
279 { | |
280 char *p = conf; | |
281 | |
282 ngx_str_t *value; | |
283 ngx_uint_t i; | |
284 ngx_array_t **a; | |
285 ngx_http_complex_value_t *cv; | |
286 ngx_http_compile_complex_value_t ccv; | |
287 | |
288 a = (ngx_array_t **) (p + cmd->offset); | |
289 | |
290 if (*a == NGX_CONF_UNSET_PTR) { | |
291 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_complex_value_t)); | |
292 if (*a == NULL) { | |
293 return NGX_CONF_ERROR; | |
294 } | |
295 } | |
296 | |
297 value = cf->args->elts; | |
298 | |
299 for (i = 1; i < cf->args->nelts; i++) { | |
300 cv = ngx_array_push(*a); | |
301 if (cv == NULL) { | |
302 return NGX_CONF_ERROR; | |
303 } | |
304 | |
305 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
306 | |
307 ccv.cf = cf; | |
308 ccv.value = &value[i]; | |
309 ccv.complex_value = cv; | |
310 | |
311 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
312 return NGX_CONF_ERROR; | |
313 } | |
314 } | |
315 | |
316 return NGX_CONF_OK; | |
317 } | |
318 | |
319 | |
214 ngx_uint_t | 320 ngx_uint_t |
215 ngx_http_script_variables_count(ngx_str_t *value) | 321 ngx_http_script_variables_count(ngx_str_t *value) |
216 { | 322 { |
217 ngx_uint_t i, n; | 323 ngx_uint_t i, n; |
218 | 324 |
981 | 1087 |
982 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, | 1088 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, |
983 NGX_UNESCAPE_REDIRECT); | 1089 NGX_UNESCAPE_REDIRECT); |
984 | 1090 |
985 if (src < e->pos) { | 1091 if (src < e->pos) { |
986 dst = ngx_copy(dst, src, e->pos - src); | 1092 dst = ngx_movemem(dst, src, e->pos - src); |
987 } | 1093 } |
988 | 1094 |
989 e->pos = dst; | 1095 e->pos = dst; |
990 | 1096 |
991 if (code->add_args && r->args.len) { | 1097 if (code->add_args && r->args.len) { |
1006 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | 1112 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
1007 return; | 1113 return; |
1008 } | 1114 } |
1009 | 1115 |
1010 r->headers_out.location->hash = 1; | 1116 r->headers_out.location->hash = 1; |
1011 r->headers_out.location->key.len = sizeof("Location") - 1; | 1117 ngx_str_set(&r->headers_out.location->key, "Location"); |
1012 r->headers_out.location->key.data = (u_char *) "Location"; | |
1013 r->headers_out.location->value = e->buf; | 1118 r->headers_out.location->value = e->buf; |
1014 | 1119 |
1015 e->ip += sizeof(ngx_http_script_regex_end_code_t); | 1120 e->ip += sizeof(ngx_http_script_regex_end_code_t); |
1016 return; | 1121 return; |
1017 } | 1122 } |
1253 { | 1358 { |
1254 ngx_http_script_return_code_t *code; | 1359 ngx_http_script_return_code_t *code; |
1255 | 1360 |
1256 code = (ngx_http_script_return_code_t *) e->ip; | 1361 code = (ngx_http_script_return_code_t *) e->ip; |
1257 | 1362 |
1258 e->status = code->status; | 1363 if (code->status < NGX_HTTP_BAD_REQUEST |
1259 | 1364 || code->text.value.len |
1260 if (code->status == NGX_HTTP_NO_CONTENT) { | 1365 || code->text.lengths) |
1261 e->request->header_only = 1; | 1366 { |
1262 e->request->zero_body = 1; | 1367 e->status = ngx_http_send_response(e->request, code->status, NULL, |
1263 } | 1368 &code->text); |
1264 | 1369 } else { |
1265 e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t); | 1370 e->status = code->status; |
1371 } | |
1372 | |
1373 e->ip = ngx_http_script_exit; | |
1266 } | 1374 } |
1267 | 1375 |
1268 | 1376 |
1269 void | 1377 void |
1270 ngx_http_script_break_code(ngx_http_script_engine_t *e) | 1378 ngx_http_script_break_code(ngx_http_script_engine_t *e) |