From: Jaroslav Kysela Date: Tue, 16 May 2017 08:41:07 +0000 (+0200) Subject: DVR: add PCRE2 support X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54ade6347467b764bef9ba219000d39d155dc535;p=thirdparty%2Ftvheadend.git DVR: add PCRE2 support --- diff --git a/configure b/configure index a5487965a..12966718d 100755 --- a/configure +++ b/configure @@ -55,6 +55,7 @@ OPTIONS=( "inotify:auto" "epoll:auto" "pcre:auto" + "pcre2:auto" "uriparser:auto" "ccache:auto" "tvhcsa:auto" @@ -385,14 +386,29 @@ if enabled_or_auto satip_client; then enable upnp fi +# +# PCRE2 +# +if enabled_or_auto pcre2; then + if check_pkg libpcre2-8; then + enable pcre2 + elif enabled pcre2; then + die "pcre2 development support not found (use --disable-pcre2)" + fi +fi + # # PCRE # -if enabled_or_auto pcre; then - if check_pkg libpcre; then - enable pcre - elif enabled pcre; then - die "pcre development support not found (use --disable-pcre)" +if enabled pcre2; then + disable pcre +else + if enabled_or_auto pcre; then + if check_pkg libpcre; then + enable pcre + elif enabled pcre; then + die "pcre development support not found (use --disable-pcre)" + fi fi fi diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h index b9ff99afd..0a828b954 100644 --- a/src/dvr/dvr.h +++ b/src/dvr/dvr.h @@ -23,6 +23,10 @@ #if ENABLE_PCRE #include #endif +#if ENABLE_PCRE2 +#define PCRE2_CODE_UNIT_WIDTH 8 +#include +#endif #include "epg.h" #include "channels.h" #include "subscriptions.h" @@ -346,6 +350,9 @@ typedef struct dvr_autorec_entry { #if ENABLE_PCRE pcre *dae_title_pcre; pcre_extra *dae_title_pcre_extra; +#elif ENABLE_PCRE2 + pcre2_code *dae_title_pcre; + pcre2_match_data *dae_title_pcre_match; #endif int dae_fulltext; diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index 0a0c01a4a..b5f70394f 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -41,14 +41,18 @@ struct dvr_autorec_entry_queue autorec_entries; */ static inline int autorec_regexec(dvr_autorec_entry_t *dae, const char *str) { - int r; #if ENABLE_PCRE if (dae->dae_pcre) { - int vec[30]; + int r, vec[30]; r = pcre_exec(dae->dae_title_pcre, dae->dae_title_pcre_extra, str, strlen(str), 0, 0, vec, ARRAY_SIZE(vec)); return r < 0; } else +#elif ENABLE_PCRE2 + int r; + r = pcre2_match(dae->dae_title_pcre, (PCRE2_SPTR8)str, -1, 0, 0, + dae->dae_title_pcre_match, NULL); + return r <= 0; #endif { return regexec(&dae->dae_title_preg, str, 0, NULL, 0); @@ -72,6 +76,12 @@ static void autorec_regfree(dvr_autorec_entry_t *dae) dae->dae_title_pcre_extra = NULL; dae->dae_title_pcre = NULL; } else +#elif ENABLE_PCRE2 + if (dae->dae_pcre) { + pcre2_match_data_free(dae->dae_title_pcre_match); + dae->dae_title_pcre_match = NULL; + dae->dae_title_pcre = NULL; + } else #endif { regfree(&dae->dae_title_preg); @@ -345,6 +355,9 @@ dvr_autorec_create(const char *uuid, htsmsg_t *conf) TAILQ_INSERT_TAIL(&autorec_entries, dae, dae_link); + /* PCRE flag must be set before load (order issue) */ + if (conf) + dae->dae_pcre = htsmsg_get_bool_or_default(conf, "pcre", 0); idnode_load(&dae->dae_id, conf); htsp_autorec_entry_add(dae); @@ -589,6 +602,21 @@ dvr_autorec_entry_class_title_set(void *o, const void *v) dae->dae_title = strdup(title); } } else +#elif ENABLE_PCRE2 + if (dae->dae_pcre) { + PCRE2_UCHAR8 ebuf[128]; + int ecode, eoff; + dae->dae_title_pcre = pcre2_compile((PCRE2_SPTR8)title, -1, + PCRE2_CASELESS | PCRE2_UTF, + &ecode, &eoff, NULL); + if (dae->dae_title_pcre == NULL) { + (void)pcre2_get_error_message(ecode, ebuf, 120); + tvherror(LS_DVR, "Unable to compile PCRE2 '%s': %s", title, ebuf); + } else { + dae->dae_title_pcre_match = pcre2_match_data_create(20, NULL); + dae->dae_title = strdup(title); + } + } else #endif { if (!regcomp(&dae->dae_title_preg, title,