From a74fbdecdbf5f2ff18b19b43d2c1341c56bbe5f0 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 12 Oct 2021 14:45:10 +0200 Subject: [PATCH] Dispatcher fixes: user callback arg, changing handler to NULL --- apps/backend/backend_plugin.c | 2 +- lib/clixon/clixon_dispatcher.h | 1 + lib/src/clixon_dispatcher.c | 14 ++------------ test/test_pagination_state.sh | 2 +- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 0542c655..a3602170 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -489,7 +489,7 @@ clixon_pagination_cb_register(clicon_handle h, void *arg) { int retval = -1; - dispatcher_definition x = {xpath, fn}; + dispatcher_definition x = {xpath, fn, arg}; dispatcher_entry_t *htable = NULL; clicon_ptr_get(h, "pagination-entries", (void**)&htable); diff --git a/lib/clixon/clixon_dispatcher.h b/lib/clixon/clixon_dispatcher.h index 6a3ddd01..88bde49d 100644 --- a/lib/clixon/clixon_dispatcher.h +++ b/lib/clixon/clixon_dispatcher.h @@ -22,6 +22,7 @@ typedef int (*handler_function)(void *handle, char *path, void *userargs, void * typedef struct { char *dd_path; handler_function dd_handler; + void *dd_arg; } dispatcher_definition; /* diff --git a/lib/src/clixon_dispatcher.c b/lib/src/clixon_dispatcher.c index c11cef84..b38e78f9 100644 --- a/lib/src/clixon_dispatcher.c +++ b/lib/src/clixon_dispatcher.c @@ -366,7 +366,6 @@ dispatcher_register_handler(dispatcher_entry_t **root, if (*x->dd_path != '/') { errno = EINVAL; - // fprintf(stderr, "%s: part '%s' must start at root\n", __func__, x->dd_path); return -1; } @@ -394,17 +393,8 @@ dispatcher_register_handler(dispatcher_entry_t **root, } /* when we get here, ptr points at last entry added */ - if (x->dd_handler != NULL) { - /* - * we're adding/changing a handler - * you could make this an error optionally - */ - if (ptr->handler != NULL) { - // fprintf(stderr, "%s: warning: replacing existing handler: (%s) %p -> %p\n", __func__, - // ptr->node_name, ptr->handler, x->dd_handler); - } - ptr->handler = x->dd_handler; - } + ptr->handler = x->dd_handler; + ptr->arg = x->dd_arg; /* clean up */ split_path_free(split_path_list, split_path_len); diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index 60574333..e9ef8490 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -153,7 +153,7 @@ testrun_stop #---------------------------- -echo "...skipped: Must run interactvely" +echo "...skipped: Must run interactively" if false; then testrun_start "/es:audit-logs/es:audit-log"