|
|
@@ -82,14 +82,28 @@ int
|
|
|
init_rule(rule_t *rule)
|
|
|
{
|
|
|
if (rule->pattern_re == NULL) {
|
|
|
- const char *reerr;
|
|
|
- int reerroffset;
|
|
|
+ int errornumber;
|
|
|
+ PCRE2_SIZE erroroffset;
|
|
|
+ rule->pattern_re = pcre2_compile(
|
|
|
+ (PCRE2_SPTR)rule->pattern, /* the pattern */
|
|
|
+ PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
|
|
|
+ 0, /* default options */
|
|
|
+ &errornumber, /* for error number */
|
|
|
+ &erroroffset, /* for error offset */
|
|
|
+ NULL); /* use default compile context */
|
|
|
|
|
|
- rule->pattern_re =
|
|
|
- pcre_compile(rule->pattern, 0, &reerr, &reerroffset, NULL);
|
|
|
if (rule->pattern_re == NULL) {
|
|
|
- LOGE("Regex compilation of \"%s\" failed: %s, offset %d",
|
|
|
- rule->pattern, reerr, reerroffset);
|
|
|
+ PCRE2_UCHAR errbuffer[512];
|
|
|
+ pcre2_get_error_message(errornumber, errbuffer, sizeof(errbuffer));
|
|
|
+ LOGE("PCRE2 regex compilation failed at offset %d: %s\n", (int)erroroffset,
|
|
|
+ errbuffer);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ rule->pattern_re_match_data = pcre2_match_data_create_from_pattern(rule->pattern_re, NULL);
|
|
|
+
|
|
|
+ if (rule->pattern_re_match_data == NULL) {
|
|
|
+ ERROR("PCRE2: the memory for the block could not be obtained");
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -109,8 +123,15 @@ lookup_rule(const struct cork_dllist *rules, const char *name, size_t name_len)
|
|
|
|
|
|
cork_dllist_foreach_void(rules, curr, next) {
|
|
|
rule_t *rule = cork_container_of(curr, rule_t, entries);
|
|
|
- if (pcre_exec(rule->pattern_re, NULL,
|
|
|
- name, name_len, 0, 0, NULL, 0) >= 0)
|
|
|
+ if (pcre2_match(
|
|
|
+ rule->pattern_re, /* the compiled pattern */
|
|
|
+ (PCRE2_SPTR)name, /* the subject string */
|
|
|
+ name_len, /* the length of the subject */
|
|
|
+ 0, /* start at offset 0 in the subject */
|
|
|
+ 0, /* default options */
|
|
|
+ rule->pattern_re_match_data, /* block for storing the result */
|
|
|
+ NULL /* use default match context */
|
|
|
+ ) >= 0)
|
|
|
return rule;
|
|
|
}
|
|
|
|
|
|
@@ -131,7 +152,13 @@ free_rule(rule_t *rule)
|
|
|
return;
|
|
|
|
|
|
ss_free(rule->pattern);
|
|
|
- if (rule->pattern_re != NULL)
|
|
|
- pcre_free(rule->pattern_re);
|
|
|
+ if (rule->pattern_re != NULL) {
|
|
|
+ pcre2_code_free(rule->pattern_re); /* data and the compiled pattern. */
|
|
|
+ rule->pattern_re = NULL;
|
|
|
+ }
|
|
|
+ if (rule->pattern_re_match_data != NULL) {
|
|
|
+ pcre2_match_data_free(rule->pattern_re_match_data); /* Release memory used for the match */
|
|
|
+ rule->pattern_re_match_data = NULL;
|
|
|
+ }
|
|
|
ss_free(rule);
|
|
|
}
|