95 PCRE2_SIZE erroroffset = 0;
97 pcre->
regexp = pcre2_compile(
99 PCRE2_ZERO_TERMINATED,
106 PCRE2_UCHAR errmsg[256];
107 (void)pcre2_get_error_message(errorcode, errmsg,
sizeof(errmsg));
108 n_log(
LOG_ERR,
"pcre2 compilation of %s failed at offset %zu : %s", str, (
size_t)erroroffset, (
char*)errmsg);
114 pcre->
match_data = pcre2_match_data_create_from_pattern(pcre->
regexp, NULL);
116 n_log(
LOG_ERR,
"pcre2_match_data_create_from_pattern failed (OOM?)");
122 (void)pcre2_jit_compile(pcre->
regexp, PCRE2_JIT_COMPLETE);
138 if ((*pcre)->captured > 0 && (*pcre)->match_list) {
140 (*pcre)->match_list = NULL;
141 (*pcre)->captured = 0;
144 if ((*pcre)->match_data) {
145 pcre2_match_data_free((*pcre)->match_data);
146 (*pcre)->match_data = NULL;
148 if ((*pcre)->regexp) {
149 pcre2_code_free((*pcre)->regexp);
150 (*pcre)->regexp = NULL;
196 _n_log(
LOG_DEBUG, file, func, line,
"no pcre error, match: %d elements in ovector", rc);
201 _n_log(
LOG_LEVEL, file, func, line,
"match OK, but not enough space in ovector to store all elements");
205 PCRE2_UCHAR errmsg[256];
206 PCRE2_SIZE cap =
sizeof(errmsg) /
sizeof(errmsg[0]);
208 int mrc = pcre2_get_error_message(rc, errmsg, cap);
210 _n_log(
LOG_LEVEL, file, func, line,
"PCRE2 error %d: %s", rc, (
const char*)errmsg);
212 _n_log(
LOG_LEVEL, file, func, line,
"Unknown PCRE2 error code: %d", rc);
231 pcre2_match_data* local_match_data = pcre2_match_data_create_from_pattern(pcre->
regexp, NULL);
232 if (!local_match_data) {
233 n_log(
LOG_ERR,
"npcre_match: pcre2_match_data_create_from_pattern failed");
237 int rc = (int)pcre2_match(
240 (PCRE2_SIZE)strlen(str),
246 pcre2_match_data_free(local_match_data);
248 return (rc > 0) ? TRUE : FALSE;
270 size_t len = strlen(str);
272 rc = (int)pcre2_match(
284 case PCRE2_ERROR_NOMATCH:
286 case PCRE2_ERROR_NULL:
289 case PCRE2_ERROR_BADOPTION:
292 case PCRE2_ERROR_BADMAGIC:
295 case PCRE2_ERROR_NOMEMORY:
313 PCRE2_SIZE* lens = NULL;
#define init_lock(__rwlock_mutex)
Macro for initializing a rwlock.
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define rw_lock_destroy(__rwlock_mutex)
Macro to destroy rwlock mutex.
#define unlock(__rwlock_mutex)
Macro for releasing read/write lock a rwlock mutex.
#define write_lock(__rwlock_mutex)
Macro for acquiring a write lock on a rwlock mutex.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Logging function.
PCRE2_UCHAR8 ** match_list
populated match list (NULL-terminated) after npcre_match_capture() Allocated by PCRE2 via pcre2_subst...
pcre2_code * regexp
regexp
pcre2_match_data * match_data
match data storage (ovector, etc.)
char * regexp_str
original regexp string
pthread_rwlock_t rwlock
rwlock protecting match_data, match_list, and captured
int captured
flag for match_list cleaning
N_PCRE * npcre_new(char *str, int flags)
From pcre doc, the flag bits are: PCRE_ANCHORED Force pattern anchoring PCRE_AUTO_CALLOUT Compile aut...
int _npcre_print_error(int LOG_LEVEL, const char *file, const char *func, int line, int rc)
print error associated to pcre error code
int npcre_match_capture(char *str, N_PCRE *pcre)
Return TRUE if str matches regexp, and make captures.
int npcre_match(char *str, N_PCRE *pcre)
Thread-safe match: returns TRUE/FALSE without modifying the N_PCRE struct.
int npcre_clean_match(N_PCRE *pcre)
clean the match list of the last capture, if any
int npcre_delete(N_PCRE **pcre)
Free a N_PCRE pointer.
static int LOG_LEVEL
static global maximum wanted log level value
PCRE helpers for regex matching.
#define PCRE2_LIST_FREE_CAST(x)