Mercurial > hg > nginx-quic
comparison src/http/ngx_http_core_module.c @ 2548:163114282d2c
captures support in location and alias
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 06 Mar 2009 12:49:22 +0000 |
parents | e73f70b4ca5c |
children | 2d34fba7cf06 |
comparison
equal
deleted
inserted
replaced
2547:912ce4113f21 | 2548:163114282d2c |
---|---|
1335 ngx_http_core_find_location(ngx_http_request_t *r) | 1335 ngx_http_core_find_location(ngx_http_request_t *r) |
1336 { | 1336 { |
1337 ngx_int_t rc; | 1337 ngx_int_t rc; |
1338 ngx_http_core_loc_conf_t *pclcf; | 1338 ngx_http_core_loc_conf_t *pclcf; |
1339 #if (NGX_PCRE) | 1339 #if (NGX_PCRE) |
1340 ngx_int_t n; | 1340 ngx_int_t n, len; |
1341 ngx_uint_t noregex; | 1341 ngx_uint_t noregex; |
1342 ngx_http_core_loc_conf_t *clcf, **clcfp; | 1342 ngx_http_core_loc_conf_t *clcf, **clcfp; |
1343 | 1343 |
1344 noregex = 0; | 1344 noregex = 0; |
1345 #endif | 1345 #endif |
1369 | 1369 |
1370 #if (NGX_PCRE) | 1370 #if (NGX_PCRE) |
1371 | 1371 |
1372 if (noregex == 0 && pclcf->regex_locations) { | 1372 if (noregex == 0 && pclcf->regex_locations) { |
1373 | 1373 |
1374 len = 0; | |
1375 | |
1374 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { | 1376 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { |
1375 | 1377 |
1376 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1378 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1377 "test location: ~ \"%V\"", &(*clcfp)->name); | 1379 "test location: ~ \"%V\"", &(*clcfp)->name); |
1378 | 1380 |
1379 n = ngx_regex_exec((*clcfp)->regex, &r->uri, NULL, 0); | 1381 if ((*clcfp)->captures && r->captures == NULL) { |
1382 | |
1383 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3 * sizeof(int); | |
1384 | |
1385 r->captures = ngx_palloc(r->pool, len); | |
1386 if (r->captures == NULL) { | |
1387 return NGX_ERROR; | |
1388 } | |
1389 } | |
1390 | |
1391 n = ngx_regex_exec((*clcfp)->regex, &r->uri, r->captures, len); | |
1380 | 1392 |
1381 if (n == NGX_REGEX_NO_MATCHED) { | 1393 if (n == NGX_REGEX_NO_MATCHED) { |
1382 continue; | 1394 continue; |
1383 } | 1395 } |
1384 | 1396 |
1392 | 1404 |
1393 /* match */ | 1405 /* match */ |
1394 | 1406 |
1395 r->loc_conf = (*clcfp)->loc_conf; | 1407 r->loc_conf = (*clcfp)->loc_conf; |
1396 | 1408 |
1409 r->ncaptures = len; | |
1410 r->captures_data = r->uri.data; | |
1411 | |
1397 /* look up nested locations */ | 1412 /* look up nested locations */ |
1398 | 1413 |
1399 rc = ngx_http_core_find_location(r); | 1414 rc = ngx_http_core_find_location(r); |
1400 | 1415 |
1401 return (rc == NGX_ERROR) ? rc : NGX_OK; | 1416 return (rc == NGX_ERROR) ? rc : NGX_OK; |
1684 return NULL; | 1699 return NULL; |
1685 } | 1700 } |
1686 | 1701 |
1687 *root_length = path->len - reserved; | 1702 *root_length = path->len - reserved; |
1688 last = path->data + *root_length; | 1703 last = path->data + *root_length; |
1704 | |
1705 if (alias) { | |
1706 *last = '\0'; | |
1707 return last; | |
1708 } | |
1689 } | 1709 } |
1690 | 1710 |
1691 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); | 1711 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); |
1692 | 1712 |
1693 return last; | 1713 return last; |
2532 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | 2552 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); |
2533 return NGX_ERROR; | 2553 return NGX_ERROR; |
2534 } | 2554 } |
2535 | 2555 |
2536 clcf->name = *regex; | 2556 clcf->name = *regex; |
2557 clcf->captures = (ngx_regex_capture_count(clcf->regex) > 0); | |
2537 | 2558 |
2538 return NGX_OK; | 2559 return NGX_OK; |
2539 | 2560 |
2540 #else | 2561 #else |
2541 | 2562 |
3475 "inside named location"); | 3496 "inside named location"); |
3476 | 3497 |
3477 return NGX_CONF_ERROR; | 3498 return NGX_CONF_ERROR; |
3478 } | 3499 } |
3479 | 3500 |
3480 #if (NGX_PCRE) | |
3481 | |
3482 if (lcf->regex && alias) { | |
3483 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3484 "the \"alias\" directive may not be used " | |
3485 "inside location given by regular expression"); | |
3486 | |
3487 return NGX_CONF_ERROR; | |
3488 } | |
3489 | |
3490 #endif | |
3491 | |
3492 value = cf->args->elts; | 3501 value = cf->args->elts; |
3493 | 3502 |
3494 if (ngx_strstr(value[1].data, "$document_root") | 3503 if (ngx_strstr(value[1].data, "$document_root") |
3495 || ngx_strstr(value[1].data, "${document_root}")) | 3504 || ngx_strstr(value[1].data, "${document_root}")) |
3496 { | 3505 { |
3526 } | 3535 } |
3527 } | 3536 } |
3528 | 3537 |
3529 n = ngx_http_script_variables_count(&lcf->root); | 3538 n = ngx_http_script_variables_count(&lcf->root); |
3530 | 3539 |
3531 if (n == 0) { | |
3532 return NGX_CONF_OK; | |
3533 } | |
3534 | |
3535 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 3540 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
3536 | 3541 |
3537 sc.cf = cf; | 3542 if (n) { |
3538 sc.source = &lcf->root; | 3543 sc.cf = cf; |
3539 sc.lengths = &lcf->root_lengths; | 3544 sc.source = &lcf->root; |
3540 sc.values = &lcf->root_values; | 3545 sc.lengths = &lcf->root_lengths; |
3541 sc.variables = n; | 3546 sc.values = &lcf->root_values; |
3542 sc.complete_lengths = 1; | 3547 sc.variables = n; |
3543 sc.complete_values = 1; | 3548 sc.complete_lengths = 1; |
3544 | 3549 sc.complete_values = 1; |
3545 if (ngx_http_script_compile(&sc) != NGX_OK) { | 3550 |
3551 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
3552 return NGX_CONF_ERROR; | |
3553 } | |
3554 } | |
3555 | |
3556 #if (NGX_PCRE) | |
3557 | |
3558 if (alias && lcf->regex | |
3559 && (ngx_regex_capture_count(lcf->regex) <= 0 || sc.ncaptures == 0)) | |
3560 { | |
3561 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3562 "the \"alias\" directive must use captures " | |
3563 "inside location given by regular expression"); | |
3564 | |
3546 return NGX_CONF_ERROR; | 3565 return NGX_CONF_ERROR; |
3547 } | 3566 } |
3567 | |
3568 #endif | |
3548 | 3569 |
3549 return NGX_CONF_OK; | 3570 return NGX_CONF_OK; |
3550 } | 3571 } |
3551 | 3572 |
3552 | 3573 |