@@ -33,15 +33,8 @@ constexpr std::string_view DefaultCrrIdentHeader = {"X-Crr-Ident"};
3333
3434Config::~Config ()
3535{
36- if (nullptr != m_regex_extra) {
37- #ifndef PCRE_STUDY_JIT_COMPILE
38- pcre_free (m_regex_extra);
39- #else
40- pcre_free_study (m_regex_extra);
41- #endif
42- }
4336 if (nullptr != m_regex) {
44- pcre_free ( m_regex) ;
37+ delete m_regex;
4538 }
4639}
4740
@@ -159,16 +152,16 @@ Config::fromArgs(int const argc, char const *const argv[])
159152 break ;
160153 }
161154
162- const char *errptr ;
155+ std::string err ;
163156 int erroffset;
164157 m_regexstr = optarg;
165- m_regex = pcre_compile (m_regexstr.c_str (), 0 , &errptr, &erroffset, nullptr );
166- if (nullptr == m_regex) {
167- ERROR_LOG (" Invalid regex: '%s'" , m_regexstr.c_str ());
168- } else {
169- m_regex_type = Exclude;
170- m_regex_extra = pcre_study (m_regex, 0 , &errptr);
158+ m_regex = new Regex ();
159+
160+ if (m_regex->compile (m_regexstr, err, erroffset)) {
161+ m_regex_type = Exclude;
171162 DEBUG_LOG (" Using regex for url exclude: '%s'" , m_regexstr.c_str ());
163+ } else {
164+ ERROR_LOG (" Invalid regex: '%s' - %s at column %d" , m_regexstr.c_str (), err.c_str (), erroffset);
172165 }
173166 } break ;
174167 case ' g' : {
@@ -180,17 +173,16 @@ Config::fromArgs(int const argc, char const *const argv[])
180173 ERROR_LOG (" Regex already specified!" );
181174 break ;
182175 }
183-
184- const char *errptr;
176+ std::string err;
185177 int erroffset;
186178 m_regexstr = optarg;
187- m_regex = pcre_compile (m_regexstr.c_str (), 0 , &errptr, &erroffset, nullptr );
188- if (nullptr == m_regex) {
189- ERROR_LOG (" Invalid regex: '%s'" , m_regexstr.c_str ());
190- } else {
191- m_regex_type = Include;
192- m_regex_extra = pcre_study (m_regex, 0 , &errptr);
179+ m_regex = new Regex ();
180+
181+ if (m_regex->compile (m_regexstr, err, erroffset)) {
182+ m_regex_type = Include;
193183 DEBUG_LOG (" Using regex for url include: '%s'" , m_regexstr.c_str ());
184+ } else {
185+ ERROR_LOG (" Invalid regex: '%s' - %s at column %d" , m_regexstr.c_str (), err.c_str (), erroffset);
194186 }
195187 } break ;
196188 case ' l' : {
@@ -330,12 +322,14 @@ Config::matchesRegex(char const *const url, int const urllen) const
330322
331323 switch (m_regex_type) {
332324 case Exclude: {
333- if (0 <= pcre_exec (m_regex, m_regex_extra, url, urllen, 0 , 0 , nullptr , 0 )) {
325+ // Exclude means if the regex matches, it doesn't match
326+ if (m_regex->exec ({url, static_cast <size_t >(urllen)})) {
334327 matches = false ;
335328 }
336329 } break ;
337330 case Include: {
338- if (pcre_exec (m_regex, m_regex_extra, url, urllen, 0 , 0 , nullptr , 0 ) < 0 ) {
331+ // Include means if the regex matches, it matches
332+ if (!m_regex->exec ({url, static_cast <size_t >(urllen)})) {
339333 matches = false ;
340334 }
341335 } break ;
0 commit comments