void owl_global_setup_default_filters(owl_global *g) { int i; static const struct { const char *name; const char *desc; } filters[] = { { "personal", "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message ) )" }, { "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, { "ping", "opcode ^ping$" }, { "auto", "opcode ^auto$" }, { "login", "not login ^none$" }, { "reply-lockout", "class ^mail$" }, { "out", "direction ^out$" }, { "aim", "type ^aim$" }, { "zephyr", "type ^zephyr$" }, { "none", "false" }, { "all", "true" }, { NULL, NULL } }; owl_function_debugmsg("startup: creating default filters"); for (i = 0; filters[i].name != NULL; i++) owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name, filters[i].desc)); }
int owl_filter_regtest(void) { int numfailed=0; owl_message m; owl_filter *f1, *f2, *f3, *f4, *f5; owl_dict_create(&g.filters); g.filterlist = NULL; owl_message_init(&m); owl_message_set_type_zephyr(&m); owl_message_set_direction_in(&m); owl_message_set_class(&m, "owl"); owl_message_set_instance(&m, "tester"); owl_message_set_sender(&m, "owl-user"); owl_message_set_recipient(&m, "joe"); owl_message_set_attribute(&m, "foo", "bar"); #define TEST_FILTER(f, e) do { \ numtests++; \ numfailed += owl_filter_test_string(f, &m, e); \ } while(0) TEST_FILTER("true", 1); TEST_FILTER("false", 0); TEST_FILTER("( true )", 1); TEST_FILTER("not false", 1); TEST_FILTER("( true ) or ( false )", 1); TEST_FILTER("true and false", 0); TEST_FILTER("( true or true ) or ( ( false ) )", 1); TEST_FILTER("class owl", 1); TEST_FILTER("class ^owl$", 1); TEST_FILTER("instance test", 1); TEST_FILTER("instance ^test$", 0); TEST_FILTER("instance ^tester$", 1); TEST_FILTER("foo bar", 1); TEST_FILTER("class owl and instance tester", 1); TEST_FILTER("type ^zephyr$ and direction ^in$ and ( class ^owl$ or instance ^owl$ )", 1); /* Order of operations and precedence */ TEST_FILTER("not true or false", 0); TEST_FILTER("true or true and false", 0); TEST_FILTER("true and true and false or true", 1); TEST_FILTER("false and false or true", 1); TEST_FILTER("true and false or false", 0); f1 = owl_filter_new_fromstring("f1", "class owl"); owl_global_add_filter(&g, f1); TEST_FILTER("filter f1", 1); owl_global_remove_filter(&g, "f1"); /* Test recursion prevention */ FAIL_UNLESS("self reference", (f2 = owl_filter_new_fromstring("test", "filter test")) == NULL); owl_filter_delete(f2); /* mutual recursion */ f3 = owl_filter_new_fromstring("f3", "filter f4"); owl_global_add_filter(&g, f3); FAIL_UNLESS("mutual recursion", (f4 = owl_filter_new_fromstring("f4", "filter f3")) == NULL); owl_global_remove_filter(&g, "f3"); owl_filter_delete(f4); /* support referencing a filter several times */ FAIL_UNLESS("DAG", (f5 = owl_filter_new_fromstring("dag", "filter f1 or filter f1")) != NULL); owl_filter_delete(f5); return 0; }