X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Ffilter.h;h=abfb5afcceea0741b80667c349a0df27098b5b93;hb=80564adb8074d47b212e6e1d3172d246ba9444a5;hp=50378683fcf9e6016f18ec59d543063ba237230d;hpb=dd53acce112e59a9ba35e3389c9bad4ea81480ca;p=apps%2Fpfixtools.git diff --git a/postlicyd/filter.h b/postlicyd/filter.h index 5037868..abfb5af 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -56,11 +56,11 @@ typedef struct filter_hook_t { } filter_hook_t; ARRAY(filter_hook_t) -typedef struct filter_params_t { +typedef struct filter_param_t { filter_param_id_t type; char *value; -} filter_params_t; -ARRAY(filter_params_t) +} filter_param_t; +ARRAY(filter_param_t) typedef struct filter_t { char *name; @@ -69,7 +69,7 @@ typedef struct filter_t { A(filter_hook_t) hooks; void *data; - A(filter_params_t) params; + A(filter_param_t) params; } filter_t; ARRAY(filter_t) @@ -154,7 +154,7 @@ static inline void filter_hook_wipe(filter_hook_t *hook) } __attribute__((nonnull(1))) -static inline void filter_params_wipe(filter_params_t *param) +static inline void filter_params_wipe(filter_param_t *param) { p_delete(¶m->value); } @@ -163,7 +163,46 @@ __attribute__((nonnull(1))) void filter_wipe(filter_t *filter); __attribute__((nonnull(1,2))) -filter_result_t filter_run(const filter_t *filter, const query_t *query); +const filter_hook_t *filter_run(const filter_t *filter, const query_t *query); +/* Helpers + */ + +#define FILTER_PARAM_PARSE_STRING(Param, Dest) \ + case ATK_ ## Param: { \ + (Dest) = param->value; \ + } break + +#define FILTER_PARAM_PARSE_INT(Param, Dest) \ + case ATK_ ## Param: { \ + char *next; \ + (Dest) = strtol(param->value, &next, 10); \ + PARSE_CHECK(!*next, "invalid %s value %s", atokens[ATK_ ## Param], \ + param->value); \ + } break + +#define FILTER_PARAM_PARSE_BOOLEAN(Param, Dest) \ + case ATK_ ## Param: { \ + if (param->value[0] == '1' && param->value[1] == '\0') { \ + (Dest) = true; \ + } else if (param->value[0] == '0' && param->value[1] == '\0') { \ + (Dest) = false; \ + } else if (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') { \ + (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]; \ + } else { \ + PARSE_CHECK(false, "invalid %s value %s", atokens[ATK_ ## Param], \ + param->value); \ + } \ + } break + #endif