From: Florent Bruneau Date: Tue, 14 Oct 2008 22:28:35 +0000 (+0200) Subject: Merge commit 'pan/master' into not-linux X-Git-Url: http://git.madism.org/?a=commitdiff_plain;ds=sidebyside;h=785558696ffa16453be0b5b565c46b6426126d1e;p=apps%2Fpfixtools.git Merge commit 'pan/master' into not-linux Conflicts: postlicyd/filter.c postlicyd/main-postlicyd.c Signed-off-by: Florent Bruneau --- 785558696ffa16453be0b5b565c46b6426126d1e diff --cc mk/common.mk index ace4e89,12e943b..4e4be6f --- a/mk/common.mk +++ b/mk/common.mk @@@ -49,8 -49,8 +49,8 @@@ $(LIBS:=.a): $$(patsubst %.c,.%.o,$$($$ $(RM) $@ $(AR) rcs $@ $(filter %.o,$^) --$(PROGRAMS) $(TESTS): $$(patsubst %.c,.%.o,$$($$@_SOURCES)) Makefile ../common.ld - $(CC) -o $@ $(filter %.ld,$^) $(filter %.o,$^) $(LDFLAGS) $($@_LIBADD) $(filter %.a,$^) ++$(PROGRAMS) $(TESTS): $$(patsubst %.c,.%.o,$$($$@_SOURCES)) Makefile + $(CC) -o $@ $(filter %.o,$^) $(LDFLAGS) $($@_LIBADD) $(filter %.a,$^) -include $(foreach p,$(PROGRAMS) $(TESTS),$(patsubst %.c,.%.dep,$(filter %.c,$($p_SOURCES)))) diff --cc postlicyd/Makefile index 81d2ac2,659588a..64c7433 --- a/postlicyd/Makefile +++ b/postlicyd/Makefile @@@ -40,10 -40,10 +40,10 @@@ TESTS = tst-rbl tst-filters tst-gre UB_LIBS = -lunbound - FILTERS = iplist.c greylist.c strlist.c match.c + FILTERS = iplist.c greylist.c strlist.c match.c counters.c postlicyd_SOURCES = main-postlicyd.c ../common/lib.a filter.c config.c query.c $(FILTERS) $(GENERATED) -postlicyd_LIBADD = $(UB_LIBS) $(TC_LIBS) +postlicyd_LIBADD = $(UB_LIBS) $(TC_LIBS) -lev tst-rbl_SOURCES = tst-rbl.c ../common/lib.a filter.c config.c query.c iplist.c $(GENERATED) diff --cc postlicyd/filter.c index 6d98d26,14bfc9b..e108b25 --- a/postlicyd/filter.c +++ b/postlicyd/filter.c @@@ -277,6 -281,6 +281,7 @@@ bool filter_add_hook(filter_t *filter, const char *value, int value_len) { filter_hook_t hook; ++ hook.filter_id = -1; hook.type = hook_tokenize(name, name_len); if (hook.type == HTK_UNKNOWN) { err("unknown hook type %.*s", name_len, name); @@@ -287,9 -291,36 +292,37 @@@ htokens[hook.type], ftokens[filter->type]); return false; } - hook.async = false; - hook.filter_id = -1; - hook.value = NULL; + hook.async = false; + + /* Value format is (counter:id:incr)?(postfix:reply|filter_name) + */ ++ hook.value = NULL; + if (strncmp(value, "counter:", 8) == 0) { + char *end = NULL; + value += 8; + hook.counter = strtol(value, &end, 10); + if (end == value || *end != ':') { + err("hook %s, cannot read counter id", htokens[hook.type]); + return false; + } else if (hook.counter < 0 || hook.counter >= MAX_COUNTERS) { + err("hook %s, invalid counter id %d", htokens[hook.type], hook.counter); + return false; + } + value = end + 1; + hook.cost = strtol(value, &end, 10); + if (end == value || *end != ':') { + err("hook %s, cannot read counter increment", htokens[hook.type]); + return false; + } else if (hook.cost < 0) { + err("hook %s, invalid counter increment value %d", htokens[hook.type], + hook.cost); + return false; + } + value = end + 1; + } else { + hook.counter = -1; + hook.cost = 0; + } hook.postfix = (strncmp(value, "postfix:", 8) == 0); if (hook.postfix && query_format(NULL, 0, value + 8, NULL) == -1) { err("invalid formatted text \"%s\"", value + 8); diff --cc postlicyd/main-postlicyd.c index 9fc0368,bf68941..9baf34a --- a/postlicyd/main-postlicyd.c +++ b/postlicyd/main-postlicyd.c @@@ -211,7 -216,11 +222,11 @@@ static int policy_run(server_t *pcy, vo if (!query_parse(pcy->data, pcy->ibuf.data)) return -1; query->eoq = eoq + strlen("\n\n"); + if (query->instance == NULL || strcmp(context->context.instance, query->instance) != 0) { + filter_context_clean(&context->context); + m_strcat(context->context.instance, 64, query->instance); + } - epoll_modify(pcy->fd, 0, pcy); + server_none(pcy); return policy_process(pcy, mconfig) ? 0 : -1; }