Changeset 588 for trunk/src/sh_log_evalrule.c
- Timestamp:
- Oct 26, 2025, 12:17:47 PM (16 hours ago)
- File:
-
- 1 edited
-
trunk/src/sh_log_evalrule.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_log_evalrule.c
r541 r588 15 15 #define FIL__ _("sh_log_evalrule.c") 16 16 17 /* Debian/Ubuntu: libpcre3-dev */ 18 #ifdef HAVE_PCRE_PCRE_H 19 #include <pcre/pcre.h> 17 /* Debian/Ubuntu: libpcre2-dev */ 18 #define PCRE2_CODE_UNIT_WIDTH 8 19 #ifdef HAVE_PCRE2_PCRE2_H 20 #include <pcre2/pcre2.h> 20 21 #else 21 #include <pcre .h>22 #include <pcre2.h> 22 23 #endif 23 24 24 #ifndef PCRE _NO_AUTO_CAPTURE25 #define PCRE _NO_AUTO_CAPTURE 025 #ifndef PCRE2_NO_AUTO_CAPTURE 26 #define PCRE2_NO_AUTO_CAPTURE 0 26 27 #endif 27 28 … … 95 96 struct sh_geval /* Group of rules (may be a single rule) */ 96 97 { 97 sh_string * label; /* label for this group */98 pcre * rule; /* compiled regex for rule */99 pcre_extra * rule_extra; 100 int * ovector;/* captured substrings */101 int ovecnum; /* how many captured */102 int captures; /* (captures+1)*3 required */103 int flags; /* bit flags */104 unsigned long delay; /* delay for keep rules */105 zAVLTree * counterlist; /* counters if EVAL_SUM */106 struct sh_qeval * queue; /* queue for this rule */107 struct sh_geval * nextrule; /* next rule in this group */108 struct sh_geval * next; /* next group of rules */109 struct sh_geval * gnext; /* grouplist next */98 sh_string * label; /* label for this group */ 99 pcre2_code * rule; /* compiled regex for rule */ 100 101 pcre2_match_data * match_data; /* captured substrings */ 102 int ovecnum; /* how many captured */ 103 int captures; /* (captures+1)*3 required */ 104 int flags; /* bit flags */ 105 unsigned long delay; /* delay for keep rules */ 106 zAVLTree * counterlist; /* counters if EVAL_SUM */ 107 struct sh_qeval * queue; /* queue for this rule */ 108 struct sh_geval * nextrule; /* next rule in this group */ 109 struct sh_geval * next; /* next group of rules */ 110 struct sh_geval * gnext; /* grouplist next */ 110 111 }; 111 112 112 113 struct sh_heval /* host-specific rules */ 113 114 { 114 pcre * hostname; /* compiled regex for hostname */ 115 pcre_extra * hostname_extra; 115 pcre2_code * hostname; /* compiled regex for hostname */ 116 116 struct sh_geval * rulegroups; /* list of group of rules */ 117 117 struct sh_heval * next; … … 142 142 struct sh_geval * ng; 143 143 struct sh_geval * tmp; 144 pcre *group;145 pcre_extra * group_extra; 146 const char *error;147 interroffset;144 pcre2_code * group; 145 146 int error; 147 PCRE2_SIZE erroffset; 148 148 unsigned int nfields = 2; 149 149 size_t lengths[2]; 150 150 151 char * new = sh_util_strdup(str); 151 152 char ** splits = split_array(new, &nfields, ':', lengths); … … 164 165 } 165 166 166 group = pcre _compile(splits[1], PCRE_NO_AUTO_CAPTURE,167 group = pcre2_compile((PCRE2_SPTR8)splits[1], lengths[1], PCRE2_NO_AUTO_CAPTURE, 167 168 &error, &erroffset, NULL); 168 169 if (!group) … … 183 184 return -1; 184 185 } 185 group_extra = NULL; /* pcre_study(group, 0, &error); */186 186 187 187 ng = SH_ALLOC(sizeof(struct sh_geval)); … … 192 192 193 193 ng->rule = group; 194 ng->rule_extra = group_extra; 195 ng-> ovector = NULL;194 195 ng->match_data = pcre2_match_data_create_from_pattern(group, NULL); 196 196 ng->ovecnum = 0; 197 197 ng->captures = 0; … … 206 206 if (0 != sh_eval_hadd("^.*")) 207 207 { 208 pcre_free(group); 208 pcre2_code_free(group); 209 pcre2_match_data_free(ng->match_data); 209 210 sh_string_destroy(&(ng->label)); 210 211 SH_FREE(splits); … … 266 267 struct sh_heval * nh; 267 268 struct sh_heval * tmp; 268 pcre * host;269 pcre_extra * host_extra; 270 const char *error;271 interroffset;269 pcre2_code * host; 270 271 int error; 272 PCRE2_SIZE erroffset; 272 273 273 274 if (host_open) 274 275 host_open = NULL; 275 276 276 host = pcre _compile(str, PCRE_NO_AUTO_CAPTURE,277 &error, &erroffset, NULL);277 host = pcre2_compile((PCRE2_SPTR8)str, PCRE2_ZERO_TERMINATED, PCRE2_NO_AUTO_CAPTURE, 278 &error, &erroffset, NULL); 278 279 if (!host) 279 280 { … … 291 292 return -1; 292 293 } 293 host_extra = NULL; /* pcre_study(host, 0, &error); */294 294 295 295 nh = SH_ALLOC(sizeof(struct sh_heval)); … … 297 297 298 298 nh->hostname = host; 299 nh->hostname_extra = host_extra;300 299 nh->rulegroups = NULL; 301 300 … … 478 477 struct sh_geval * tmp; 479 478 struct sh_qeval * queue; 480 pcre * rule;481 pcre_extra * rule_extra; 482 const char *error;483 interroffset;484 intcaptures = 0;479 pcre2_code * rule; 480 481 int error; 482 PCRE2_SIZE erroffset; 483 unsigned int captures = 0; 485 484 unsigned int nfields = 2; /* queue:regex */ 486 485 size_t lengths[3]; … … 576 575 } 577 576 578 rule = pcre _compile(splits[rpos], 0,579 &error, &erroffset, NULL);577 rule = pcre2_compile((PCRE2_SPTR8)splits[rpos], lengths[rpos], 0, 578 &error, &erroffset, NULL); 580 579 if (!rule) 581 580 { … … 595 594 return -1; 596 595 } 597 rule_extra = NULL; /* pcre_study(rule, 0, &error); */ 598 pcre _fullinfo(rule, rule_extra, PCRE_INFO_CAPTURECOUNT, &captures);596 597 pcre2_pattern_info(rule, PCRE2_INFO_CAPTURECOUNT, &captures); 599 598 600 599 if (flag_err_debug == S_TRUE) … … 602 601 char * emsg = SH_ALLOC(SH_ERRBUF_SIZE); 603 602 if (dstr) 604 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Adding rule: |%s| with % dcaptures, keep(%lu,%s)"),603 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Adding rule: |%s| with %u captures, keep(%lu,%s)"), 605 604 splits[rpos], captures, dsec, dstr); 606 605 else 607 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Adding rule: |%s| with % dcaptures"),606 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Adding rule: |%s| with %u captures"), 608 607 splits[rpos], captures); 609 608 SH_MUTEX_LOCK(mutex_thread_nolog); … … 614 613 } 615 614 616 DEBUG("adding rule: |%s| with % dcaptures\n", splits[rpos], captures);615 DEBUG("adding rule: |%s| with %u captures\n", splits[rpos], captures); 617 616 618 617 SH_FREE(splits); … … 627 626 628 627 nr->rule = rule; 629 nr->rule_extra = rule_extra; 628 630 629 nr->captures = captures; 631 nr-> ovector = SH_ALLOC(sizeof(int) * (captures+1) * 3);630 nr->match_data = pcre2_match_data_create_from_pattern(rule, NULL); 632 631 nr->ovecnum = 0; 633 632 nr->counterlist = NULL; … … 695 694 if (nr->label) 696 695 sh_string_destroy(&(nr->label)); 697 SH_FREE(nr->ovector); 696 if (nr->rule) 697 pcre2_code_free(nr->rule); 698 if (nr->match_data) 699 pcre2_match_data_free(nr->match_data); 698 700 SH_FREE(nr); 699 701 return -1; … … 743 745 if (nr->label) 744 746 sh_string_destroy(&(nr->label)); 745 SH_FREE(nr->ovector); 747 if (nr->rule) 748 pcre2_code_free(nr->rule); 749 if (nr->match_data) 750 pcre2_match_data_free(nr->match_data); 746 751 SH_FREE(nr); 747 752 return -1; … … 763 768 grouplist = gtmp->gnext; 764 769 765 if (gtmp->label) sh_string_destroy(&(gtmp->label)); 766 if (gtmp->rule_extra) (*pcre_free)(gtmp->rule_extra); 767 if (gtmp->rule) (*pcre_free)(gtmp->rule); 770 if (gtmp->label) 771 sh_string_destroy(&(gtmp->label)); 772 if (gtmp->rule) 773 pcre2_code_free(gtmp->rule); 774 if (gtmp->match_data) 775 pcre2_match_data_free(gtmp->match_data); 768 776 if (gtmp->counterlist) 769 777 zAVLFreeTree(gtmp->counterlist, sh_ceval_free); 770 if (gtmp->ovector) 771 SH_FREE(gtmp->ovector); 778 772 779 #if 0 773 780 while (gtmp->nextrule) … … 776 783 gtmp->nextrule = tmp->nextrule; 777 784 778 if (tmp->rule _extra) (*pcre_free)(tmp->rule_extra);779 if (tmp->rule) (*pcre_free)(tmp->rule);785 if (tmp->rule) 786 pcre2_code_free(tmp->rule); 780 787 if (tmp->counterlist) 781 788 zAVLFreeTree(tmp->counterlist, sh_ceval_free); … … 800 807 while (htmp) 801 808 { 802 if (htmp->hostname_extra) (*pcre_free)(htmp->hostname_extra); 803 if (htmp->hostname) (*pcre_free)(htmp->hostname); 804 if (htmp->rulegroups) htmp->rulegroups = NULL; 809 if (htmp->hostname) 810 pcre2_code_free(htmp->hostname); 811 if (htmp->rulegroups) 812 htmp->rulegroups = NULL; 805 813 hostlist = htmp->next; 806 814 htmp->next = NULL; … … 862 870 863 871 DEBUG("debug: check rule %d for <%s>\n", count, msg->str); 864 res = pcre_exec(rule->rule, rule->rule_extra, 865 sh_string_str(msg), (int)sh_string_len(msg), 0, 866 0, rule->ovector, (3*(1+rule->captures))); 867 if (res >= 0) 872 873 res = pcre2_match(rule->rule, 874 (PCRE2_SPTR8)sh_string_str(msg), (int)sh_string_len(msg), 0, 875 0, rule->match_data, NULL); 876 877 if (res > 0) 868 878 { 869 rule->ovecnum = res;879 rule->ovecnum = pcre2_get_ovector_count(rule->match_data); 870 880 871 881 if (flag_err_debug == S_TRUE) … … 965 975 966 976 DEBUG("debug: if group->label %s\n", sh_string_str(group->label)); 967 if (pcre_exec(group->rule, group->rule_extra, 968 sh_string_str(msg), (int) sh_string_len(msg), 969 0, 0, NULL, 0) >= 0) 977 978 if (pcre2_match(group->rule, 979 (PCRE2_SPTR8)sh_string_str(msg), (int) sh_string_len(msg), 0, 980 0, NULL, NULL) > 0) 970 981 { 971 982 result = test_rule(group->nextrule, msg, timestamp); … … 1017 1028 { 1018 1029 do { 1019 if (pcre _exec(hlist->hostname, hlist->hostname_extra,1020 sh_string_str(host), (int) sh_string_len(host),1021 0, 0, NULL, 0) >=0)1030 if (pcre2_match(hlist->hostname, 1031 (PCRE2_SPTR8)sh_string_str(host), (int) sh_string_len(host), 0, 1032 0, NULL, NULL) > 0) 1022 1033 { 1023 1034 /* matching host, check rules/groups of rules */ … … 1035 1046 */ 1036 1047 static sh_string * replace_captures(const sh_string * message, 1037 int * ovector, int ovecnum)1048 size_t * ovector, int ovecnum) 1038 1049 { 1039 1050 sh_string * retval = sh_string_new_from_lchar(sh_string_str(message), … … 1058 1069 SH_MUTEX_LOCK(mutex_thread_nolog); 1059 1070 if (rule) { 1060 mmm = replace_captures(record->message, rule->ovector,1071 mmm = replace_captures(record->message, pcre2_get_ovector_pointer(rule->match_data), 1061 1072 rule->ovecnum); 1062 1073 rule->ovecnum = 0; … … 1170 1181 if (!(counter->counted_str)) 1171 1182 { 1172 counter->counted_str = replace_captures(record->message, rule->ovector,1183 counter->counted_str = replace_captures(record->message, pcre2_get_ovector_pointer(rule->match_data), 1173 1184 rule->ovecnum); 1174 1185 rule->ovecnum = 0;
Note:
See TracChangeset
for help on using the changeset viewer.