comparison src/http/ngx_http_script.c @ 578:f3a9e57d2e17

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 11 Mar 2010 21:27:17 +0300
parents ab7d265273ed
children 8246d8a2c2be
comparison
equal deleted inserted replaced
539:5f4de8cf0d9d 578:f3a9e57d2e17
249 249
250 #if (NGX_PCRE) 250 #if (NGX_PCRE)
251 { 251 {
252 ngx_uint_t n; 252 ngx_uint_t n;
253 253
254 /* NGX_HTTP_MAX_CAPTURES is 9 */
255
256 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') { 254 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') {
257 255
258 n = sc->source->data[i] - '0'; 256 n = sc->source->data[i] - '0';
259 257
260 if (sc->captures_mask & (1 << n)) { 258 if (sc->captures_mask & (1 << n)) {
826 e->sp--; 824 e->sp--;
827 e->line.len = e->sp->len; 825 e->line.len = e->sp->len;
828 e->line.data = e->sp->data; 826 e->line.data = e->sp->data;
829 } 827 }
830 828
831 if (code->ncaptures && r->captures == NULL) { 829 rc = ngx_http_regex_exec(r, code->regex, &e->line);
832 830
833 r->captures = ngx_palloc(r->pool, 831 if (rc == NGX_DECLINED) {
834 (NGX_HTTP_MAX_CAPTURES + 1) * 3 * sizeof(int));
835 if (r->captures == NULL) {
836 e->ip = ngx_http_script_exit;
837 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
838 return;
839 }
840 }
841
842 rc = ngx_regex_exec(code->regex, &e->line, r->captures, code->ncaptures);
843
844 if (rc == NGX_REGEX_NO_MATCHED) {
845 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { 832 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
846 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, 833 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
847 "\"%V\" does not match \"%V\"", 834 "\"%V\" does not match \"%V\"",
848 &code->name, &e->line); 835 &code->name, &e->line);
849 } 836 }
868 855
869 e->ip += code->next; 856 e->ip += code->next;
870 return; 857 return;
871 } 858 }
872 859
873 if (rc < 0) { 860 if (rc == NGX_ERROR) {
874 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
875 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
876 rc, &e->line, &code->name);
877
878 e->ip = ngx_http_script_exit; 861 e->ip = ngx_http_script_exit;
879 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; 862 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
880 return; 863 return;
881 } 864 }
882 865
883 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { 866 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
884 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, 867 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
885 "\"%V\" matches \"%V\"", &code->name, &e->line); 868 "\"%V\" matches \"%V\"", &code->name, &e->line);
886 } 869 }
887
888 r->ncaptures = code->ncaptures;
889 r->captures_data = e->line.data;
890 870
891 if (code->test) { 871 if (code->test) {
892 if (code->negative_test) { 872 if (code->negative_test) {
893 e->sp->len = 0; 873 e->sp->len = 0;
894 e->sp->data = (u_char *) ""; 874 e->sp->data = (u_char *) "";
928 908
929 if (code->lengths == NULL) { 909 if (code->lengths == NULL) {
930 e->buf.len = code->size; 910 e->buf.len = code->size;
931 911
932 if (code->uri) { 912 if (code->uri) {
933 if (rc && (r->quoted_uri || r->plus_in_uri)) { 913 if (r->ncaptures && (r->quoted_uri || r->plus_in_uri)) {
934 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, 914 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
935 NGX_ESCAPE_ARGS); 915 NGX_ESCAPE_ARGS);
936 } 916 }
937 } 917 }
938 918
939 for (n = 1; n < (ngx_uint_t) rc; n++) { 919 for (n = 2; n < r->ncaptures; n += 2) {
940 e->buf.len += r->captures[2 * n + 1] - r->captures[2 * n]; 920 e->buf.len += r->captures[n + 1] - r->captures[n];
941 } 921 }
942 922
943 } else { 923 } else {
944 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); 924 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
945 925
1405 1385
1406 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 1386 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1407 1387
1408 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); 1388 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1409 1389
1390 of.read_ahead = clcf->read_ahead;
1410 of.directio = clcf->directio; 1391 of.directio = clcf->directio;
1411 of.valid = clcf->open_file_cache_valid; 1392 of.valid = clcf->open_file_cache_valid;
1412 of.min_uses = clcf->open_file_cache_min_uses; 1393 of.min_uses = clcf->open_file_cache_min_uses;
1413 of.test_only = 1; 1394 of.test_only = 1;
1414 of.errors = clcf->open_file_cache_errors; 1395 of.errors = clcf->open_file_cache_errors;
1415 of.events = clcf->open_file_cache_events; 1396 of.events = clcf->open_file_cache_events;
1416 1397
1417 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) 1398 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1418 != NGX_OK) 1399 != NGX_OK)
1419 { 1400 {
1420 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) { 1401 if (of.err != NGX_ENOENT
1402 && of.err != NGX_ENOTDIR
1403 && of.err != NGX_ENAMETOOLONG)
1404 {
1421 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, 1405 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
1422 "%s \"%s\" failed", of.failed, value->data); 1406 "%s \"%s\" failed", of.failed, value->data);
1423 } 1407 }
1424 1408
1425 switch (code->op) { 1409 switch (code->op) {