summaryrefslogtreecommitdiff
path: root/src/sp_pcre_compat.c
diff options
context:
space:
mode:
authorjvoisin2020-12-13 16:26:19 +0100
committerjvoisin2020-12-13 16:26:19 +0100
commitefec261b07e76f6c3e53beb831bbc2c65d8884d3 (patch)
tree50757bc6d8540124c70e8f81514c84f34eee4c89 /src/sp_pcre_compat.c
parent5329a55bfd2b00d617a40d587cd37050d964ccbf (diff)
Get rid of pcre1
Diffstat (limited to 'src/sp_pcre_compat.c')
-rw-r--r--src/sp_pcre_compat.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c
index 3f8ff1e..d3a10af 100644
--- a/src/sp_pcre_compat.c
+++ b/src/sp_pcre_compat.c
@@ -1,19 +1,14 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3sp_pcre* sp_pcre_compile(const char* const pattern) { 3sp_pcre* sp_pcre_compile(const char* const pattern) {
4 sp_pcre* ret = NULL; 4 assert(NULL != pattern);
5#ifdef SP_HAS_PCRE2 5
6 unsigned char pcre_error[128] = {0}; 6 unsigned char pcre_error[128] = {0};
7 int errornumber; 7 int errornumber;
8 PCRE2_SIZE erroroffset; 8 PCRE2_SIZE erroroffset;
9 ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, 9 sp_pcre* ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
10 PCRE2_CASELESS, &errornumber, &erroroffset, NULL); 10 PCRE2_CASELESS, &errornumber, &erroroffset, NULL);
11 pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)); 11 pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error));
12#else
13 const char* pcre_error = NULL;
14 int erroroffset;
15 ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL);
16#endif
17 12
18 if (NULL == ret) { 13 if (NULL == ret) {
19 sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, 14 sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern,
@@ -24,26 +19,15 @@ sp_pcre* sp_pcre_compile(const char* const pattern) {
24 19
25bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, 20bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str,
26 size_t len) { 21 size_t len) {
27 int ret = 0;
28
29 assert(NULL != regexp); 22 assert(NULL != regexp);
30 assert(NULL != str); 23 assert(NULL != str);
31 24
32#ifdef SP_HAS_PCRE2
33 pcre2_match_data* match_data = 25 pcre2_match_data* match_data =
34 pcre2_match_data_create_from_pattern(regexp, NULL); 26 pcre2_match_data_create_from_pattern(regexp, NULL);
35 ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); 27 int ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL);
36#else
37 int vec[30];
38 ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int));
39#endif
40 28
41 if (ret < 0) { 29 if (ret < 0) {
42#ifdef SP_HAS_PCRE2
43 if (ret != PCRE2_ERROR_NOMATCH) { 30 if (ret != PCRE2_ERROR_NOMATCH) {
44#else
45 if (ret != PCRE_ERROR_NOMATCH) {
46#endif
47 // LCOV_EXCL_START 31 // LCOV_EXCL_START
48 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret); 32 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
49 // LCOV_EXCL_STOP 33 // LCOV_EXCL_STOP