X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Ffilter.h;h=a5e0f1a5739576bfb99530f52aaa142ee811feff;hb=HEAD;hp=f551e58fa2faea101403f49c3a27d467924cddf9;hpb=ae0c2eb5d2ea501fd9e458fc138696c268a14569;p=apps%2Fpfixtools.git diff --git a/postlicyd/filter.h b/postlicyd/filter.h index f551e58..a5e0f1a 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -16,17 +16,20 @@ /* products derived from this software without specific prior written */ /* permission. */ /* */ -/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */ -/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ -/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ -/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */ -/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ -/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ -/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ -/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ -/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ -/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */ -/* THE POSSIBILITY OF SUCH DAMAGE. */ +/* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS */ +/* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ +/* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY */ +/* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */ +/* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS */ +/* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/* POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/* Copyright (c) 2006-2008 the Authors */ +/* see AUTHORS and source files for details */ /******************************************************************************/ /* @@ -43,6 +46,7 @@ #include "query.h" #include "array.h" + typedef filter_token filter_type_t; typedef hook_token filter_result_t; typedef param_token filter_param_id_t; @@ -51,9 +55,13 @@ typedef struct filter_hook_t { filter_result_t type; char *value; + int counter; + int cost; + unsigned postfix:1; unsigned async:1; int filter_id; + } filter_hook_t; ARRAY(filter_hook_t) @@ -81,13 +89,24 @@ typedef struct filter_t { } filter_t; ARRAY(filter_t) +#define MAX_COUNTERS (64) + /** Context of the query. To be filled with data to use when * performing asynchronous filtering. */ typedef struct filter_context_t { + /* filter context + */ const filter_t *current_filter; void *contexts[FTK_count]; + /* message context + */ + char instance[64]; + uint32_t counters[MAX_COUNTERS]; + + /* connection context + */ void *data; } filter_context_t; @@ -116,6 +135,12 @@ typedef void (*filter_destructor_t)(filter_t *filter); typedef void *(*filter_context_constructor_t)(void); typedef void (*filter_context_destructor_t)(void*); +typedef void (*filter_async_handler_t)(filter_context_t *context, + const filter_hook_t *result); + +/** Number of filter currently running. + */ +extern uint32_t filter_running; /* Registration. */ @@ -132,6 +157,8 @@ filter_result_t filter_hook_register(filter_type_t filter, const char *name); __attribute__((nonnull(2))) filter_param_id_t filter_param_register(filter_type_t filter, const char *name); +__attribute__((nonnull)) +void filter_async_handler_register(filter_async_handler_t handler); /* Filter builder. */ @@ -218,9 +245,9 @@ bool filter_test(const filter_t *filter, const query_t *query, /* Parsing Helpers */ -#define FILTER_PARAM_PARSE_STRING(Param, Dest) \ +#define FILTER_PARAM_PARSE_STRING(Param, Dest, Copy) \ case ATK_ ## Param: { \ - (Dest) = param->value; \ + (Dest) = (Copy) ? m_strdup(param->value) : param->value; \ } break #define FILTER_PARAM_PARSE_INT(Param, Dest) \ @@ -238,16 +265,18 @@ bool filter_test(const filter_t *filter, const query_t *query, } else if (param->value_len == 1 && param->value[0] == '0') { \ (Dest) = false; \ } 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'; \ + && ascii_tolower(param->value[0]) == 't' \ + && ascii_tolower(param->value[1]) == 'r' \ + && ascii_tolower(param->value[2]) == 'u' \ + && ascii_tolower(param->value[3]) == 'e') { \ + (Dest) = true; \ } 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'; \ + && ascii_tolower(param->value[0]) == 'f' \ + && ascii_tolower(param->value[1]) == 'a' \ + && ascii_tolower(param->value[2]) == 'l' \ + && ascii_tolower(param->value[3]) == 's' \ + && ascii_tolower(param->value[4]) == 'e') { \ + (Dest) = false; \ } else { \ PARSE_CHECK(false, "invalid %s value %.*s", atokens[ATK_ ## Param],\ param->value_len, param->value); \ @@ -258,10 +287,16 @@ bool filter_test(const filter_t *filter, const query_t *query, /* Filter context */ -__attribute__((nonnull)) +__attribute__((nonnull(1))) void filter_context_prepare(filter_context_t *context, void* qctx); __attribute__((nonnull)) void filter_context_wipe(filter_context_t *context); +__attribute__((nonnull)) +void filter_context_clean(filter_context_t *context); + +__attribute__((nonnull)) +void filter_post_async_result(filter_context_t *context, filter_result_t result); + #endif