annotate src/core/ngx_regex.c @ 9270:3d455e37abf8 default tip

Core: PID file writing synchronization. Now, ngx_daemon() does not call exit() in the parent process immediately, but instead waits for the child process to signal it actually started (and wrote the PID file if configured to). This ensures that the PID file already exists when the parent process exits. To make sure that signal handlers won't cause unexpected logging in the parent process if the child process dies (for example, due to errors when writing the PID file), ngx_init_signals() is moved to the child process. This resolves "PID file ... not readable (yet?) after start" and "Failed to parse PID from file..." errors as observed with systemd. Note that the errors observed are considered to be a bug in systemd, which isn't able to work properly with traditional Unix daemons. Still, the workaround is implemented to make sure there will be no OS vendor patches trying to address this.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 13 May 2024 06:13:22 +0300
parents 533bc2336df4
children
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 {
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
21 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
22 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size, void *data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
23 static void ngx_libc_cdecl ngx_regex_free(void *p, void *data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
24 #else
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
25 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
26 static void ngx_libc_cdecl ngx_regex_free(void *p);
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
75 static ngx_pool_t *ngx_regex_pool;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
76 static ngx_list_t *ngx_regex_studies;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
77 static ngx_uint_t ngx_regex_direct_alloc;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
78
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
79 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
80 static pcre2_compile_context *ngx_regex_compile_context;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
81 static pcre2_match_data *ngx_regex_match_data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
82 static ngx_uint_t ngx_regex_match_data_size;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
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
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
86 void
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
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
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
96 static ngx_inline void
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
100 ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
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
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 static ngx_inline void
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
105 ngx_regex_malloc_done(void)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
106 {
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
107 ngx_regex_pool = NULL;
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
108 ngx_regex_direct_alloc = 0;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
109 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
110
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
111
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
112 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
113
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
114 ngx_int_t
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
115 ngx_regex_compile(ngx_regex_compile_t *rc)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
116 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
117 int n, errcode;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
118 char *p;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
119 u_char errstr[128];
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
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
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
122 pcre2_code *re;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
123 ngx_regex_elt_t *elt;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
124 pcre2_general_context *gctx;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
125 pcre2_compile_context *cctx;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
126
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
127 if (ngx_regex_compile_context == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
128 /*
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
129 * Allocate a compile context if not yet allocated. This uses
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
130 * direct allocations from heap, so the result can be cached
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
131 * even at runtime.
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
132 */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
133
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
134 ngx_regex_malloc_init(NULL);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
135
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
136 gctx = pcre2_general_context_create(ngx_regex_malloc, ngx_regex_free,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
137 NULL);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
138 if (gctx == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
139 ngx_regex_malloc_done();
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
140 goto nomem;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
141 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
142
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
143 cctx = pcre2_compile_context_create(gctx);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
144 if (cctx == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
145 pcre2_general_context_free(gctx);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
146 ngx_regex_malloc_done();
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
147 goto nomem;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
148 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
149
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
150 ngx_regex_compile_context = cctx;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
151
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
152 pcre2_general_context_free(gctx);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
153 ngx_regex_malloc_done();
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
154 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
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
7983
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
162 if (rc->options & NGX_REGEX_MULTILINE) {
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
163 options |= PCRE2_MULTILINE;
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
164 }
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
165
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
166 if (rc->options & ~(NGX_REGEX_CASELESS|NGX_REGEX_MULTILINE)) {
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
167 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
168 "regex \"%V\" compilation failed: invalid options",
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
169 &rc->pattern)
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
170 - rc->err.data;
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
171 return NGX_ERROR;
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
172 }
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
173
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
174 ngx_regex_malloc_init(rc->pool);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
175
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
176 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
177 &errcode, &erroff, ngx_regex_compile_context);
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
178
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
179 /* ensure that there is no current pool */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
180 ngx_regex_malloc_done();
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
181
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
182 if (re == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
183 pcre2_get_error_message(errcode, errstr, 128);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
184
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
185 if ((size_t) erroff == rc->pattern.len) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
186 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
187 "pcre2_compile() failed: %s in \"%V\"",
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
188 errstr, &rc->pattern)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
189 - rc->err.data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
190
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
191 } else {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
192 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
193 "pcre2_compile() failed: %s in \"%V\" at \"%s\"",
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
194 errstr, &rc->pattern, rc->pattern.data + erroff)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
195 - rc->err.data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
196 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
197
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
198 return NGX_ERROR;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
199 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
200
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
201 rc->regex = re;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
202
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
203 /* do not study at runtime */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
204
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
205 if (ngx_regex_studies != NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
206 elt = ngx_list_push(ngx_regex_studies);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
207 if (elt == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
208 goto nomem;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
209 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
210
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
211 elt->regex = rc->regex;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
212 elt->name = rc->pattern.data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
213 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
214
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
215 n = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &rc->captures);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
216 if (n < 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
217 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_CAPTURECOUNT) failed: %d";
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
218 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
219 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
220
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
221 if (rc->captures == 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
222 return NGX_OK;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
223 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
224
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
225 n = pcre2_pattern_info(re, PCRE2_INFO_NAMECOUNT, &rc->named_captures);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
226 if (n < 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
227 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMECOUNT) failed: %d";
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
228 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
229 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
230
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
231 if (rc->named_captures == 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
232 return NGX_OK;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
233 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
234
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
235 n = pcre2_pattern_info(re, PCRE2_INFO_NAMEENTRYSIZE, &rc->name_size);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
236 if (n < 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
237 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMEENTRYSIZE) failed: %d";
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
238 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
239 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
240
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
241 n = pcre2_pattern_info(re, PCRE2_INFO_NAMETABLE, &rc->names);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
242 if (n < 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
243 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMETABLE) failed: %d";
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
244 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
245 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
246
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
247 return NGX_OK;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
248
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
249 failed:
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
250
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
251 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
252 - rc->err.data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
253 return NGX_ERROR;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
254
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
255 nomem:
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
256
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
257 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
258 "regex \"%V\" compilation failed: no memory",
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
259 &rc->pattern)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
260 - rc->err.data;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
261 return NGX_ERROR;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
262 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
263
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
264 #else
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
265
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
266 ngx_int_t
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
267 ngx_regex_compile(ngx_regex_compile_t *rc)
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
268 {
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
269 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
270 char *p;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
271 pcre *re;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
272 const char *errstr;
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
273 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
274 ngx_regex_elt_t *elt;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
275
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
276 options = 0;
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 options |= PCRE_CASELESS;
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
280 }
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
281
7983
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
282 if (rc->options & NGX_REGEX_MULTILINE) {
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
283 options |= PCRE_MULTILINE;
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
284 }
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
285
d07456044b61 Core: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7982
diff changeset
286 if (rc->options & ~(NGX_REGEX_CASELESS|NGX_REGEX_MULTILINE)) {
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
287 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
288 "regex \"%V\" compilation failed: invalid options",
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
289 &rc->pattern)
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
290 - rc->err.data;
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
291 return NGX_ERROR;
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
292 }
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
293
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
294 ngx_regex_malloc_init(rc->pool);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
295
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
296 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
297 &errstr, &erroff, NULL);
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
299 /* ensure that there is no current pool */
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
300 ngx_regex_malloc_done();
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
301
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 if (re == NULL) {
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
303 if ((size_t) erroff == rc->pattern.len) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
304 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
305 "pcre_compile() failed: %s in \"%V\"",
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
306 errstr, &rc->pattern)
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
307 - rc->err.data;
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
308
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
309 } else {
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
310 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
311 "pcre_compile() failed: %s in \"%V\" at \"%s\"",
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
312 errstr, &rc->pattern, rc->pattern.data + erroff)
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
313 - rc->err.data;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
315
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
316 return NGX_ERROR;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
317 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
318
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
319 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
320 if (rc->regex == NULL) {
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
321 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
322 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
323
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
324 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
325
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
326 /* 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
327
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
328 if (ngx_regex_studies != NULL) {
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
329 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
330 if (elt == NULL) {
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
331 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
332 }
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 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
335 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
336 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
337
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
338 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
339 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
340 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
341 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
342 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
343
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
344 if (rc->captures == 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
345 return NGX_OK;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
348 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
349 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
350 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
351 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
352 }
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
353
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
354 if (rc->named_captures == 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
355 return NGX_OK;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
356 }
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
357
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
358 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
359 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
360 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
361 goto failed;
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
362 }
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
363
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
364 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names);
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
365 if (n < 0) {
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
366 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d";
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
367 goto failed;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
368 }
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
369
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
370 return NGX_OK;
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
371
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
372 failed:
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
373
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
374 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
375 - rc->err.data;
5824
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
376 return NGX_ERROR;
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
377
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
378 nomem:
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
379
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
380 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
381 "regex \"%V\" compilation failed: no memory",
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
382 &rc->pattern)
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
383 - rc->err.data;
e7f6991eca47 Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4638
diff changeset
384 return NGX_ERROR;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
387 #endif
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
388
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
389
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
390 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
391
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
392 ngx_int_t
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
393 ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, ngx_uint_t size)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
394 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
395 size_t *ov;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
396 ngx_int_t rc;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
397 ngx_uint_t n, i;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
398
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
399 /*
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
400 * The pcre2_match() function might allocate memory for backtracking
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
401 * frames, typical allocations are from 40k and above. So the allocator
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
402 * is configured to do direct allocations from heap during matching.
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
403 */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
404
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
405 ngx_regex_malloc_init(NULL);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
406
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
407 if (ngx_regex_match_data == NULL
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
408 || size > ngx_regex_match_data_size)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
409 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
410 /*
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
411 * Allocate a match data if not yet allocated or smaller than
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
412 * needed.
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
413 */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
414
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
415 if (ngx_regex_match_data) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
416 pcre2_match_data_free(ngx_regex_match_data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
417 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
418
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
419 ngx_regex_match_data_size = size;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
420 ngx_regex_match_data = pcre2_match_data_create(size / 3, NULL);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
421
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
422 if (ngx_regex_match_data == NULL) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
423 rc = PCRE2_ERROR_NOMEMORY;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
424 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
425 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
426 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
427
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
428 rc = pcre2_match(re, s->data, s->len, 0, 0, ngx_regex_match_data, NULL);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
429
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
430 if (rc < 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
431 goto failed;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
432 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
433
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
434 n = pcre2_get_ovector_count(ngx_regex_match_data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
435 ov = pcre2_get_ovector_pointer(ngx_regex_match_data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
436
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
437 if (n > size / 3) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
438 n = size / 3;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
439 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
440
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
441 for (i = 0; i < n; i++) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
442 captures[i * 2] = ov[i * 2];
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
443 captures[i * 2 + 1] = ov[i * 2 + 1];
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
444 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
445
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
446 failed:
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
447
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
448 ngx_regex_malloc_done();
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
449
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
450 return rc;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
451 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
452
7982
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
453 #else
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
454
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
455 ngx_int_t
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
456 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
457 {
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
458 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
459 0, 0, captures, size);
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
460 }
fbbb5ce52995 PCRE2 and PCRE binary compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7981
diff changeset
461
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
462 #endif
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
463
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
465 ngx_int_t
1784
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
466 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
467 {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
468 ngx_int_t n;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
469 ngx_uint_t i;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
470 ngx_regex_elt_t *re;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
471
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
472 re = a->elts;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
473
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
474 for (i = 0; i < a->nelts; i++) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
475
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
476 n = ngx_regex_exec(re[i].regex, s, NULL, 0);
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
477
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
478 if (n == NGX_REGEX_NO_MATCHED) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
479 continue;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
480 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
481
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
482 if (n < 0) {
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
483 ngx_log_error(NGX_LOG_ALERT, log, 0,
3325
42c16d8bddbe regex named captures
Igor Sysoev <igor@sysoev.ru>
parents: 3319
diff changeset
484 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
485 n, s, re[i].name);
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
486 return NGX_ERROR;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
487 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
488
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
489 /* match */
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
490
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
491 return NGX_OK;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
492 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
493
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
494 return NGX_DECLINED;
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
495 }
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
496
7d313324d874 ngx_regex_exec_array()
Igor Sysoev <igor@sysoev.ru>
parents: 503
diff changeset
497
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
498 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
499
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
500 static void * ngx_libc_cdecl
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
501 ngx_regex_malloc(size_t size, void *data)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
502 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
503 if (ngx_regex_pool) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
504 return ngx_palloc(ngx_regex_pool, size);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
505 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
506
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
507 if (ngx_regex_direct_alloc) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
508 return ngx_alloc(size, ngx_cycle->log);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
509 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
510
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
511 return NULL;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
512 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
513
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
514
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
515 static void ngx_libc_cdecl
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
516 ngx_regex_free(void *p, void *data)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
517 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
518 if (ngx_regex_direct_alloc) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
519 ngx_free(p);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
520 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
521
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
522 return;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
523 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
524
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
525 #else
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
526
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
527 static void * ngx_libc_cdecl
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
528 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
529 {
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
530 if (ngx_regex_pool) {
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
531 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
532 }
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
533
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
534 return NULL;
195
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535 }
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537
503
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
538 static void ngx_libc_cdecl
b1648294f693 nginx-0.1.26-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
539 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
540 {
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541 return;
8dee38ea9117 nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542 }
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
543
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
544 #endif
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
545
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
546
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
547 static void
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
548 ngx_regex_cleanup(void *data)
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
549 {
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
550 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT)
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
551 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
552
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
553 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
554 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
555 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
556
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
557 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
558 elts = part->elts;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
559
7088
Maxim Dounin <mdounin@mdounin.ru>
parents: 6511
diff changeset
560 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
561
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
562 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
563 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
564 break;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
565 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
566
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
567 part = part->next;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
568 elts = part->elts;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
569 i = 0;
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
570 }
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
571
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
572 /*
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
573 * 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
574 * have to explicitly call the pcre_free_study() function to free
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
575 * this memory. In PCRE2, we call the pcre2_code_free() function
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
576 * 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
577 */
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
578
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
579 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
580 pcre2_code_free(elts[i].regex);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
581 #else
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
582 if (elts[i].regex->extra != NULL) {
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
583 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
584 }
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
585 #endif
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
586 }
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
587 #endif
4423
196c3dacff0d Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents: 4413
diff changeset
588
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
589 /*
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
590 * 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
591 * 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
592 */
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
593
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
594 ngx_regex_studies = NULL;
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
595
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
596 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
597
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
598 /*
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
599 * Free compile context and match data. If needed at runtime by
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
600 * the new cycle, these will be re-allocated.
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
601 */
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
602
9166
533bc2336df4 Core: fixed memory leak on configuration reload with PCRE2.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8163
diff changeset
603 ngx_regex_malloc_init(NULL);
533bc2336df4 Core: fixed memory leak on configuration reload with PCRE2.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8163
diff changeset
604
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
605 if (ngx_regex_compile_context) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
606 pcre2_compile_context_free(ngx_regex_compile_context);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
607 ngx_regex_compile_context = NULL;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
608 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
609
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
610 if (ngx_regex_match_data) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
611 pcre2_match_data_free(ngx_regex_match_data);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
612 ngx_regex_match_data = NULL;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
613 ngx_regex_match_data_size = 0;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
614 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
615
9166
533bc2336df4 Core: fixed memory leak on configuration reload with PCRE2.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8163
diff changeset
616 ngx_regex_malloc_done();
533bc2336df4 Core: fixed memory leak on configuration reload with PCRE2.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8163
diff changeset
617
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
618 #endif
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
619 }
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
620
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 static ngx_int_t
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
623 ngx_regex_module_init(ngx_cycle_t *cycle)
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
624 {
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
625 int opt;
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
626 #if !(NGX_PCRE2)
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
627 const char *errstr;
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
628 #endif
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
629 ngx_uint_t i;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
630 ngx_list_part_t *part;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
631 ngx_regex_elt_t *elts;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
632 ngx_regex_conf_t *rcf;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
633
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
634 opt = 0;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
635
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
636 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
637
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
638 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
639
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
640 if (rcf->pcre_jit) {
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
641 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
642 opt = 1;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
643 #else
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
644 opt = PCRE_STUDY_JIT_COMPILE;
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
645 #endif
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
646 }
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
647
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
648 #endif
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 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
651
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
652 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
653 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
654
7088
Maxim Dounin <mdounin@mdounin.ru>
parents: 6511
diff changeset
655 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
656
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
657 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
658 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
659 break;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
660 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
661
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
662 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
663 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
664 i = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
665 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
666
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
667 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
668
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
669 if (opt) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
670 int n;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
671
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
672 n = pcre2_jit_compile(elts[i].regex, PCRE2_JIT_COMPLETE);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
673
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
674 if (n != 0) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
675 ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
676 "pcre2_jit_compile() failed: %d in \"%s\", "
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
677 "ignored",
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
678 n, elts[i].name);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
679 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
680 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
681
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
682 #else
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
683
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
684 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
685
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
686 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
687 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
688 "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
689 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
690 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
691
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
692 #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
693 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
694 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
695
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
696 jit = 0;
4638
6e1a48bcf915 Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents: 4423
diff changeset
697 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
698 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
699
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
700 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
701 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
702 "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
703 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
704 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
705 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
706 #endif
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
707 #endif
4388
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
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_malloc_done();
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
711
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
712 ngx_regex_studies = NULL;
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
713
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
714 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
715 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
716
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
717
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
718 static void *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
719 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
720 {
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
721 ngx_regex_conf_t *rcf;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
722 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
723
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
724 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
725 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
726 return NULL;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
727 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
728
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
729 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
730
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
731 cln = ngx_pool_cleanup_add(cycle->pool, 0);
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
732 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
733 return NULL;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
734 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
735
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
736 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
737 if (rcf->studies == NULL) {
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
738 return NULL;
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
739 }
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
740
8163
77d5c662f3d9 Fixed segfault if regex studies list allocation fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7983
diff changeset
741 cln->handler = ngx_regex_cleanup;
77d5c662f3d9 Fixed segfault if regex studies list allocation fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7983
diff changeset
742 cln->data = rcf;
77d5c662f3d9 Fixed segfault if regex studies list allocation fails.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7983
diff changeset
743
7979
060bf88d2473 Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7978
diff changeset
744 ngx_regex_studies = rcf->studies;
7978
2ca57257252d Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7088
diff changeset
745
4388
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
746 return rcf;
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
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 static char *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
751 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
752 {
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_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
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_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
756
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
757 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
758 }
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
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
761 static char *
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
762 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
763 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
764 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
765
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
766 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
767 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
768 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
769
7981
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
770 #if (NGX_PCRE2)
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
771 {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
772 int r;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
773 uint32_t jit;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
774
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
775 jit = 0;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
776 r = pcre2_config(PCRE2_CONFIG_JIT, &jit);
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
777
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
778 if (r != 0 || jit != 1) {
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
779 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
780 "PCRE2 library does not support JIT");
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
781 *fp = 0;
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
782 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
783 }
0b5f12d5c531 PCRE2 library support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7979
diff changeset
784 #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
785 {
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
786 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
787
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
788 jit = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
789 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
790
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
791 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
792 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
793 "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
794 *fp = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
795 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
796 }
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
797 #else
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
798 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
799 "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
800 *fp = 0;
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
801 #endif
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
802
005fc2d5e84f Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents: 4326
diff changeset
803 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
804 }