Mercurial > hg > nginx-quic
comparison src/core/ngx_regex.c @ 195:8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 25 Nov 2003 20:44:56 +0000 |
parents | |
children | 0b67be7d4489 |
comparison
equal
deleted
inserted
replaced
194:2357fa41738a | 195:8dee38ea9117 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 | |
5 | |
6 static void *ngx_regex_malloc(size_t size); | |
7 static void ngx_regex_free(void *p); | |
8 | |
9 | |
10 /* THREADS: this pool should be private for each thread */ | |
11 static ngx_pool_t *ngx_pcre_pool; | |
12 | |
13 | |
14 void ngx_regex_init() | |
15 { | |
16 pcre_malloc = ngx_regex_malloc; | |
17 pcre_free = ngx_regex_free; | |
18 } | |
19 | |
20 | |
21 ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, | |
22 ngx_pool_t *pool, ngx_str_t *err) | |
23 { | |
24 int erroff; | |
25 const char *errstr; | |
26 ngx_regex_t *re; | |
27 | |
28 ngx_pcre_pool = pool; | |
29 | |
30 re = pcre_compile(pattern->data, (int) options, &errstr, &erroff, NULL); | |
31 | |
32 if (re == NULL) { | |
33 if ((size_t) erroff == pattern->len) { | |
34 ngx_snprintf(err->data, err->len - 1, | |
35 "pcre_compile() failed: %s in \"%s\"", | |
36 errstr, pattern->data); | |
37 } else { | |
38 ngx_snprintf(err->data, err->len - 1, | |
39 "pcre_compile() failed: %s in \"%s\" at \"%s\"", | |
40 errstr, pattern->data, pattern->data + erroff); | |
41 } | |
42 } | |
43 | |
44 return re; | |
45 } | |
46 | |
47 | |
48 ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s) | |
49 { | |
50 int rc; | |
51 | |
52 rc = pcre_exec(re, NULL, s->data, s->len, 0, 0, NULL, 0); | |
53 | |
54 if (rc == -1) { | |
55 return NGX_DECLINED; | |
56 } | |
57 | |
58 return rc; | |
59 } | |
60 | |
61 | |
62 static void *ngx_regex_malloc(size_t size) | |
63 { | |
64 return ngx_palloc(ngx_pcre_pool, size); | |
65 } | |
66 | |
67 | |
68 static void ngx_regex_free(void *p) | |
69 { | |
70 return; | |
71 } |