return NULL;
}
-typedef struct DetectParseRegex_ {
- pcre *regex;
- pcre_extra *study;
- struct DetectParseRegex_ *next;
-} DetectParseRegex;
-
static DetectParseRegex *g_detect_parse_regex_list = NULL;
+int DetectParsePcreExecLen(DetectParseRegex *parse_regex, const char *str,
+ int str_len,
+ int start_offset, int options,
+ int *ovector, int ovector_size)
+{
+ return pcre_exec(parse_regex->regex, parse_regex->study, str, str_len,
+ start_offset, options, ovector, ovector_size);
+}
+
+int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str,
+ int start_offset, int options,
+ int *ovector, int ovector_size)
+{
+ return pcre_exec(parse_regex->regex, parse_regex->study, str, strlen(str),
+ start_offset, options, ovector, ovector_size);
+}
+
+void DetectParseFreeRegex(DetectParseRegex *r)
+{
+ if (r->regex) {
+ pcre_free(r->regex);
+ }
+ if (r->study) {
+ pcre_free_study(r->study);
+ }
+}
void DetectParseFreeRegexes(void)
{
while (r) {
DetectParseRegex *next = r->next;
- if (r->regex) {
- pcre_free(r->regex);
- }
- if (r->study) {
- pcre_free_study(r->study);
- }
+ DetectParseFreeRegex(r);
+
SCFree(r);
r = next;
}
/** \brief add regex and/or study to at exit free list
*/
-void DetectParseRegexAddToFreeList(pcre *regex, pcre_extra *study)
+void DetectParseRegexAddToFreeList(DetectParseRegex *detect_parse)
{
DetectParseRegex *r = SCCalloc(1, sizeof(*r));
if (r == NULL) {
FatalError(SC_ERR_MEM_ALLOC, "failed to alloc memory for pcre free list");
}
- r->regex = regex;
- r->study = study;
+ r->regex = detect_parse->regex;
+ r->study = detect_parse->study;
r->next = g_detect_parse_regex_list;
g_detect_parse_regex_list = r;
}
-void DetectSetupParseRegexes(const char *parse_str,
- pcre **parse_regex,
- pcre_extra **parse_regex_study)
+void DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *detect_parse, int opts)
{
const char *eb;
int eo;
- int opts = 0;
- *parse_regex = pcre_compile(parse_str, opts, &eb, &eo, NULL);
- if (*parse_regex == NULL) {
+ detect_parse->regex = pcre_compile(parse_str, opts, &eb, &eo, NULL);
+ if (detect_parse->regex == NULL) {
FatalError(SC_ERR_PCRE_COMPILE, "pcre compile of \"%s\" failed at "
"offset %" PRId32 ": %s", parse_str, eo, eb);
}
- *parse_regex_study = pcre_study(*parse_regex, 0, &eb);
+ detect_parse->study = pcre_study(detect_parse->regex, 0 , &eb);
if (eb != NULL) {
FatalError(SC_ERR_PCRE_STUDY, "pcre study failed: %s", eb);
}
- DetectParseRegexAddToFreeList(*parse_regex, *parse_regex_study);
+
+ DetectParseRegexAddToFreeList(detect_parse);
+
+ return;
+}
+
+void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
+{
+ DetectSetupParseRegexesOpts(parse_str, detect_parse, 0);
return;
}
SIG_DIREC_DST
};
+typedef struct DetectParseRegex_ {
+ pcre *regex;
+ pcre_extra *study;
+#ifdef PCRE_HAVE_JIT_EXEC
+ pcre_jit_stack *jit_stack;
+#endif
+ struct DetectParseRegex_ *next;
+} DetectParseRegex;
+
/* prototypes */
Signature *SigAlloc(void);
void SigFree(Signature *s);
/* parse regex setup and free util funcs */
-void DetectSetupParseRegexes(const char *parse_str,
- pcre **parse_regex,
- pcre_extra **parse_regex_study);
-void DetectParseRegexAddToFreeList(pcre *regex, pcre_extra *study);
+void DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts);
+void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex);
+void DetectParseRegexAddToFreeList(DetectParseRegex *parse_regex);
void DetectParseFreeRegexes(void);
+void DetectParseFreeRegex(DetectParseRegex *r);
+
+/* parse regex exec */
+int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str,
+ int start_offset, int options,
+ int *ovector, int ovector_size);
+int DetectParsePcreExecLen(DetectParseRegex *parse_regex, const char *str,
+ int str_len, int start_offset, int options,
+ int *ovector, int ovector_size);
#ifdef AFLFUZZ_RULES
int RuleParseDataFromFile(char *filename);
#endif
+/* typical size of ovector */
+#define MAX_SUBSTRINGS 30
+
#endif /* __DETECT_PARSE_H__ */