mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
nfaCheckFinalState: define return value
Make nfaCheckFinalState return MO_HALT_MATCHING when the user instructs us (via the callback return value) to halt matching. In the caller, check this value and stop matching if told.
This commit is contained in:
parent
843ca0e7cc
commit
621dfbebb7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Intel Corporation
|
* Copyright (c) 2015-2016, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -1049,15 +1049,16 @@ char nfaExecGough16_inAccept(const struct NFA *n, ReportID report,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void goughCheckEOD(const struct NFA *nfa, u16 s,
|
char goughCheckEOD(const struct NFA *nfa, u16 s,
|
||||||
const struct gough_som_info *som,
|
const struct gough_som_info *som,
|
||||||
u64a offset, SomNfaCallback cb, void *ctxt) {
|
u64a offset, SomNfaCallback cb, void *ctxt) {
|
||||||
const struct mcclellan *m = (const struct mcclellan *)getImplNfa(nfa);
|
const struct mcclellan *m = (const struct mcclellan *)getImplNfa(nfa);
|
||||||
const struct mstate_aux *aux = get_aux(m, s);
|
const struct mstate_aux *aux = get_aux(m, s);
|
||||||
|
|
||||||
if (aux->accept_eod) {
|
if (!aux->accept_eod) {
|
||||||
doReports(cb, ctxt, m, som, s, offset, 1, NULL, NULL, NULL);
|
return MO_CONTINUE_MATCHING;
|
||||||
}
|
}
|
||||||
|
return doReports(cb, ctxt, m, som, s, offset, 1, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char nfaExecGough8_testEOD(const struct NFA *nfa, const char *state,
|
char nfaExecGough8_testEOD(const struct NFA *nfa, const char *state,
|
||||||
@ -1065,8 +1066,8 @@ char nfaExecGough8_testEOD(const struct NFA *nfa, const char *state,
|
|||||||
UNUSED NfaCallback callback,
|
UNUSED NfaCallback callback,
|
||||||
SomNfaCallback som_callback, void *context) {
|
SomNfaCallback som_callback, void *context) {
|
||||||
const struct gough_som_info *som = getSomInfoConst(state);
|
const struct gough_som_info *som = getSomInfoConst(state);
|
||||||
goughCheckEOD(nfa, *(const u8 *)state, som, offset, som_callback, context);
|
return goughCheckEOD(nfa, *(const u8 *)state, som, offset, som_callback,
|
||||||
return 0;
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
char nfaExecGough16_testEOD(const struct NFA *nfa, const char *state,
|
char nfaExecGough16_testEOD(const struct NFA *nfa, const char *state,
|
||||||
@ -1075,8 +1076,8 @@ char nfaExecGough16_testEOD(const struct NFA *nfa, const char *state,
|
|||||||
SomNfaCallback som_callback, void *context) {
|
SomNfaCallback som_callback, void *context) {
|
||||||
assert(ISALIGNED_N(state, 8));
|
assert(ISALIGNED_N(state, 8));
|
||||||
const struct gough_som_info *som = getSomInfoConst(state);
|
const struct gough_som_info *som = getSomInfoConst(state);
|
||||||
goughCheckEOD(nfa, *(const u16 *)state, som, offset, som_callback, context);
|
return goughCheckEOD(nfa, *(const u16 *)state, som, offset, som_callback,
|
||||||
return 0;
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
char nfaExecGough8_queueInitState(UNUSED const struct NFA *nfa, struct mq *q) {
|
char nfaExecGough8_queueInitState(UNUSED const struct NFA *nfa, struct mq *q) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Intel Corporation
|
* Copyright (c) 2015-2016, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -445,14 +445,15 @@ char mcclellanExec8_i_ni(const struct mcclellan *m, u8 *state, const u8 *buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static really_inline
|
static really_inline
|
||||||
void mcclellanCheckEOD(const struct NFA *nfa, u16 s, u64a offset,
|
char mcclellanCheckEOD(const struct NFA *nfa, u16 s, u64a offset,
|
||||||
NfaCallback cb, void *ctxt) {
|
NfaCallback cb, void *ctxt) {
|
||||||
const struct mcclellan *m = getImplNfa(nfa);
|
const struct mcclellan *m = getImplNfa(nfa);
|
||||||
const struct mstate_aux *aux = get_aux(m, s);
|
const struct mstate_aux *aux = get_aux(m, s);
|
||||||
|
|
||||||
if (aux->accept_eod) {
|
if (!aux->accept_eod) {
|
||||||
doComplexReport(cb, ctxt, m, s, offset, 1, NULL, NULL);
|
return MO_CONTINUE_MATCHING;
|
||||||
}
|
}
|
||||||
|
return doComplexReport(cb, ctxt, m, s, offset, 1, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static really_inline
|
static really_inline
|
||||||
@ -1053,8 +1054,8 @@ char nfaExecMcClellan8_testEOD(const struct NFA *nfa, const char *state,
|
|||||||
UNUSED const char *streamState,
|
UNUSED const char *streamState,
|
||||||
u64a offset, NfaCallback callback,
|
u64a offset, NfaCallback callback,
|
||||||
UNUSED SomNfaCallback som_cb, void *context) {
|
UNUSED SomNfaCallback som_cb, void *context) {
|
||||||
mcclellanCheckEOD(nfa, *(const u8 *)state, offset, callback, context);
|
return mcclellanCheckEOD(nfa, *(const u8 *)state, offset, callback,
|
||||||
return 0;
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
char nfaExecMcClellan16_testEOD(const struct NFA *nfa, const char *state,
|
char nfaExecMcClellan16_testEOD(const struct NFA *nfa, const char *state,
|
||||||
@ -1062,8 +1063,8 @@ char nfaExecMcClellan16_testEOD(const struct NFA *nfa, const char *state,
|
|||||||
u64a offset, NfaCallback callback,
|
u64a offset, NfaCallback callback,
|
||||||
UNUSED SomNfaCallback som_cb, void *context) {
|
UNUSED SomNfaCallback som_cb, void *context) {
|
||||||
assert(ISALIGNED_N(state, 2));
|
assert(ISALIGNED_N(state, 2));
|
||||||
mcclellanCheckEOD(nfa, *(const u16 *)state, offset, callback, context);
|
return mcclellanCheckEOD(nfa, *(const u16 *)state, offset, callback,
|
||||||
return 0;
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
char nfaExecMcClellan8_queueInitState(UNUSED const struct NFA *nfa, struct mq *q) {
|
char nfaExecMcClellan8_queueInitState(UNUSED const struct NFA *nfa, struct mq *q) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Intel Corporation
|
* Copyright (c) 2015-2016, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -236,6 +236,9 @@ char nfaBlockExecReverse(const struct NFA *nfa, u64a offset, const u8 *buf,
|
|||||||
* @param callback the callback to call for each match raised
|
* @param callback the callback to call for each match raised
|
||||||
* @param som_cb the callback to call for each match raised (Haig)
|
* @param som_cb the callback to call for each match raised (Haig)
|
||||||
* @param context context pointer passed to each callback
|
* @param context context pointer passed to each callback
|
||||||
|
*
|
||||||
|
* @return @ref MO_HALT_MATCHING if the user instructed us to halt, otherwise
|
||||||
|
* @ref MO_CONTINUE_MATCHING.
|
||||||
*/
|
*/
|
||||||
char nfaCheckFinalState(const struct NFA *nfa, const char *state,
|
char nfaCheckFinalState(const struct NFA *nfa, const char *state,
|
||||||
const char *streamState, u64a offset,
|
const char *streamState, u64a offset,
|
||||||
|
@ -168,8 +168,12 @@ void roseCheckNfaEod(const struct RoseEngine *t, char *state,
|
|||||||
nfaExpandState(nfa, fstate, sstate, offset, key);
|
nfaExpandState(nfa, fstate, sstate, offset, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
|
if (nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
|
||||||
scratch->tctxt.cb_som, scratch->tctxt.userCtx);
|
scratch->tctxt.cb_som,
|
||||||
|
scratch->tctxt.userCtx) == MO_HALT_MATCHING) {
|
||||||
|
DEBUG_PRINTF("user instructed us to stop\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,8 +217,13 @@ void roseCheckEodSuffixes(const struct RoseEngine *t, char *state, u64a offset,
|
|||||||
* history buffer. */
|
* history buffer. */
|
||||||
char rv = nfaQueueExecRose(q->nfa, q, MO_INVALID_IDX);
|
char rv = nfaQueueExecRose(q->nfa, q, MO_INVALID_IDX);
|
||||||
if (rv) { /* nfa is still alive */
|
if (rv) { /* nfa is still alive */
|
||||||
nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
|
if (nfaCheckFinalState(nfa, fstate, sstate, offset,
|
||||||
scratch->tctxt.cb_som, scratch->tctxt.userCtx);
|
scratch->tctxt.cb, scratch->tctxt.cb_som,
|
||||||
|
scratch->tctxt.userCtx) ==
|
||||||
|
MO_HALT_MATCHING) {
|
||||||
|
DEBUG_PRINTF("user instructed us to stop\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user