100-Upgrade-PCRE-to-PCRE2.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. From d4f4d9761cbd41c3ab6de79383ff39b9f97bf452 Mon Sep 17 00:00:00 2001
  2. From: Syrone Wong <[email protected]>
  3. Date: Sat, 18 Nov 2017 20:06:50 +0800
  4. Subject: [PATCH] Upgrade PCRE to PCRE2
  5. - Use 8bit variant by default
  6. This comes from a PR closed and never reopen as at times PCRE2 was too
  7. new(???.)
  8. Ref: https://github.com/shadowsocks/shadowsocks-libev/pull/1792
  9. Signed-off-by: Syrone Wong <[email protected]>
  10. [ squash the first 2 patch from PR, drop the last one ]
  11. Signed-off-by: Christian Marangi <[email protected]>
  12. ---
  13. .travis.yml | 9 ++-
  14. configure.ac | 8 +--
  15. m4/pcre.m4 | 152 ------------------------------------------
  16. m4/pcre2.m4 | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++
  17. src/rule.c | 53 ++++++++++++---
  18. src/rule.h | 23 +++++--
  19. 6 files changed, 253 insertions(+), 173 deletions(-)
  20. delete mode 100644 m4/pcre.m4
  21. create mode 100644 m4/pcre2.m4
  22. # diff --git a/.travis.yml b/.travis.yml
  23. # index ee3424c..e7da08c 100644
  24. # --- a/.travis.yml
  25. # +++ b/.travis.yml
  26. # @@ -11,11 +11,12 @@ env:
  27. # global:
  28. # - LIBSODIUM_VER=1.0.12
  29. # - MBEDTLS_VER=2.4.0
  30. # + - PCRE2_VER=10.30
  31. # before_install:
  32. # - |
  33. # if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
  34. # # All dependencies for macOS build. Some packages has been installed by travis so use reinstall.
  35. # - brew reinstall autoconf automake xmlto c-ares libev mbedtls libsodium asciidoc >> /dev/null 2>&1;
  36. # + brew reinstall autoconf automake xmlto pcre2 c-ares libev mbedtls libsodium asciidoc >> /dev/null 2>&1;
  37. # else
  38. # wget https://github.com/jedisct1/libsodium/releases/download/$LIBSODIUM_VER/libsodium-$LIBSODIUM_VER.tar.gz;
  39. # tar xvf libsodium-$LIBSODIUM_VER.tar.gz;
  40. # @@ -29,6 +30,12 @@ before_install:
  41. # make SHARED=1;
  42. # sudo make install;
  43. # popd;
  44. # + wget https://ftp.pcre.org/pub/pcre/pcre2-$PCRE2_VER.tar.gz;
  45. # + tar xvf pcre2-$PCRE2_VER.tar.gz;
  46. # + pushd pcre2-$PCRE2_VER;
  47. # + ./configure --prefix=/usr --enable-pcre2-16 --enable-pcre2-32 && make;
  48. # + sudo make install;
  49. # + popd;
  50. # # Load cached docker images
  51. # if [[ -d $HOME/docker ]]; then
  52. # ls $HOME/docker/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load";
  53. --- a/configure.ac
  54. +++ b/configure.ac
  55. @@ -20,10 +20,10 @@ AC_DISABLE_STATIC
  56. AC_DISABLE_SHARED
  57. LT_INIT([dlopen])
  58. -dnl Check for pcre library
  59. -TS_CHECK_PCRE
  60. -if test "x${enable_pcre}" != "xyes"; then
  61. - AC_MSG_ERROR([Cannot find pcre library. Configure --with-pcre=DIR])
  62. +dnl Check for pcre2 library
  63. +TS_CHECK_PCRE2
  64. +if test "x${enable_pcre2}" != "xyes"; then
  65. + AC_MSG_ERROR([Cannot find pcre2 library. Configure --with-pcre2=DIR])
  66. fi
  67. dnl Checks for using shared libraries from system
  68. --- a/m4/pcre.m4
  69. +++ /dev/null
  70. @@ -1,152 +0,0 @@
  71. -dnl -------------------------------------------------------- -*- autoconf -*-
  72. -dnl Licensed to the Apache Software Foundation (ASF) under one or more
  73. -dnl contributor license agreements. See the NOTICE file distributed with
  74. -dnl this work for additional information regarding copyright ownership.
  75. -dnl The ASF licenses this file to You under the Apache License, Version 2.0
  76. -dnl (the "License"); you may not use this file except in compliance with
  77. -dnl the License. You may obtain a copy of the License at
  78. -dnl
  79. -dnl http://www.apache.org/licenses/LICENSE-2.0
  80. -dnl
  81. -dnl Unless required by applicable law or agreed to in writing, software
  82. -dnl distributed under the License is distributed on an "AS IS" BASIS,
  83. -dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  84. -dnl See the License for the specific language governing permissions and
  85. -dnl limitations under the License.
  86. -
  87. -dnl
  88. -dnl TS_ADDTO(variable, value)
  89. -dnl
  90. -dnl Add value to variable
  91. -dnl
  92. -AC_DEFUN([TS_ADDTO], [
  93. - if test "x$$1" = "x"; then
  94. - test "x$verbose" = "xyes" && echo " setting $1 to \"$2\""
  95. - $1="$2"
  96. - else
  97. - ats_addto_bugger="$2"
  98. - for i in $ats_addto_bugger; do
  99. - ats_addto_duplicate="0"
  100. - for j in $$1; do
  101. - if test "x$i" = "x$j"; then
  102. - ats_addto_duplicate="1"
  103. - break
  104. - fi
  105. - done
  106. - if test $ats_addto_duplicate = "0"; then
  107. - test "x$verbose" = "xyes" && echo " adding \"$i\" to $1"
  108. - $1="$$1 $i"
  109. - fi
  110. - done
  111. - fi
  112. -])dnl
  113. -
  114. -dnl
  115. -dnl TS_ADDTO_RPATH(path)
  116. -dnl
  117. -dnl Adds path to variable with the '-rpath' directive.
  118. -dnl
  119. -AC_DEFUN([TS_ADDTO_RPATH], [
  120. - AC_MSG_NOTICE([adding $1 to RPATH])
  121. - TS_ADDTO(LIBTOOL_LINK_FLAGS, [-R$1])
  122. -])dnl
  123. -
  124. -dnl
  125. -dnl pcre.m4: Trafficserver's pcre autoconf macros
  126. -dnl
  127. -
  128. -dnl
  129. -dnl TS_CHECK_PCRE: look for pcre libraries and headers
  130. -dnl
  131. -AC_DEFUN([TS_CHECK_PCRE], [
  132. -enable_pcre=no
  133. -AC_ARG_WITH(pcre, [AC_HELP_STRING([--with-pcre=DIR],[use a specific pcre library])],
  134. -[
  135. - if test "x$withval" != "xyes" && test "x$withval" != "x"; then
  136. - pcre_base_dir="$withval"
  137. - if test "$withval" != "no"; then
  138. - enable_pcre=yes
  139. - case "$withval" in
  140. - *":"*)
  141. - pcre_include="`echo $withval |sed -e 's/:.*$//'`"
  142. - pcre_ldflags="`echo $withval |sed -e 's/^.*://'`"
  143. - AC_MSG_CHECKING(checking for pcre includes in $pcre_include libs in $pcre_ldflags )
  144. - ;;
  145. - *)
  146. - pcre_include="$withval/include"
  147. - pcre_ldflags="$withval/lib"
  148. - AC_MSG_CHECKING(checking for pcre includes in $withval)
  149. - ;;
  150. - esac
  151. - fi
  152. - fi
  153. -],
  154. -[
  155. - AC_CHECK_PROG(PCRE_CONFIG, pcre-config, pcre-config)
  156. - if test "x$PCRE_CONFIG" != "x"; then
  157. - enable_pcre=yes
  158. - pcre_base_dir="`$PCRE_CONFIG --prefix`"
  159. - pcre_include="`$PCRE_CONFIG --cflags | sed -es/-I//`"
  160. - pcre_ldflags="`$PCRE_CONFIG --libs | sed -es/-lpcre// -es/-L//`"
  161. - fi
  162. -])
  163. -
  164. -if test "x$pcre_base_dir" = "x"; then
  165. - AC_MSG_CHECKING([for pcre location])
  166. - AC_CACHE_VAL(ats_cv_pcre_dir,[
  167. - for dir in /usr/local /usr ; do
  168. - if test -d $dir && ( test -f $dir/include/pcre.h || test -f $dir/include/pcre/pcre.h ); then
  169. - ats_cv_pcre_dir=$dir
  170. - break
  171. - fi
  172. - done
  173. - ])
  174. - pcre_base_dir=$ats_cv_pcre_dir
  175. - if test "x$pcre_base_dir" = "x"; then
  176. - enable_pcre=no
  177. - AC_MSG_RESULT([not found])
  178. - else
  179. - enable_pcre=yes
  180. - pcre_include="$pcre_base_dir/include"
  181. - pcre_ldflags="$pcre_base_dir/lib"
  182. - AC_MSG_RESULT([$pcre_base_dir])
  183. - fi
  184. -else
  185. - AC_MSG_CHECKING(for pcre headers in $pcre_include)
  186. - if test -d $pcre_include && test -d $pcre_ldflags && ( test -f $pcre_include/pcre.h || test -f $pcre_include/pcre/pcre.h ); then
  187. - AC_MSG_RESULT([ok])
  188. - else
  189. - AC_MSG_RESULT([not found])
  190. - fi
  191. -fi
  192. -
  193. -pcreh=0
  194. -pcre_pcreh=0
  195. -if test "$enable_pcre" != "no"; then
  196. - saved_ldflags=$LDFLAGS
  197. - saved_cppflags=$CFLAGS
  198. - pcre_have_headers=0
  199. - pcre_have_libs=0
  200. - if test "$pcre_base_dir" != "/usr"; then
  201. - TS_ADDTO(CFLAGS, [-I${pcre_include}])
  202. - TS_ADDTO(CFLAGS, [-DPCRE_STATIC])
  203. - TS_ADDTO(LDFLAGS, [-L${pcre_ldflags}])
  204. - TS_ADDTO_RPATH(${pcre_ldflags})
  205. - fi
  206. - AC_SEARCH_LIBS([pcre_exec], [pcre], [pcre_have_libs=1])
  207. - if test "$pcre_have_libs" != "0"; then
  208. - AC_CHECK_HEADERS(pcre.h, [pcre_have_headers=1])
  209. - AC_CHECK_HEADERS(pcre/pcre.h, [pcre_have_headers=1])
  210. - fi
  211. - if test "$pcre_have_headers" != "0"; then
  212. - AC_DEFINE(HAVE_LIBPCRE,1,[Compiling with pcre support])
  213. - AC_SUBST(LIBPCRE, [-lpcre])
  214. - else
  215. - enable_pcre=no
  216. - CFLAGS=$saved_cppflags
  217. - LDFLAGS=$saved_ldflags
  218. - fi
  219. -fi
  220. -AC_SUBST(pcreh)
  221. -AC_SUBST(pcre_pcreh)
  222. -])
  223. --- /dev/null
  224. +++ b/m4/pcre2.m4
  225. @@ -0,0 +1,181 @@
  226. +dnl -------------------------------------------------------- -*- autoconf -*-
  227. +dnl Licensed to the Apache Software Foundation (ASF) under one or more
  228. +dnl contributor license agreements. See the NOTICE file distributed with
  229. +dnl this work for additional information regarding copyright ownership.
  230. +dnl The ASF licenses this file to You under the Apache License, Version 2.0
  231. +dnl (the "License"); you may not use this file except in compliance with
  232. +dnl the License. You may obtain a copy of the License at
  233. +dnl
  234. +dnl http://www.apache.org/licenses/LICENSE-2.0
  235. +dnl
  236. +dnl Unless required by applicable law or agreed to in writing, software
  237. +dnl distributed under the License is distributed on an "AS IS" BASIS,
  238. +dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  239. +dnl See the License for the specific language governing permissions and
  240. +dnl limitations under the License.
  241. +
  242. +dnl Modified by Syrone Wong <[email protected]> to support pcre2 8bit variant only
  243. +
  244. +dnl
  245. +dnl TS_ADDTO(variable, value)
  246. +dnl
  247. +dnl Add value to variable
  248. +dnl
  249. +AC_DEFUN([TS_ADDTO], [
  250. + if test "x$$1" = "x"; then
  251. + test "x$verbose" = "xyes" && echo " setting $1 to \"$2\""
  252. + $1="$2"
  253. + else
  254. + ats_addto_bugger="$2"
  255. + for i in $ats_addto_bugger; do
  256. + ats_addto_duplicate="0"
  257. + for j in $$1; do
  258. + if test "x$i" = "x$j"; then
  259. + ats_addto_duplicate="1"
  260. + break
  261. + fi
  262. + done
  263. + if test $ats_addto_duplicate = "0"; then
  264. + test "x$verbose" = "xyes" && echo " adding \"$i\" to $1"
  265. + $1="$$1 $i"
  266. + fi
  267. + done
  268. + fi
  269. +])dnl
  270. +
  271. +dnl
  272. +dnl TS_ADDTO_RPATH(path)
  273. +dnl
  274. +dnl Adds path to variable with the '-rpath' directive.
  275. +dnl
  276. +AC_DEFUN([TS_ADDTO_RPATH], [
  277. + AC_MSG_NOTICE([adding $1 to RPATH])
  278. + TS_ADDTO(LIBTOOL_LINK_FLAGS, [-R$1])
  279. +])dnl
  280. +
  281. +dnl
  282. +dnl pcre2.m4: Trafficserver's pcre2 autoconf macros
  283. +dnl
  284. +
  285. +dnl
  286. +dnl TS_CHECK_PCRE2: look for pcre2 libraries and headers
  287. +dnl
  288. +AC_DEFUN([TS_CHECK_PCRE2], [
  289. +enable_pcre2=no
  290. +AC_ARG_WITH(pcre2, [AC_HELP_STRING([--with-pcre2=DIR],[use a specific pcre2 library])],
  291. +[
  292. + if test "x$withval" != "xyes" && test "x$withval" != "x"; then
  293. + pcre2_base_dir="$withval"
  294. + if test "$withval" != "no"; then
  295. + enable_pcre2=yes
  296. + case "$withval" in
  297. + *":"*)
  298. + pcre2_include="`echo $withval |sed -e 's/:.*$//'`"
  299. + pcre2_ldflags="`echo $withval |sed -e 's/^.*://'`"
  300. + AC_MSG_CHECKING(checking for pcre2 includes in $pcre2_include libs in $pcre2_ldflags )
  301. + ;;
  302. + *)
  303. + pcre2_include="$withval/include"
  304. + pcre2_ldflags="$withval/lib"
  305. + AC_MSG_CHECKING(checking for pcre2 includes in $withval)
  306. + ;;
  307. + esac
  308. + fi
  309. + fi
  310. +],
  311. +[
  312. + AC_CHECK_PROG(PCRE2_CONFIG, pcre2-config, pcre2-config)
  313. + if test "x$PCRE2_CONFIG" != "x"; then
  314. + enable_pcre2=yes
  315. + pcre2_base_dir="`$PCRE2_CONFIG --prefix`"
  316. + pcre2_include="`$PCRE2_CONFIG --cflags | sed -es/-I//`"
  317. + pcre2_ldflags="`$PCRE2_CONFIG --libs8 | sed -es/-lpcre2-8// -es/-L//`"
  318. + fi
  319. +])
  320. +
  321. +if test "x$pcre2_base_dir" = "x"; then
  322. + AC_MSG_CHECKING([for pcre2 location])
  323. + AC_CACHE_VAL(ats_cv_pcre2_dir,[
  324. + for dir in /usr/local /usr ; do
  325. + if test -d $dir && ( test -f $dir/include/pcre2.h || test -f $dir/include/pcre2/pcre2.h ); then
  326. + ats_cv_pcre2_dir=$dir
  327. + break
  328. + fi
  329. + done
  330. + ])
  331. + pcre2_base_dir=$ats_cv_pcre2_dir
  332. + if test "x$pcre2_base_dir" = "x"; then
  333. + enable_pcre2=no
  334. + AC_MSG_RESULT([not found])
  335. + else
  336. + enable_pcre2=yes
  337. + pcre2_include="$pcre2_base_dir/include"
  338. + pcre2_ldflags="$pcre2_base_dir/lib"
  339. + AC_MSG_RESULT([$pcre2_base_dir])
  340. + fi
  341. +else
  342. + AC_MSG_CHECKING(for pcre2 headers in $pcre2_include)
  343. + if test -d $pcre2_include && test -d $pcre2_ldflags && ( test -f $pcre2_include/pcre2.h || test -f $pcre2_include/pcre2/pcre2.h ); then
  344. + AC_MSG_RESULT([ok])
  345. + else
  346. + AC_MSG_RESULT([not found])
  347. + fi
  348. +fi
  349. +
  350. +pcre2h=0
  351. +pcre2_pcre2h=0
  352. +if test "$enable_pcre2" != "no"; then
  353. + saved_ldflags=$LDFLAGS
  354. + saved_cppflags=$CFLAGS
  355. + pcre2_have_headers=0
  356. + pcre2_have_libs=0
  357. + if test "$pcre2_base_dir" != "/usr"; then
  358. + TS_ADDTO(CFLAGS, [-I${pcre2_include}])
  359. + TS_ADDTO(CFLAGS, [-DPCRE2_STATIC])
  360. + TS_ADDTO(LDFLAGS, [-L${pcre2_ldflags}])
  361. + TS_ADDTO_RPATH(${pcre2_ldflags})
  362. + fi
  363. + AC_SEARCH_LIBS([pcre2_match_8], [pcre2-8], [pcre2_have_libs=1])
  364. + if test "$pcre2_have_libs" != "0"; then
  365. + AC_MSG_CHECKING([pcre2.h])
  366. + AC_COMPILE_IFELSE(
  367. + [AC_LANG_PROGRAM(
  368. + [[
  369. +#define PCRE2_CODE_UNIT_WIDTH 8
  370. +#include <pcre2.h>
  371. + ]],
  372. + [[
  373. + ]]
  374. + )],
  375. + [pcre2_have_headers=1
  376. + AC_MSG_RESULT([ok])],
  377. + [AC_MSG_RESULT([not found])]
  378. + )
  379. +
  380. + AC_MSG_CHECKING([pcre2/pcre2.h])
  381. + AC_COMPILE_IFELSE(
  382. + [AC_LANG_PROGRAM(
  383. + [[
  384. +#define PCRE2_CODE_UNIT_WIDTH 8
  385. +#include <pcre2/pcre2.h>
  386. + ]],
  387. + [[
  388. + ]]
  389. + )],
  390. + [pcre2_have_headers=1
  391. + AC_MSG_RESULT([ok])],
  392. + [AC_MSG_RESULT([not found])]
  393. + )
  394. + fi
  395. + if test "$pcre2_have_headers" != "0"; then
  396. + AC_DEFINE(HAVE_LIBPCRE2,1,[Compiling with pcre2 support])
  397. + AC_SUBST(LIBPCRE2, [-lpcre2-8])
  398. + else
  399. + enable_pcre2=no
  400. + CFLAGS=$saved_cppflags
  401. + LDFLAGS=$saved_ldflags
  402. + fi
  403. +fi
  404. +AC_SUBST(pcre2h)
  405. +AC_SUBST(pcre2_pcre2h)
  406. +])
  407. --- a/src/rule.c
  408. +++ b/src/rule.c
  409. @@ -1,6 +1,7 @@
  410. /*
  411. * Copyright (c) 2011 and 2012, Dustin Lundquist <[email protected]>
  412. * Copyright (c) 2011 Manuel Kasper <[email protected]>
  413. + * Copyright (c) 2017 Syrone Wong <[email protected]>
  414. * All rights reserved.
  415. *
  416. * Redistribution and use in source and binary forms, with or without
  417. @@ -74,18 +75,37 @@ add_rule(struct cork_dllist *rules, rule
  418. cork_dllist_add(rules, &rule->entries);
  419. }
  420. +/*
  421. + * XXX: As pattern and subject are char arguments, they can be straightforwardly
  422. + * cast to PCRE2_SPTR as we are working in 8-bit code units.
  423. + */
  424. +
  425. int
  426. init_rule(rule_t *rule)
  427. {
  428. if (rule->pattern_re == NULL) {
  429. - const char *reerr;
  430. - int reerroffset;
  431. + int errornumber;
  432. + PCRE2_SIZE erroroffset;
  433. + rule->pattern_re = pcre2_compile(
  434. + (PCRE2_SPTR)rule->pattern, /* the pattern */
  435. + PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
  436. + 0, /* default options */
  437. + &errornumber, /* for error number */
  438. + &erroroffset, /* for error offset */
  439. + NULL); /* use default compile context */
  440. - rule->pattern_re =
  441. - pcre_compile(rule->pattern, 0, &reerr, &reerroffset, NULL);
  442. if (rule->pattern_re == NULL) {
  443. - LOGE("Regex compilation of \"%s\" failed: %s, offset %d",
  444. - rule->pattern, reerr, reerroffset);
  445. + PCRE2_UCHAR errbuffer[512];
  446. + pcre2_get_error_message(errornumber, errbuffer, sizeof(errbuffer));
  447. + LOGE("PCRE2 regex compilation failed at offset %d: %s\n", (int)erroroffset,
  448. + errbuffer);
  449. + return 0;
  450. + }
  451. +
  452. + rule->pattern_re_match_data = pcre2_match_data_create_from_pattern(rule->pattern_re, NULL);
  453. +
  454. + if (rule->pattern_re_match_data == NULL) {
  455. + ERROR("PCRE2: the memory for the block could not be obtained");
  456. return 0;
  457. }
  458. }
  459. @@ -105,8 +125,15 @@ lookup_rule(const struct cork_dllist *ru
  460. cork_dllist_foreach_void(rules, curr, next) {
  461. rule_t *rule = cork_container_of(curr, rule_t, entries);
  462. - if (pcre_exec(rule->pattern_re, NULL,
  463. - name, name_len, 0, 0, NULL, 0) >= 0)
  464. + if (pcre2_match(
  465. + rule->pattern_re, /* the compiled pattern */
  466. + (PCRE2_SPTR)name, /* the subject string */
  467. + name_len, /* the length of the subject */
  468. + 0, /* start at offset 0 in the subject */
  469. + 0, /* default options */
  470. + rule->pattern_re_match_data, /* block for storing the result */
  471. + NULL /* use default match context */
  472. + ) >= 0)
  473. return rule;
  474. }
  475. @@ -127,7 +154,13 @@ free_rule(rule_t *rule)
  476. return;
  477. ss_free(rule->pattern);
  478. - if (rule->pattern_re != NULL)
  479. - pcre_free(rule->pattern_re);
  480. + if (rule->pattern_re != NULL) {
  481. + pcre2_code_free(rule->pattern_re); /* data and the compiled pattern. */
  482. + rule->pattern_re = NULL;
  483. + }
  484. + if (rule->pattern_re_match_data != NULL) {
  485. + pcre2_match_data_free(rule->pattern_re_match_data); /* Release memory used for the match */
  486. + rule->pattern_re_match_data = NULL;
  487. + }
  488. ss_free(rule);
  489. }
  490. --- a/src/rule.h
  491. +++ b/src/rule.h
  492. @@ -1,6 +1,7 @@
  493. /*
  494. * Copyright (c) 2011 and 2012, Dustin Lundquist <[email protected]>
  495. * Copyright (c) 2011 Manuel Kasper <[email protected]>
  496. + * Copyright (c) 2017 Syrone Wong <[email protected]>
  497. * All rights reserved.
  498. *
  499. * Redistribution and use in source and binary forms, with or without
  500. @@ -33,17 +34,27 @@
  501. #include <libcork/ds.h>
  502. -#ifdef HAVE_PCRE_H
  503. -#include <pcre.h>
  504. -#elif HAVE_PCRE_PCRE_H
  505. -#include <pcre/pcre.h>
  506. -#endif
  507. +/*
  508. + * The PCRE2_CODE_UNIT_WIDTH macro must be defined before including pcre2.h.
  509. + * For a program that uses only one code unit width, setting it to 8, 16, or 32
  510. + * makes it possible to use generic function names such as pcre2_compile(). Note
  511. + * that just changing 8 to 16 (for example) is not sufficient to convert this
  512. + * program to process 16-bit characters. Even in a fully 16-bit environment, where
  513. + * string-handling functions such as strcmp() and printf() work with 16-bit
  514. + * characters, the code for handling the table of named substrings will still need
  515. + * to be modified.
  516. + */
  517. +/* we only need to support ASCII chartable, thus set it to 8 */
  518. +#define PCRE2_CODE_UNIT_WIDTH 8
  519. +
  520. +#include <pcre2.h>
  521. typedef struct rule {
  522. char *pattern;
  523. /* Runtime fields */
  524. - pcre *pattern_re;
  525. + pcre2_code *pattern_re;
  526. + pcre2_match_data *pattern_re_match_data;
  527. struct cork_dllist_item entries;
  528. } rule_t;