annotate src/core/ngx_regex.c @ 5834:ca63fc5ed9b1

SSL: session id context now includes certificate hash. This prevents inappropriate session reuse in unrelated server{} blocks, while preserving ability to restore sessions on other servers when using TLS Session Tickets. Additionally, session context is now set even if there is no session cache configured. This is needed as it's also used for TLS Session Tickets. Thanks to Antoine Delignat-Lavaud and Piotr Sikora.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 15 Sep 2014 17:59:47 +0400
parents e7f6991eca47
children 457ec43dd8d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4388
diff changeset
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 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
13 ngx_flag_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
14 } 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
15
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
16
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
17 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size);
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
18 static void ngx_libc_cdecl ngx_regex_free(void *p);
4423
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
19 #if (NGX_HAVE_PCRE_JIT)
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
20 static void ngx_pcre_free_studies(void *data);
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
21 #endif
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
23 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
24
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
25 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
26 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
27
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
28 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
29 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
30
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 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
33
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
34 { ngx_string("pcre_jit"),
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
35 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
36 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
37 0,
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
38 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
39 &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
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_null_command
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
42 };
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
43
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
44
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
45 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
46 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
47 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
48 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
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 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
53 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
54 &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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 };
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
66
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 static ngx_pool_t *ngx_pcre_pool;
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
69 static ngx_list_t *ngx_pcre_studies;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
72 void
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
73 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
74 {
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 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
76 pcre_free = ngx_regex_free;
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
80 static ngx_inline void
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
81 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
82 {
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
83 #if (NGX_THREADS)
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
84 ngx_core_tls_t *tls;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
85
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
86 if (ngx_threaded) {
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
87 tls = ngx_thread_get_tls(ngx_core_tls_key);
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
88 tls->pool = pool;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
89 return;
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
90 }
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
91
3349
169d84ff4064 fix pcre allocation on Win32, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents: 3325
diff changeset
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 ngx_pcre_pool = pool;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
95 }
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
96
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
97
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
98 static ngx_inline void
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
99 ngx_regex_malloc_done(void)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
100 {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
101 #if (NGX_THREADS)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
102 ngx_core_tls_t *tls;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
103
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
104 if (ngx_threaded) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
105 tls = ngx_thread_get_tls(ngx_core_tls_key);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
106 tls->pool = NULL;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
107 return;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
108 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
109
3349
169d84ff4064 fix pcre allocation on Win32, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents: 3325
diff changeset
110 #endif
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
111
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
112 ngx_pcre_pool = NULL;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
113 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
114
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
115
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
116 ngx_int_t
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
117 ngx_regex_compile(ngx_regex_compile_t *rc)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
118 {
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
119 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
120 char *p;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
121 pcre *re;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
122 const char *errstr;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
123 ngx_regex_elt_t *elt;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
124
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
125 ngx_regex_malloc_init(rc->pool);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
126
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
127 re = pcre_compile((const char *) rc->pattern.data, (int) rc->options,
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 216
diff changeset
128 &errstr, &erroff, NULL);
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
130 /* ensure that there is no current pool */
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
131 ngx_regex_malloc_done();
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
132
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 if (re == NULL) {
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
134 if ((size_t) erroff == rc->pattern.len) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
135 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
136 "pcre_compile() failed: %s in \"%V\"",
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
137 errstr, &rc->pattern)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
138 - rc->err.data;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
139
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 } else {
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
141 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
142 "pcre_compile() failed: %s in \"%V\" at \"%s\"",
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
143 errstr, &rc->pattern, rc->pattern.data + erroff)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
144 - rc->err.data;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
146
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
147 return NGX_ERROR;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
148 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
149
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
150 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
151 if (rc->regex == NULL) {
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
152 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
153 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
154
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
155 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
156
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
157 /* 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
158
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
159 if (ngx_pcre_studies != NULL) {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
160 elt = ngx_list_push(ngx_pcre_studies);
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
161 if (elt == NULL) {
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
162 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
163 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
164
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
165 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
166 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
167 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
168
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
169 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
170 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
171 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
172 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
173 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
174
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
175 if (rc->captures == 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
176 return NGX_OK;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
179 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
180 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
181 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
182 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
183 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
184
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
185 if (rc->named_captures == 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
186 return NGX_OK;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
187 }
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
188
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
189 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
190 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
191 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
192 goto failed;
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
193 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
194
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
195 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
196 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
197 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
198 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
199 }
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
200
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
201 return NGX_OK;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
202
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
203 failed:
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
204
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
205 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
206 - rc->err.data;
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
207 return NGX_ERROR;
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
208
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
209 nomem:
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
210
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
211 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
212 "regex \"%V\" compilation failed: no memory",
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
213 &rc->pattern)
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
214 - rc->err.data;
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
215 return NGX_ERROR;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
219 ngx_int_t
1784
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
220 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log)
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
221 {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
222 ngx_int_t n;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
223 ngx_uint_t i;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
224 ngx_regex_elt_t *re;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
225
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
226 re = a->elts;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
227
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
228 for (i = 0; i < a->nelts; i++) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
229
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
230 n = ngx_regex_exec(re[i].regex, s, NULL, 0);
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
231
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
232 if (n == NGX_REGEX_NO_MATCHED) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
233 continue;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
234 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
235
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
236 if (n < 0) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
237 ngx_log_error(NGX_LOG_ALERT, log, 0,
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
238 ngx_regex_exec_n " failed: %i on \"%V\" using \"%s\"",
1784
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
239 n, s, re[i].name);
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
240 return NGX_ERROR;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
241 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
242
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
243 /* match */
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
244
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
245 return NGX_OK;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
246 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
247
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
248 return NGX_DECLINED;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
249 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
250
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
251
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
252 static void * ngx_libc_cdecl
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
253 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
254 {
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
255 ngx_pool_t *pool;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
256 #if (NGX_THREADS)
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
257 ngx_core_tls_t *tls;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
258
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
259 if (ngx_threaded) {
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
260 tls = ngx_thread_get_tls(ngx_core_tls_key);
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
261 pool = tls->pool;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
262
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
263 } else {
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
264 pool = ngx_pcre_pool;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
265 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
266
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
267 #else
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
268
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
269 pool = ngx_pcre_pool;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
270
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
271 #endif
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
272
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
273 if (pool) {
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 2039
diff changeset
274 return ngx_palloc(pool, size);
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
275 }
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
276
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
277 return NULL;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
279
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
281 static void ngx_libc_cdecl
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
282 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
283 {
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284 return;
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
285 }
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
286
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
287
4423
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
288 #if (NGX_HAVE_PCRE_JIT)
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
289
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
290 static void
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
291 ngx_pcre_free_studies(void *data)
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
292 {
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
293 ngx_list_t *studies = data;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
294
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
295 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
296 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
297 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
298
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
299 part = &studies->part;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
300 elts = part->elts;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
301
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
302 for (i = 0 ; /* void */ ; i++) {
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
303
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
304 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
305 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
306 break;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
307 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
308
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
309 part = part->next;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
310 elts = part->elts;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
311 i = 0;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
312 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
313
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
314 if (elts[i].regex->extra != NULL) {
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
315 pcre_free_study(elts[i].regex->extra);
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
316 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
317 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
318 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
319
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
320 #endif
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
321
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
322
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
323 static ngx_int_t
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
324 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
325 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
326 int opt;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
327 const char *errstr;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
328 ngx_uint_t i;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
329 ngx_list_part_t *part;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
330 ngx_regex_elt_t *elts;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
331
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
332 opt = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
333
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
334 #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
335 {
4423
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
336 ngx_regex_conf_t *rcf;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
337 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
338
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
339 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, 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
340
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
341 if (rcf->pcre_jit) {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
342 opt = PCRE_STUDY_JIT_COMPILE;
4423
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
343
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
344 /*
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
345 * 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
346 * have to explicitly call the pcre_free_study() function to free
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
347 * this memory.
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
348 */
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
349
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
350 cln = ngx_pool_cleanup_add(cycle->pool, 0);
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
351 if (cln == NULL) {
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
352 return NGX_ERROR;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
353 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
354
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
355 cln->handler = ngx_pcre_free_studies;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
356 cln->data = ngx_pcre_studies;
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
357 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
358 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
359 #endif
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
360
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
361 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
362
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
363 part = &ngx_pcre_studies->part;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
364 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
365
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
366 for (i = 0 ; /* void */ ; i++) {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
367
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
368 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
369 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
370 break;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
371 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
372
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
373 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
374 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
375 i = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
376 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
377
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
378 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
379
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
380 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
381 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
382 "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
383 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
384 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
385
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
386 #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
387 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
388 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
389
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
390 jit = 0;
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
391 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
392 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
393
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
394 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
395 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
396 "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
397 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
398 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
399 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
400 #endif
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
401 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
402
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
403 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
404
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
405 ngx_pcre_studies = NULL;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
406
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
407 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
408 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
409
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
410
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
411 static void *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
412 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
413 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
414 ngx_regex_conf_t *rcf;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
415
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
416 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
417 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
418 return NULL;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
419 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
420
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
421 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
422
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
423 ngx_pcre_studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t));
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
424 if (ngx_pcre_studies == NULL) {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
425 return NULL;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
426 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
427
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
428 return rcf;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
429 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
430
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
431
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
432 static char *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
433 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
434 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
435 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
436
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
437 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
438
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
439 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
440 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
441
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
442
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
443 static char *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
444 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
445 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
446 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
447
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
448 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
449 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
450 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
451
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
452 #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
453 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
454 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
455
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
456 jit = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
457 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
458
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
459 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
460 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
461 "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
462 *fp = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
463 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
464 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
465 #else
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
466 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
467 "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
468 *fp = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
469 #endif
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
470
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
471 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
472 }