return true;
}
+static inline bool filter_check_loop(filter_t *filter, A(filter_t) *array, bool cleanup)
+{
+ if (cleanup) {
+ foreach (filter_t *filter2, *array) {
+ filter2->seen = false;
+ }}
+ } else if (filter->seen) {
+ return false;
+ }
+ if (filter->safe) {
+ return true;
+ }
+ filter->seen = true;
+ foreach (filter_hook_t *hook, filter->hooks) {
+ if (hook->postfix) {
+ continue;
+ }
+ if (!filter_check_loop(array_ptr(*array, hook->filter_id), array, false)) {
+ 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)) {
+ syslog(LOG_ERR, "the filter tree contains a loop");
+ return false;
+ }
+ }}
+ return true;
+}
+
void filter_wipe(filter_t *filter)
{
filter_destructor_t destructor = destructors[filter->type];
void *data;
A(filter_param_t) params;
+
+ /* Internal: to check the filter tree structure.
+ */
+ unsigned safe :1;
+ unsigned seen :1;
} filter_t;
ARRAY(filter_t)
-#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT }
+#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT, false, false }
#define CHECK_FILTER(Filter) \
assert(Filter != FTK_UNKNOWN && Filter != FTK_count \
&& "Unknown filter type")
__attribute__((nonnull(1,2)))
bool filter_update_references(filter_t *filter, A(filter_t) *array);
+__attribute__((nonnull(1)))
+bool filter_check_safety(A(filter_t) *array);
+
__attribute__((nonnull(1)))
static inline void filter_hook_wipe(filter_hook_t *hook)
{