diff options
| author | jvoisin | 2018-02-05 18:13:57 +0100 |
|---|---|---|
| committer | jvoisin | 2018-02-05 18:13:57 +0100 |
| commit | 9d153cc185b4e2327a4aabe645cf1fabd3b4f21b (patch) | |
| tree | bfaf6ff5fa41098864d6b51ad1fa91304d8c32a6 /src/sp_pcre_compat.c | |
| parent | 3ab41db5bb38ec534e96f89680e55becd758aa28 (diff) | |
Massive simplification of functions hooking
Diffstat (limited to 'src/sp_pcre_compat.c')
| -rw-r--r-- | src/sp_pcre_compat.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 42a11cb..c3f1d86 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c | |||
| @@ -2,38 +2,40 @@ | |||
| 2 | 2 | ||
| 3 | #include "sp_pcre_compat.h" | 3 | #include "sp_pcre_compat.h" |
| 4 | 4 | ||
| 5 | sp_pcre* sp_pcre_compile(const char *const pattern) { | 5 | sp_pcre* sp_pcre_compile(const char* const pattern) { |
| 6 | sp_pcre* ret = NULL; | 6 | sp_pcre* ret = NULL; |
| 7 | const char *pcre_error = NULL; | 7 | const char* pcre_error = NULL; |
| 8 | #ifdef SP_HAS_PCRE2 | 8 | #ifdef SP_HAS_PCRE2 |
| 9 | int errornumber; | 9 | int errornumber; |
| 10 | PCRE2_SIZE erroroffset; | 10 | PCRE2_SIZE erroroffset; |
| 11 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | 11 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, |
| 12 | PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | ||
| 12 | #else | 13 | #else |
| 13 | int erroroffset; | 14 | int erroroffset; |
| 14 | ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); | 15 | ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); |
| 15 | #endif | 16 | #endif |
| 16 | 17 | ||
| 17 | if (NULL == ret) { | 18 | if (NULL == ret) { |
| 18 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, | 19 | sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, |
| 19 | pcre_error, sp_line_no); | 20 | pcre_error, sp_line_no); |
| 20 | } | 21 | } |
| 21 | return ret; | 22 | return ret; |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len) { | 25 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, |
| 26 | size_t len) { | ||
| 25 | int ret = 0; | 27 | int ret = 0; |
| 26 | 28 | ||
| 27 | assert(NULL != regexp); | 29 | assert(NULL != regexp); |
| 28 | assert(NULL != str); | 30 | assert(NULL != str); |
| 29 | 31 | ||
| 30 | #ifdef SP_HAS_PCRE2 | 32 | #ifdef SP_HAS_PCRE2 |
| 31 | pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regexp, NULL); | 33 | pcre2_match_data* match_data = |
| 32 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | 34 | pcre2_match_data_create_from_pattern(regexp, NULL); |
| 35 | ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); | ||
| 33 | #else | 36 | #else |
| 34 | int vec[30]; | 37 | int vec[30]; |
| 35 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, | 38 | ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); |
| 36 | sizeof(vec) / sizeof(int)); | ||
| 37 | #endif | 39 | #endif |
| 38 | 40 | ||
| 39 | if (ret < 0) { | 41 | if (ret < 0) { |
