Mercurial > hg > nginx-quic
comparison src/http/ngx_http_script.c @ 3325:42c16d8bddbe
regex named captures
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 16 Nov 2009 12:19:02 +0000 |
parents | 975f0558aab3 |
children | 1aed55182ea2 |
comparison
equal
deleted
inserted
replaced
3324:616da2ea901f | 3325:42c16d8bddbe |
---|---|
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 *) ""; |