Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 3325:42c16d8bddbe
regex named captures
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 16 Nov 2009 12:19:02 +0000 |
parents | fcd98af88df3 |
children | ac9c0380337d |
comparison
equal
deleted
inserted
replaced
3324:616da2ea901f | 3325:42c16d8bddbe |
---|---|
2405 return f; | 2405 return f; |
2406 } | 2406 } |
2407 | 2407 |
2408 n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3); | 2408 n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3); |
2409 | 2409 |
2410 if (n >= 0) { /* match */ | |
2411 f->script_name.len = captures[3] - captures[2]; | |
2412 f->script_name.data = r->uri.data; | |
2413 | |
2414 f->path_info.len = captures[5] - captures[4]; | |
2415 f->path_info.data = r->uri.data + f->script_name.len; | |
2416 | |
2417 return f; | |
2418 } | |
2419 | |
2410 if (n == NGX_REGEX_NO_MATCHED) { | 2420 if (n == NGX_REGEX_NO_MATCHED) { |
2411 f->script_name = r->uri; | 2421 f->script_name = r->uri; |
2412 return f; | 2422 return f; |
2413 } | 2423 } |
2414 | 2424 |
2415 if (n < 0) { | 2425 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
2416 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 2426 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", |
2417 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", | 2427 n, &r->uri, &flcf->split_name); |
2418 n, &r->uri, &flcf->split_name); | 2428 return NULL; |
2419 return NULL; | |
2420 } | |
2421 | |
2422 /* match */ | |
2423 | |
2424 f->script_name.len = captures[3] - captures[2]; | |
2425 f->script_name.data = r->uri.data; | |
2426 | |
2427 f->path_info.len = captures[5] - captures[4]; | |
2428 f->path_info.data = r->uri.data + f->script_name.len; | |
2429 | |
2430 return f; | |
2431 | 2429 |
2432 #else | 2430 #else |
2433 | 2431 |
2434 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | 2432 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); |
2435 | 2433 |
2516 ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2514 ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2517 { | 2515 { |
2518 #if (NGX_PCRE) | 2516 #if (NGX_PCRE) |
2519 ngx_http_fastcgi_loc_conf_t *flcf = conf; | 2517 ngx_http_fastcgi_loc_conf_t *flcf = conf; |
2520 | 2518 |
2521 ngx_int_t n; | 2519 ngx_str_t *value; |
2522 ngx_str_t *value, err; | 2520 ngx_regex_compile_t rc; |
2523 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 2521 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
2524 | 2522 |
2525 value = cf->args->elts; | 2523 value = cf->args->elts; |
2526 | 2524 |
2527 flcf->split_name = value[1]; | 2525 flcf->split_name = value[1]; |
2528 | 2526 |
2529 err.len = NGX_MAX_CONF_ERRSTR; | 2527 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
2530 err.data = errstr; | 2528 |
2531 | 2529 rc.pattern = value[1]; |
2532 flcf->split_regex = ngx_regex_compile(&value[1], 0, cf->pool, &err); | 2530 rc.pool = cf->pool; |
2533 | 2531 rc.err.len = NGX_MAX_CONF_ERRSTR; |
2534 if (flcf->split_regex == NULL) { | 2532 rc.err.data = errstr; |
2535 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | 2533 |
2534 if (ngx_regex_compile(&rc) != NGX_OK) { | |
2535 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); | |
2536 return NGX_CONF_ERROR; | 2536 return NGX_CONF_ERROR; |
2537 } | 2537 } |
2538 | 2538 |
2539 n = ngx_regex_capture_count(flcf->split_regex); | 2539 if (rc.captures != 2) { |
2540 | |
2541 if (n < 0) { | |
2542 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2543 ngx_regex_capture_count_n " failed for " | |
2544 "pattern \"%V\"", &value[1]); | |
2545 return NGX_CONF_ERROR; | |
2546 } | |
2547 | |
2548 if (n != 2) { | |
2549 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2540 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2550 "pattern \"%V\" must have 2 captures", &value[1]); | 2541 "pattern \"%V\" must have 2 captures", &value[1]); |
2551 return NGX_CONF_ERROR; | 2542 return NGX_CONF_ERROR; |
2552 } | 2543 } |
2544 | |
2545 flcf->split_regex = rc.regex; | |
2553 | 2546 |
2554 return NGX_CONF_OK; | 2547 return NGX_CONF_OK; |
2555 | 2548 |
2556 #else | 2549 #else |
2557 | 2550 |