Mercurial > hg > nginx
annotate src/core/ngx_regex.c @ 7982:fbbb5ce52995
PCRE2 and PCRE binary compatibility.
With this change, dynamic modules using nginx regex interface can be used
regardless of the variant of the PCRE library nginx was compiled with.
If a module is compiled with different PCRE library variant, in case of
ngx_regex_exec() errors it will report wrong function name in error
messages. This is believed to be tolerable, given that fixing this will
require interface changes.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 25 Dec 2021 01:07:16 +0300 |
parents | 0b5f12d5c531 |
children | d07456044b61 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
6 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
12 typedef struct { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
13 ngx_flag_t pcre_jit; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
14 ngx_list_t *studies; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
15 } ngx_regex_conf_t; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
16 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
17 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
18 static ngx_inline void ngx_regex_malloc_init(ngx_pool_t *pool); |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
19 static ngx_inline void ngx_regex_malloc_done(void); |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
20 |
7981 | 21 #if (NGX_PCRE2) |
22 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size, void *data); | |
23 static void ngx_libc_cdecl ngx_regex_free(void *p, void *data); | |
24 #else | |
503 | 25 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); |
26 static void ngx_libc_cdecl ngx_regex_free(void *p); | |
7981 | 27 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
28 static void ngx_regex_cleanup(void *data); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
30 static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
31 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
32 static void *ngx_regex_create_conf(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
33 static char *ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
34 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
35 static char *ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
36 static ngx_conf_post_t ngx_regex_pcre_jit_post = { ngx_regex_pcre_jit }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
37 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
38 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
39 static ngx_command_t ngx_regex_commands[] = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
40 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
41 { ngx_string("pcre_jit"), |
6511
640288d0e1bc
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse (as in e444e8f6538b).
Ruslan Ermilov <ru@nginx.com>
parents:
6109
diff
changeset
|
42 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
43 ngx_conf_set_flag_slot, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
44 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
45 offsetof(ngx_regex_conf_t, pcre_jit), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
46 &ngx_regex_pcre_jit_post }, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
47 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
48 ngx_null_command |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
49 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
50 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
51 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
52 static ngx_core_module_t ngx_regex_module_ctx = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
53 ngx_string("regex"), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
54 ngx_regex_create_conf, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
55 ngx_regex_init_conf |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
56 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
57 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
58 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
59 ngx_module_t ngx_regex_module = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
60 NGX_MODULE_V1, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
61 &ngx_regex_module_ctx, /* module context */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
62 ngx_regex_commands, /* module directives */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
63 NGX_CORE_MODULE, /* module type */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
64 NULL, /* init master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
65 ngx_regex_module_init, /* init module */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
66 NULL, /* init process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
67 NULL, /* init thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
68 NULL, /* exit thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
69 NULL, /* exit process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
70 NULL, /* exit master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
71 NGX_MODULE_V1_PADDING |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
72 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
73 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
7981 | 75 static ngx_pool_t *ngx_regex_pool; |
76 static ngx_list_t *ngx_regex_studies; | |
77 static ngx_uint_t ngx_regex_direct_alloc; | |
78 | |
79 #if (NGX_PCRE2) | |
80 static pcre2_compile_context *ngx_regex_compile_context; | |
81 static pcre2_match_data *ngx_regex_match_data; | |
82 static ngx_uint_t ngx_regex_match_data_size; | |
83 #endif | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
503 | 86 void |
87 ngx_regex_init(void) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 { |
7981 | 89 #if !(NGX_PCRE2) |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 pcre_malloc = ngx_regex_malloc; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 pcre_free = ngx_regex_free; |
7981 | 92 #endif |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 |
3325 | 96 static ngx_inline void |
97 ngx_regex_malloc_init(ngx_pool_t *pool) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 { |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
99 ngx_regex_pool = pool; |
7981 | 100 ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0; |
3325 | 101 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
102 |
3325 | 103 |
104 static ngx_inline void | |
105 ngx_regex_malloc_done(void) | |
106 { | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
107 ngx_regex_pool = NULL; |
7981 | 108 ngx_regex_direct_alloc = 0; |
3325 | 109 } |
110 | |
111 | |
7981 | 112 #if (NGX_PCRE2) |
113 | |
114 ngx_int_t | |
115 ngx_regex_compile(ngx_regex_compile_t *rc) | |
116 { | |
117 int n, errcode; | |
118 char *p; | |
119 u_char errstr[128]; | |
120 size_t erroff; | |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
121 uint32_t options; |
7981 | 122 pcre2_code *re; |
123 ngx_regex_elt_t *elt; | |
124 pcre2_general_context *gctx; | |
125 pcre2_compile_context *cctx; | |
126 | |
127 if (ngx_regex_compile_context == NULL) { | |
128 /* | |
129 * Allocate a compile context if not yet allocated. This uses | |
130 * direct allocations from heap, so the result can be cached | |
131 * even at runtime. | |
132 */ | |
133 | |
134 ngx_regex_malloc_init(NULL); | |
135 | |
136 gctx = pcre2_general_context_create(ngx_regex_malloc, ngx_regex_free, | |
137 NULL); | |
138 if (gctx == NULL) { | |
139 ngx_regex_malloc_done(); | |
140 goto nomem; | |
141 } | |
142 | |
143 cctx = pcre2_compile_context_create(gctx); | |
144 if (cctx == NULL) { | |
145 pcre2_general_context_free(gctx); | |
146 ngx_regex_malloc_done(); | |
147 goto nomem; | |
148 } | |
149 | |
150 ngx_regex_compile_context = cctx; | |
151 | |
152 pcre2_general_context_free(gctx); | |
153 ngx_regex_malloc_done(); | |
154 } | |
155 | |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
156 options = 0; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
157 |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
158 if (rc->options & NGX_REGEX_CASELESS) { |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
159 options |= PCRE2_CASELESS; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
160 } |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
161 |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
162 if (rc->options & ~NGX_REGEX_CASELESS) { |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
163 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
164 "regex \"%V\" compilation failed: invalid options", |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
165 &rc->pattern) |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
166 - rc->err.data; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
167 return NGX_ERROR; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
168 } |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
169 |
7981 | 170 ngx_regex_malloc_init(rc->pool); |
171 | |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
172 re = pcre2_compile(rc->pattern.data, rc->pattern.len, options, |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
173 &errcode, &erroff, ngx_regex_compile_context); |
7981 | 174 |
175 /* ensure that there is no current pool */ | |
176 ngx_regex_malloc_done(); | |
177 | |
178 if (re == NULL) { | |
179 pcre2_get_error_message(errcode, errstr, 128); | |
180 | |
181 if ((size_t) erroff == rc->pattern.len) { | |
182 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
183 "pcre2_compile() failed: %s in \"%V\"", | |
184 errstr, &rc->pattern) | |
185 - rc->err.data; | |
186 | |
187 } else { | |
188 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
189 "pcre2_compile() failed: %s in \"%V\" at \"%s\"", | |
190 errstr, &rc->pattern, rc->pattern.data + erroff) | |
191 - rc->err.data; | |
192 } | |
193 | |
194 return NGX_ERROR; | |
195 } | |
196 | |
197 rc->regex = re; | |
198 | |
199 /* do not study at runtime */ | |
200 | |
201 if (ngx_regex_studies != NULL) { | |
202 elt = ngx_list_push(ngx_regex_studies); | |
203 if (elt == NULL) { | |
204 goto nomem; | |
205 } | |
206 | |
207 elt->regex = rc->regex; | |
208 elt->name = rc->pattern.data; | |
209 } | |
210 | |
211 n = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &rc->captures); | |
212 if (n < 0) { | |
213 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_CAPTURECOUNT) failed: %d"; | |
214 goto failed; | |
215 } | |
216 | |
217 if (rc->captures == 0) { | |
218 return NGX_OK; | |
219 } | |
220 | |
221 n = pcre2_pattern_info(re, PCRE2_INFO_NAMECOUNT, &rc->named_captures); | |
222 if (n < 0) { | |
223 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMECOUNT) failed: %d"; | |
224 goto failed; | |
225 } | |
226 | |
227 if (rc->named_captures == 0) { | |
228 return NGX_OK; | |
229 } | |
230 | |
231 n = pcre2_pattern_info(re, PCRE2_INFO_NAMEENTRYSIZE, &rc->name_size); | |
232 if (n < 0) { | |
233 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMEENTRYSIZE) failed: %d"; | |
234 goto failed; | |
235 } | |
236 | |
237 n = pcre2_pattern_info(re, PCRE2_INFO_NAMETABLE, &rc->names); | |
238 if (n < 0) { | |
239 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMETABLE) failed: %d"; | |
240 goto failed; | |
241 } | |
242 | |
243 return NGX_OK; | |
244 | |
245 failed: | |
246 | |
247 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
248 - rc->err.data; | |
249 return NGX_ERROR; | |
250 | |
251 nomem: | |
252 | |
253 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
254 "regex \"%V\" compilation failed: no memory", | |
255 &rc->pattern) | |
256 - rc->err.data; | |
257 return NGX_ERROR; | |
258 } | |
259 | |
260 #else | |
261 | |
3325 | 262 ngx_int_t |
263 ngx_regex_compile(ngx_regex_compile_t *rc) | |
264 { | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
265 int n, erroff; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
266 char *p; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
267 pcre *re; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
268 const char *errstr; |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
269 ngx_uint_t options; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
270 ngx_regex_elt_t *elt; |
3325 | 271 |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
272 options = 0; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
273 |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
274 if (rc->options & NGX_REGEX_CASELESS) { |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
275 options |= PCRE_CASELESS; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
276 } |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
277 |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
278 if (rc->options & ~NGX_REGEX_CASELESS) { |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
279 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
280 "regex \"%V\" compilation failed: invalid options", |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
281 &rc->pattern) |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
282 - rc->err.data; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
283 return NGX_ERROR; |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
284 } |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
285 |
3325 | 286 ngx_regex_malloc_init(rc->pool); |
287 | |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
288 re = pcre_compile((const char *) rc->pattern.data, (int) options, |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
216
diff
changeset
|
289 &errstr, &erroff, NULL); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
290 |
3325 | 291 /* ensure that there is no current pool */ |
292 ngx_regex_malloc_done(); | |
293 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 if (re == NULL) { |
3325 | 295 if ((size_t) erroff == rc->pattern.len) { |
296 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
297 "pcre_compile() failed: %s in \"%V\"", | |
298 errstr, &rc->pattern) | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
299 - rc->err.data; |
3325 | 300 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 } else { |
3325 | 302 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
303 "pcre_compile() failed: %s in \"%V\" at \"%s\"", | |
304 errstr, &rc->pattern, rc->pattern.data + erroff) | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
305 - rc->err.data; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 } |
3325 | 307 |
308 return NGX_ERROR; | |
309 } | |
310 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
311 rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
312 if (rc->regex == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
313 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
314 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
315 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
316 rc->regex->code = re; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
317 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
318 /* do not study at runtime */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
319 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
320 if (ngx_regex_studies != NULL) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
321 elt = ngx_list_push(ngx_regex_studies); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
322 if (elt == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
323 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
324 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
325 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
326 elt->regex = rc->regex; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
327 elt->name = rc->pattern.data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
328 } |
3325 | 329 |
330 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures); | |
331 if (n < 0) { | |
332 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d"; | |
333 goto failed; | |
334 } | |
335 | |
336 if (rc->captures == 0) { | |
337 return NGX_OK; | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
338 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
339 |
3325 | 340 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures); |
341 if (n < 0) { | |
342 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d"; | |
343 goto failed; | |
344 } | |
345 | |
346 if (rc->named_captures == 0) { | |
347 return NGX_OK; | |
348 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
349 |
3325 | 350 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size); |
351 if (n < 0) { | |
352 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d"; | |
353 goto failed; | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
354 } |
3325 | 355 |
356 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names); | |
357 if (n < 0) { | |
358 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d"; | |
359 goto failed; | |
360 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
361 |
3325 | 362 return NGX_OK; |
363 | |
364 failed: | |
365 | |
366 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
367 - rc->err.data; | |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
368 return NGX_ERROR; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
369 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
370 nomem: |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
371 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
372 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
373 "regex \"%V\" compilation failed: no memory", |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
374 &rc->pattern) |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
375 - rc->err.data; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
376 return NGX_ERROR; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
377 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
378 |
7981 | 379 #endif |
380 | |
381 | |
382 #if (NGX_PCRE2) | |
383 | |
384 ngx_int_t | |
385 ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, ngx_uint_t size) | |
386 { | |
387 size_t *ov; | |
388 ngx_int_t rc; | |
389 ngx_uint_t n, i; | |
390 | |
391 /* | |
392 * The pcre2_match() function might allocate memory for backtracking | |
393 * frames, typical allocations are from 40k and above. So the allocator | |
394 * is configured to do direct allocations from heap during matching. | |
395 */ | |
396 | |
397 ngx_regex_malloc_init(NULL); | |
398 | |
399 if (ngx_regex_match_data == NULL | |
400 || size > ngx_regex_match_data_size) | |
401 { | |
402 /* | |
403 * Allocate a match data if not yet allocated or smaller than | |
404 * needed. | |
405 */ | |
406 | |
407 if (ngx_regex_match_data) { | |
408 pcre2_match_data_free(ngx_regex_match_data); | |
409 } | |
410 | |
411 ngx_regex_match_data_size = size; | |
412 ngx_regex_match_data = pcre2_match_data_create(size / 3, NULL); | |
413 | |
414 if (ngx_regex_match_data == NULL) { | |
415 rc = PCRE2_ERROR_NOMEMORY; | |
416 goto failed; | |
417 } | |
418 } | |
419 | |
420 rc = pcre2_match(re, s->data, s->len, 0, 0, ngx_regex_match_data, NULL); | |
421 | |
422 if (rc < 0) { | |
423 goto failed; | |
424 } | |
425 | |
426 n = pcre2_get_ovector_count(ngx_regex_match_data); | |
427 ov = pcre2_get_ovector_pointer(ngx_regex_match_data); | |
428 | |
429 if (n > size / 3) { | |
430 n = size / 3; | |
431 } | |
432 | |
433 for (i = 0; i < n; i++) { | |
434 captures[i * 2] = ov[i * 2]; | |
435 captures[i * 2 + 1] = ov[i * 2 + 1]; | |
436 } | |
437 | |
438 failed: | |
439 | |
440 ngx_regex_malloc_done(); | |
441 | |
442 return rc; | |
443 } | |
444 | |
7982
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
445 #else |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
446 |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
447 ngx_int_t |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
448 ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, ngx_uint_t size) |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
449 { |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
450 return pcre_exec(re->code, re->extra, (const char *) s->data, s->len, |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
451 0, 0, captures, size); |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
452 } |
fbbb5ce52995
PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7981
diff
changeset
|
453 |
7981 | 454 #endif |
455 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
456 |
503 | 457 ngx_int_t |
1784 | 458 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) |
459 { | |
460 ngx_int_t n; | |
461 ngx_uint_t i; | |
462 ngx_regex_elt_t *re; | |
463 | |
464 re = a->elts; | |
465 | |
466 for (i = 0; i < a->nelts; i++) { | |
467 | |
468 n = ngx_regex_exec(re[i].regex, s, NULL, 0); | |
469 | |
470 if (n == NGX_REGEX_NO_MATCHED) { | |
471 continue; | |
472 } | |
473 | |
474 if (n < 0) { | |
475 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
3325 | 476 ngx_regex_exec_n " failed: %i on \"%V\" using \"%s\"", |
1784 | 477 n, s, re[i].name); |
478 return NGX_ERROR; | |
479 } | |
480 | |
481 /* match */ | |
482 | |
483 return NGX_OK; | |
484 } | |
485 | |
486 return NGX_DECLINED; | |
487 } | |
488 | |
489 | |
7981 | 490 #if (NGX_PCRE2) |
491 | |
492 static void * ngx_libc_cdecl | |
493 ngx_regex_malloc(size_t size, void *data) | |
494 { | |
495 if (ngx_regex_pool) { | |
496 return ngx_palloc(ngx_regex_pool, size); | |
497 } | |
498 | |
499 if (ngx_regex_direct_alloc) { | |
500 return ngx_alloc(size, ngx_cycle->log); | |
501 } | |
502 | |
503 return NULL; | |
504 } | |
505 | |
506 | |
507 static void ngx_libc_cdecl | |
508 ngx_regex_free(void *p, void *data) | |
509 { | |
510 if (ngx_regex_direct_alloc) { | |
511 ngx_free(p); | |
512 } | |
513 | |
514 return; | |
515 } | |
516 | |
517 #else | |
518 | |
503 | 519 static void * ngx_libc_cdecl |
520 ngx_regex_malloc(size_t size) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
521 { |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
522 if (ngx_regex_pool) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
523 return ngx_palloc(ngx_regex_pool, size); |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
524 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
525 |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
526 return NULL; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
527 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
528 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
529 |
503 | 530 static void ngx_libc_cdecl |
531 ngx_regex_free(void *p) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
532 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
533 return; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
534 } |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
535 |
7981 | 536 #endif |
537 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
538 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
539 static void |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
540 ngx_regex_cleanup(void *data) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
541 { |
7981 | 542 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT) |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
543 ngx_regex_conf_t *rcf = data; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
544 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
545 ngx_uint_t i; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
546 ngx_list_part_t *part; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
547 ngx_regex_elt_t *elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
548 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
549 part = &rcf->studies->part; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
550 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
551 |
7088 | 552 for (i = 0; /* void */ ; i++) { |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
553 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
554 if (i >= part->nelts) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
555 if (part->next == NULL) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
556 break; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
557 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
558 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
559 part = part->next; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
560 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
561 i = 0; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
562 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
563 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
564 /* |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
565 * The PCRE JIT compiler uses mmap for its executable codes, so we |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
566 * have to explicitly call the pcre_free_study() function to free |
7981 | 567 * this memory. In PCRE2, we call the pcre2_code_free() function |
568 * for the same reason. | |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
569 */ |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
570 |
7981 | 571 #if (NGX_PCRE2) |
572 pcre2_code_free(elts[i].regex); | |
573 #else | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
574 if (elts[i].regex->extra != NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
575 pcre_free_study(elts[i].regex->extra); |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
576 } |
7981 | 577 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
578 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
579 #endif |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
580 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
581 /* |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
582 * On configuration parsing errors ngx_regex_module_init() will not |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
583 * be called. Make sure ngx_regex_studies is properly cleared anyway. |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
584 */ |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
585 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
586 ngx_regex_studies = NULL; |
7981 | 587 |
588 #if (NGX_PCRE2) | |
589 | |
590 /* | |
591 * Free compile context and match data. If needed at runtime by | |
592 * the new cycle, these will be re-allocated. | |
593 */ | |
594 | |
595 if (ngx_regex_compile_context) { | |
596 pcre2_compile_context_free(ngx_regex_compile_context); | |
597 ngx_regex_compile_context = NULL; | |
598 } | |
599 | |
600 if (ngx_regex_match_data) { | |
601 pcre2_match_data_free(ngx_regex_match_data); | |
602 ngx_regex_match_data = NULL; | |
603 ngx_regex_match_data_size = 0; | |
604 } | |
605 | |
606 #endif | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
607 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
608 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
609 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
610 static ngx_int_t |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
611 ngx_regex_module_init(ngx_cycle_t *cycle) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
612 { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
613 int opt; |
7981 | 614 #if !(NGX_PCRE2) |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
615 const char *errstr; |
7981 | 616 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
617 ngx_uint_t i; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
618 ngx_list_part_t *part; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
619 ngx_regex_elt_t *elts; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
620 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
621 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
622 opt = 0; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
623 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
624 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
625 |
7981 | 626 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT) |
627 | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
628 if (rcf->pcre_jit) { |
7981 | 629 #if (NGX_PCRE2) |
630 opt = 1; | |
631 #else | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
632 opt = PCRE_STUDY_JIT_COMPILE; |
7981 | 633 #endif |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
634 } |
7981 | 635 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
636 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
637 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
638 ngx_regex_malloc_init(cycle->pool); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
639 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
640 part = &rcf->studies->part; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
641 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
642 |
7088 | 643 for (i = 0; /* void */ ; i++) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
644 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
645 if (i >= part->nelts) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
646 if (part->next == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
647 break; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
648 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
649 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
650 part = part->next; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
651 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
652 i = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
653 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
654 |
7981 | 655 #if (NGX_PCRE2) |
656 | |
657 if (opt) { | |
658 int n; | |
659 | |
660 n = pcre2_jit_compile(elts[i].regex, PCRE2_JIT_COMPLETE); | |
661 | |
662 if (n != 0) { | |
663 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | |
664 "pcre2_jit_compile() failed: %d in \"%s\", " | |
665 "ignored", | |
666 n, elts[i].name); | |
667 } | |
668 } | |
669 | |
670 #else | |
671 | |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
672 elts[i].regex->extra = pcre_study(elts[i].regex->code, opt, &errstr); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
673 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
674 if (errstr != NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
675 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
676 "pcre_study() failed: %s in \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
677 errstr, elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
678 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
679 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
680 #if (NGX_HAVE_PCRE_JIT) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
681 if (opt & PCRE_STUDY_JIT_COMPILE) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
682 int jit, n; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
683 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
684 jit = 0; |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
685 n = pcre_fullinfo(elts[i].regex->code, elts[i].regex->extra, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
686 PCRE_INFO_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
687 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
688 if (n != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
689 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
690 "JIT compiler does not support pattern: \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
691 elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
692 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
693 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
694 #endif |
7981 | 695 #endif |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
696 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
697 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
698 ngx_regex_malloc_done(); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
699 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
700 ngx_regex_studies = NULL; |
7981 | 701 #if (NGX_PCRE2) |
702 ngx_regex_compile_context = NULL; | |
703 #endif | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
704 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
705 return NGX_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
706 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
707 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
708 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
709 static void * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
710 ngx_regex_create_conf(ngx_cycle_t *cycle) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
711 { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
712 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
713 ngx_pool_cleanup_t *cln; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
714 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
715 rcf = ngx_pcalloc(cycle->pool, sizeof(ngx_regex_conf_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
716 if (rcf == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
717 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
718 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
719 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
720 rcf->pcre_jit = NGX_CONF_UNSET; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
721 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
722 cln = ngx_pool_cleanup_add(cycle->pool, 0); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
723 if (cln == NULL) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
724 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
725 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
726 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
727 cln->handler = ngx_regex_cleanup; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
728 cln->data = rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
729 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
730 rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t)); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
731 if (rcf->studies == NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
732 return NULL; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
733 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
734 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
735 ngx_regex_studies = rcf->studies; |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
736 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
737 return rcf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
738 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
739 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
740 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
741 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
742 ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
743 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
744 ngx_regex_conf_t *rcf = conf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
745 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
746 ngx_conf_init_value(rcf->pcre_jit, 0); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
747 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
748 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
749 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
750 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
751 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
752 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
753 ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
754 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
755 ngx_flag_t *fp = data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
756 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
757 if (*fp == 0) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
758 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
759 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
760 |
7981 | 761 #if (NGX_PCRE2) |
762 { | |
763 int r; | |
764 uint32_t jit; | |
765 | |
766 jit = 0; | |
767 r = pcre2_config(PCRE2_CONFIG_JIT, &jit); | |
768 | |
769 if (r != 0 || jit != 1) { | |
770 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
771 "PCRE2 library does not support JIT"); | |
772 *fp = 0; | |
773 } | |
774 } | |
775 #elif (NGX_HAVE_PCRE_JIT) | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
776 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
777 int jit, r; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
778 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
779 jit = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
780 r = pcre_config(PCRE_CONFIG_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
781 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
782 if (r != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
783 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
784 "PCRE library does not support JIT"); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
785 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
786 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
787 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
788 #else |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
789 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
4413
23ea4e72c85a
Fixed grammar in PCRE JIT error log message.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
790 "nginx was built without PCRE JIT support"); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
791 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
792 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
793 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
794 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
795 } |