comparison src/core/ngx_regex.h @ 7982:fbbb5ce52995

PCRE2 and PCRE binary compatibility. With this change, dynamic modules using nginx regex interface can be used regardless of the variant of the PCRE library nginx was compiled with. If a module is compiled with different PCRE library variant, in case of ngx_regex_exec() errors it will report wrong function name in error messages. This is believed to be tolerable, given that fixing this will require interface changes.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 25 Dec 2021 01:07:16 +0300
parents 0b5f12d5c531
children d07456044b61
comparison
equal deleted inserted replaced
7981:0b5f12d5c531 7982:fbbb5ce52995
17 17
18 #define PCRE2_CODE_UNIT_WIDTH 8 18 #define PCRE2_CODE_UNIT_WIDTH 8
19 #include <pcre2.h> 19 #include <pcre2.h>
20 20
21 #define NGX_REGEX_NO_MATCHED PCRE2_ERROR_NOMATCH /* -1 */ 21 #define NGX_REGEX_NO_MATCHED PCRE2_ERROR_NOMATCH /* -1 */
22 #define NGX_REGEX_CASELESS PCRE2_CASELESS
23 22
24 typedef pcre2_code ngx_regex_t; 23 typedef pcre2_code ngx_regex_t;
25 24
26 #else 25 #else
27 26
28 #include <pcre.h> 27 #include <pcre.h>
29 28
30 #define NGX_REGEX_NO_MATCHED PCRE_ERROR_NOMATCH /* -1 */ 29 #define NGX_REGEX_NO_MATCHED PCRE_ERROR_NOMATCH /* -1 */
31 #define NGX_REGEX_CASELESS PCRE_CASELESS
32 30
33 typedef struct { 31 typedef struct {
34 pcre *code; 32 pcre *code;
35 pcre_extra *extra; 33 pcre_extra *extra;
36 } ngx_regex_t; 34 } ngx_regex_t;
37 35
38 #endif 36 #endif
39 37
40 38
39 #define NGX_REGEX_CASELESS 0x00000001
40
41
41 typedef struct { 42 typedef struct {
42 ngx_str_t pattern; 43 ngx_str_t pattern;
43 ngx_pool_t *pool; 44 ngx_pool_t *pool;
44 ngx_int_t options; 45 ngx_uint_t options;
45 46
46 ngx_regex_t *regex; 47 ngx_regex_t *regex;
47 int captures; 48 int captures;
48 int named_captures; 49 int named_captures;
49 int name_size; 50 int name_size;
59 60
60 61
61 void ngx_regex_init(void); 62 void ngx_regex_init(void);
62 ngx_int_t ngx_regex_compile(ngx_regex_compile_t *rc); 63 ngx_int_t ngx_regex_compile(ngx_regex_compile_t *rc);
63 64
64 #if (NGX_PCRE2)
65
66 ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, 65 ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures,
67 ngx_uint_t size); 66 ngx_uint_t size);
67
68 #if (NGX_PCRE2)
68 #define ngx_regex_exec_n "pcre2_match()" 69 #define ngx_regex_exec_n "pcre2_match()"
69
70 #else 70 #else
71
72 #define ngx_regex_exec(re, s, captures, size) \
73 pcre_exec(re->code, re->extra, (const char *) (s)->data, (s)->len, 0, 0, \
74 captures, size)
75 #define ngx_regex_exec_n "pcre_exec()" 71 #define ngx_regex_exec_n "pcre_exec()"
76
77 #endif 72 #endif
78 73
79 ngx_int_t ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log); 74 ngx_int_t ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log);
80 75
81 76