filter_token tok = filter_tokenize(type, m_strlen(type));
CHECK_FILTER(tok);
- syslog(LOG_DEBUG, "filter type %s registered", type);
-
runners[tok] = runner;
constructors[tok] = constructor;
destructors[tok] = destructor;
CHECK_FILTER(filter);
CHECK_HOOK(tok);
- syslog(LOG_DEBUG, "hook %s registered for filter type %s", name,
- ftokens[filter]);
-
hooks[filter][tok] = true;
return tok;
}
CHECK_FILTER(filter);
CHECK_PARAM(tok);
- syslog(LOG_INFO, "param %s registered for filter type %s", name,
- ftokens[filter]);
-
params[filter][tok] = true;
return tok;
}
return true;
}
-static inline bool filter_check_loop(filter_t *filter, A(filter_t) *array, bool cleanup)
+static inline bool filter_check_loop(filter_t *filter, A(filter_t) *array, int level)
{
- if (cleanup) {
- foreach (filter_t *filter2, *array) {
- filter2->seen = false;
- }}
- } else if (filter->seen) {
- return false;
- }
- if (filter->safe) {
+ if (filter->last_seen == level) {
return true;
}
- filter->seen = true;
+ filter->last_seen = level;
foreach (filter_hook_t *hook, filter->hooks) {
if (hook->postfix) {
continue;
}
- if (!filter_check_loop(array_ptr(*array, hook->filter_id), array, false)) {
+ if (hook->filter_id == level) {
+ return false;
+ }
+ if (!filter_check_loop(array_ptr(*array, hook->filter_id), array, level)) {
return false;
}
}}
- filter->safe = true;
return true;
}
bool filter_check_safety(A(filter_t) *array)
{
foreach (filter_t *filter, *array) {
- if (!filter_check_loop(filter, array, true)) {
+ if (!filter_check_loop(filter, array, __Ai)) {
syslog(LOG_ERR, "the filter tree contains a loop");
return false;
}
A(filter_param_t) params;
- /* Internal: to check the filter tree structure.
+ /* Loop checking flags.
*/
- unsigned safe :1;
- unsigned seen :1;
+ int last_seen;
} filter_t;
ARRAY(filter_t)
-#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT, false, false }
+#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT, -1 }
#define CHECK_FILTER(Filter) \
assert(Filter != FTK_UNKNOWN && Filter != FTK_count \
&& "Unknown filter type")