X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Ffilter.h;h=3047803e2492d99dc508cb369542a4ae8700a8d7;hb=59b8220d0227fe68537a563b3e5fa2e63e26bc0d;hp=e8319d3b73b74322fb4932a291b231b38c8c2ded;hpb=4e8709f2fc6338d2774c24c9c353deca1990f600;p=apps%2Fpfixtools.git diff --git a/postlicyd/filter.h b/postlicyd/filter.h index e8319d3..3047803 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -58,7 +58,8 @@ ARRAY(filter_hook_t) typedef struct filter_param_t { filter_param_id_t type; - char *value; + char *value; + int value_len; } filter_param_t; ARRAY(filter_param_t) @@ -71,14 +72,13 @@ typedef struct filter_t { 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") @@ -112,24 +112,24 @@ static inline void filter_init(filter_t *filter) } __attribute__((nonnull(1,2))) -void filter_set_name(filter_t *filter, const char *name, ssize_t len); +void filter_set_name(filter_t *filter, const char *name, int len); __attribute__((nonnull(1,2))) -bool filter_set_type(filter_t *filter, const char *type, ssize_t len); +bool filter_set_type(filter_t *filter, const char *type, int len); __attribute__((nonnull(1,2,4))) -bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len); +bool filter_add_param(filter_t *filter, const char *name, int name_len, + const char *value, int value_len); __attribute__((nonnull(1,2,4))) -bool filter_add_hook(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len); +bool filter_add_hook(filter_t *filter, const char *name, int name_len, + const char *value, int value_len); __attribute__((nonnull(1))) bool filter_build(filter_t *filter); __attribute__((nonnull(1,2))) -static inline int filter_find_with_name(A(filter_t) *array, const char *name) +static inline int filter_find_with_name(const A(filter_t) *array, const char *name) { int start = 0; int end = array->len; @@ -173,6 +173,9 @@ void filter_wipe(filter_t *filter); __attribute__((nonnull(1,2))) const filter_hook_t *filter_run(const filter_t *filter, const query_t *query); +__attribute__((nonnull(1,2))) +bool filter_test(const filter_t *filter, const query_t *query, filter_result_t expt); + /* Helpers */ @@ -186,30 +189,30 @@ const filter_hook_t *filter_run(const filter_t *filter, const query_t *query); case ATK_ ## Param: { \ char *next; \ (Dest) = strtol(param->value, &next, 10); \ - PARSE_CHECK(!*next, "invalid %s value %s", atokens[ATK_ ## Param], \ - param->value); \ + PARSE_CHECK(!*next, "invalid %s value %.*s", atokens[ATK_ ## Param], \ + param->value_len, param->value); \ } break #define FILTER_PARAM_PARSE_BOOLEAN(Param, Dest) \ case ATK_ ## Param: { \ - if (param->value[0] == '1' && param->value[1] == '\0') { \ + if (param->value_len == 1 && param->value[0] == '1') { \ (Dest) = true; \ - } else if (param->value[0] == '0' && param->value[1] == '\0') { \ + } else if (param->value_len == 1 && param->value[0] == '0') { \ (Dest) = false; \ - } else if (ascii_tolower(param->value[0]) == 't') { \ + } else if (param->value_len == 4 \ + && ascii_tolower(param->value[0]) == 't') { \ (Dest) = ascii_tolower(param->value[1]) == 'r' \ && ascii_tolower(param->value[2]) == 'u' \ - && ascii_tolower(param->value[3]) == 'e' \ - && !param->value[4]; \ - } else if (ascii_tolower(param->value[0]) == 'f') { \ + && ascii_tolower(param->value[3]) == 'e'; \ + } else if (param->value_len == 5 \ + && ascii_tolower(param->value[0]) == 'f') { \ (Dest) = ascii_tolower(param->value[1]) == 'a' \ && ascii_tolower(param->value[2]) == 'l' \ && ascii_tolower(param->value[3]) == 's' \ - && ascii_tolower(param->value[4]) == 'e' \ - && !param->value[5]; \ + && ascii_tolower(param->value[4]) == 'e'; \ } else { \ - PARSE_CHECK(false, "invalid %s value %s", atokens[ATK_ ## Param], \ - param->value); \ + PARSE_CHECK(false, "invalid %s value %.*s", atokens[ATK_ ## Param],\ + param->value_len, param->value); \ } \ } break