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