diff --git a/server/include/hooks.h b/server/include/hooks.h index 89ad082d8..0203663cc 100644 --- a/server/include/hooks.h +++ b/server/include/hooks.h @@ -64,15 +64,6 @@ struct hook { */ const struct hook * hook_lookup(const char *name); -/** Conditionally execute the hooks - * - * @param p A pointer to the path structure. - * @param t Which type of hooks should be executed? - * @retval 0 All registred hooks for the specified type have been executed successfully. - * @retval <0 On of the hook functions signalized, that the processing should be aborted; message should be skipped. - */ -int hook_run(struct path *p, enum hook_type t); - /* The following prototypes are example hooks */ diff --git a/server/include/path.h b/server/include/path.h index eb4d65728..fdf269883 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -138,4 +138,13 @@ void path_print_stats(struct path *p); */ int path_print(struct path *p, char *buf, int len); +/** Conditionally execute the hooks + * + * @param p A pointer to the path structure. + * @param t Which type of hooks should be executed? + * @retval 0 All registred hooks for the specified type have been executed successfully. + * @retval <0 On of the hook functions signalized, that the processing should be aborted; message should be skipped. + */ +int path_run_hook(struct path *p, enum hook_type t); + #endif /* _PATH_H_ */ diff --git a/server/src/hooks.c b/server/src/hooks.c index 445fd8679..9b2e6b423 100644 --- a/server/src/hooks.c +++ b/server/src/hooks.c @@ -48,15 +48,6 @@ const struct hook* hook_lookup(const char *name) return NULL; /* No matching hook was found */ } -int hook_run(struct path *p, enum hook_type t) -{ - int ret = 0; - - FOREACH(&p->hooks[t], it) - ret += ((hook_cb_t) it->ptr)(p); - - return ret; -} int hook_print(struct path *p) { diff --git a/server/src/path.c b/server/src/path.c index 72fffc19f..37a20cc13 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -39,6 +39,15 @@ static void path_write(struct path *p) } } +int path_run_hook(struct path *p, enum hook_type t) +{ + int ret = 0; + FOREACH(&p->hooks[t], it) + ret += ((hook_cb_t) it->ptr)(p); + + return ret; +} + /** Send messages asynchronously */ static void * path_run_async(void *arg) { @@ -71,7 +80,7 @@ static void * path_run(void *arg) debug(10, "Received %u messages from node '%s'", recv, p->in->name); /* Run preprocessing hooks */ - if (hook_run(p, HOOK_PRE)) { + if (path_run_hook(p, HOOK_PRE)) { p->skipped += recv; continue; } @@ -84,14 +93,14 @@ static void * path_run(void *arg) p->received++; /* Run hooks for filtering, stats collection and manipulation */ - if (hook_run(p, HOOK_MSG)) { + if (path_run_hook(p, HOOK_MSG)) { p->skipped++; continue; } } /* Run post processing hooks */ - if (hook_run(p, HOOK_POST)) { + if (path_run_hook(p, HOOK_POST)) { p->skipped += recv; continue; } @@ -111,7 +120,7 @@ int path_start(struct path *p) info("Starting path: %s (poolsize = %u)", buf, p->poolsize); - if (hook_run(p, HOOK_PATH_START)) + if (path_run_hook(p, HOOK_PATH_START)) return -1; /* At fixed rate mode, we start another thread for sending */ @@ -151,7 +160,7 @@ int path_stop(struct path *p) close(p->tfd); } - if (hook_run(p, HOOK_PATH_STOP)) + if (path_run_hook(p, HOOK_PATH_STOP)) return -1; return 0; @@ -177,7 +186,7 @@ int path_print(struct path *p, char *buf, int len) int path_reset(struct path *p) { - if (hook_run(p, HOOK_PATH_RESTART)) + if (path_run_hook(p, HOOK_PATH_RESTART)) return -1; p->sent = diff --git a/server/src/server.c b/server/src/server.c index 34897c18c..fa673686d 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) for (;;) FOREACH(&paths, it) { usleep(settings.stats * 1e6); - hook_run(it->path, HOOK_PERIODIC); + path_run_hook(it->path, HOOK_PERIODIC); } } else