1/*
2 * Copyright (c) 2015-2016, Intel Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * \file
31 * \brief Data structures and helper functions used to describe the purpose of
32 * a particular NFA engine at build time.
33 */
34
35#ifndef NFA_KIND_H
36#define NFA_KIND_H
37
38#include "ue2common.h"
39
40#include <string>
41
42namespace ue2 {
43
44/** \brief Specify the use-case for an nfa engine. */
45enum nfa_kind {
46 NFA_PREFIX, //!< rose prefix
47 NFA_INFIX, //!< rose infix
48 NFA_SUFFIX, //!< rose suffix
49 NFA_OUTFIX, //!< "outfix" nfa not triggered by external events
50 NFA_OUTFIX_RAW, //!< "outfix", but with unmanaged reports
51 NFA_REV_PREFIX, //! reverse running prefixes (for som)
52 NFA_EAGER_PREFIX, //!< rose prefix that is also run up to matches
53};
54
55/** \brief True if this kind of engine is triggered by a top event. */
56inline
57bool is_triggered(enum nfa_kind k) {
58 switch (k) {
59 case NFA_INFIX:
60 case NFA_SUFFIX:
61 case NFA_REV_PREFIX:
62 return true;
63 default:
64 return false;
65 }
66}
67
68/**
69 * \brief True if this kind of engine generates actively checks for accept
70 * states either to halt matching or to raise a callback. Only these engines
71 * generated with this property should call nfaQueueExec() or
72 * nfaQueueExecToMatch().
73 */
74inline
75bool generates_callbacks(enum nfa_kind k) {
76 switch (k) {
77 case NFA_SUFFIX:
78 case NFA_OUTFIX:
79 case NFA_OUTFIX_RAW:
80 case NFA_REV_PREFIX:
81 case NFA_EAGER_PREFIX:
82 return true;
83 default:
84 return false;
85 }
86}
87
88/**
89 * \brief True if this kind of engine has its state inspected to see if it is in
90 * an accept state. Engines generated with this property will commonly call
91 * nfaQueueExecRose(), nfaInAcceptState(), and nfaInAnyAcceptState().
92 */
93inline
94bool inspects_states_for_accepts(enum nfa_kind k) {
95 switch (k) {
96 case NFA_PREFIX:
97 case NFA_INFIX:
98 case NFA_EAGER_PREFIX:
99 return true;
100 default:
101 return false;
102 }
103}
104
105/**
106 * \brief True if this kind of engine has reports that are managed by the \ref
107 * ReportManager.
108 */
109inline
110bool has_managed_reports(enum nfa_kind k) {
111 switch (k) {
112 case NFA_SUFFIX:
113 case NFA_OUTFIX:
114 return true;
115 default:
116 return false;
117 }
118}
119
120#if defined(DEBUG) || defined(DUMP_SUPPORT)
121
122inline
123std::string to_string(nfa_kind k) {
124 switch (k) {
125 case NFA_PREFIX:
126 return "PREFIX";
127 case NFA_INFIX:
128 return "INFIX";
129 case NFA_SUFFIX:
130 return "SUFFIX";
131 case NFA_OUTFIX:
132 return "OUTFIX";
133 case NFA_REV_PREFIX:
134 return "REV_PREFIX";
135 case NFA_OUTFIX_RAW:
136 return "OUTFIX_RAW";
137 case NFA_EAGER_PREFIX:
138 return "EAGER_PREFIX";
139 }
140 assert(0);
141 return "?";
142}
143
144#endif
145
146} // namespace ue2
147
148#endif
149