1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | https://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Author: Andrei Zmievski <andrei@php.net> | 14 +----------------------------------------------------------------------+ 15 */ 16 17 #ifndef PHP_PCRE_H 18 #define PHP_PCRE_H 19 20 #ifdef HAVE_BUNDLED_PCRE 21 #include "pcre2lib/pcre2.h" 22 #else 23 #include "pcre2.h" 24 #endif 25 26 #include <locale.h> 27 28 PHPAPI zend_string *php_pcre_replace(zend_string *regex, zend_string *subject_str, const char *subject, size_t subject_len, zend_string *replace_str, size_t limit, size_t *replace_count); 29 PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count); 30 31 extern zend_module_entry pcre_module_entry; 32 #define pcre_module_ptr &pcre_module_entry 33 34 #include "php_version.h" 35 #define PHP_PCRE_VERSION PHP_VERSION 36 37 typedef struct _pcre_cache_entry pcre_cache_entry; 38 39 typedef enum { 40 PHP_PCRE_NO_ERROR = 0, 41 PHP_PCRE_INTERNAL_ERROR, 42 PHP_PCRE_BACKTRACK_LIMIT_ERROR, 43 PHP_PCRE_RECURSION_LIMIT_ERROR, 44 PHP_PCRE_BAD_UTF8_ERROR, 45 PHP_PCRE_BAD_UTF8_OFFSET_ERROR, 46 PHP_PCRE_JIT_STACKLIMIT_ERROR 47 } php_pcre_error_code; 48 49 PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex); 50 PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware); 51 52 PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, zval *return_value, 53 zval *subpats, int global, int use_flags, zend_long flags, zend_off_t start_offset); 54 55 PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *subject_str, const char *subject, size_t subject_len, zend_string *replace_str, 56 size_t limit, size_t *replace_count); 57 58 PHPAPI void php_pcre_split_impl( pcre_cache_entry *pce, zend_string *subject_str, zval *return_value, 59 zend_long limit_val, zend_long flags); 60 61 PHPAPI void php_pcre_grep_impl( pcre_cache_entry *pce, zval *input, zval *return_value, 62 zend_long flags); 63 64 PHPAPI pcre2_match_context *php_pcre_mctx(void); 65 PHPAPI pcre2_general_context *php_pcre_gctx(void); 66 PHPAPI pcre2_compile_context *php_pcre_cctx(void); 67 PHPAPI void php_pcre_pce_incref(pcre_cache_entry *); 68 PHPAPI void php_pcre_pce_decref(pcre_cache_entry *); 69 PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *); 70 /* capture_count can be ignored, re is required. */ 71 PHPAPI pcre2_match_data *php_pcre_create_match_data(uint32_t, pcre2_code *); 72 PHPAPI void php_pcre_free_match_data(pcre2_match_data *); 73 74 ZEND_BEGIN_MODULE_GLOBALS(pcre) 75 HashTable pcre_cache; 76 zend_long backtrack_limit; 77 zend_long recursion_limit; 78 #ifdef HAVE_PCRE_JIT_SUPPORT 79 bool jit; 80 #endif 81 bool per_request_cache; 82 php_pcre_error_code error_code; 83 /* Used for unmatched subpatterns in OFFSET_CAPTURE mode */ 84 zval unmatched_null_pair; 85 zval unmatched_empty_pair; 86 /* General context using per-request allocator (ZMM). */ 87 pcre2_general_context *gctx_zmm; 88 ZEND_END_MODULE_GLOBALS(pcre) 89 90 PHPAPI ZEND_EXTERN_MODULE_GLOBALS(pcre) 91 #define PCRE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pcre, v) 92 93 #define phpext_pcre_ptr pcre_module_ptr 94 95 #endif /* PHP_PCRE_H */ 96