diff options
author | Jose Bollo <jose.bollo@iot.bzh> | 2019-02-15 13:41:38 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2019-03-29 14:14:13 +0100 |
commit | a2cf84ecde926adeebf09bc2c284401513d3fab3 (patch) | |
tree | 2aeb893daf240e34ab12a8828f1b3ad9b900422c | |
parent | 5011060f04181acbb18babcc2017a2f0b6cfb853 (diff) |
hooks: Allow to remove hooking (and/or trace)
This change allows to downsize the binder by
removing its internal hooking and tracing features.
Change-Id: Ifb080a7426216f6c6b1c8f8e5bf8ddd52df40a3e
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | coverage/bin/Makefile | 6 | ||||
-rw-r--r-- | src/CMakeLists.txt | 38 | ||||
-rw-r--r-- | src/afb-api.h | 2 | ||||
-rw-r--r-- | src/afb-apiset.c | 2 | ||||
-rw-r--r-- | src/afb-apiset.h | 2 | ||||
-rw-r--r-- | src/afb-calls.c | 152 | ||||
-rw-r--r-- | src/afb-calls.h | 111 | ||||
-rw-r--r-- | src/afb-config.c | 32 | ||||
-rw-r--r-- | src/afb-evt.c | 204 | ||||
-rw-r--r-- | src/afb-evt.h | 14 | ||||
-rw-r--r-- | src/afb-export.c | 235 | ||||
-rw-r--r-- | src/afb-export.h | 5 | ||||
-rw-r--r-- | src/afb-hook-flags.c | 3 | ||||
-rw-r--r-- | src/afb-hook-flags.h | 3 | ||||
-rw-r--r-- | src/afb-hook.c | 3 | ||||
-rw-r--r-- | src/afb-hook.h | 3 | ||||
-rw-r--r-- | src/afb-monitor.c | 8 | ||||
-rw-r--r-- | src/afb-session.c | 12 | ||||
-rw-r--r-- | src/afb-supervision.c | 24 | ||||
-rw-r--r-- | src/afb-trace.c | 4 | ||||
-rw-r--r-- | src/afb-trace.h | 8 | ||||
-rw-r--r-- | src/afb-xreq.c | 109 | ||||
-rw-r--r-- | src/afb-xreq.h | 2 | ||||
-rw-r--r-- | src/main-afb-daemon.c | 25 | ||||
-rw-r--r-- | src/tests/apiset/test-apiset.c | 8 | ||||
-rw-r--r-- | src/tests/session/test-session.c | 5 |
26 files changed, 620 insertions, 400 deletions
diff --git a/coverage/bin/Makefile b/coverage/bin/Makefile index ef8b68e8..c0581693 100644 --- a/coverage/bin/Makefile +++ b/coverage/bin/Makefile @@ -63,6 +63,12 @@ cflags = $(ccflags) $(ldflags) defs = -DAGL_DEVEL \ -DWITH_MONITORING_OPTION \ -DAFB_VERSION=\"cov\" \ + -DUSE_SIG_MONITOR_DUMPSTACK=1 \ + -DUSE_SIG_MONITOR_SIGNALS=1 \ + -DUSE_SIG_MONITOR_FOR_CALL=1 \ + -DUSE_SIG_MONITOR_TIMERS=1 \ + -DWITH_AFB_HOOK=1 \ + -DWITH_AFB_TRACE=1 \ -DBINDING_INSTALL_DIR=\"$(shell pwd)/fake\" afb_lib_src = $(shell ls $(srcdir)/*.c | egrep -v '/afs-|/main-|/fdev-epoll.c|/afb-ws-client.c' ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1d5da5e8..eb299d28 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,31 +26,21 @@ ADD_DEFINITIONS(-DINFER_EXTENSION) ############################################################################ # TODO: improve below setting -set(USE_SIG_MONITOR_DUMPSTACK ON CACHE BOOL "activate dump stack on error") -set(USE_SIG_MONITOR_SIGNALS ON CACHE BOOL "activate handling of signals") -set(USE_SIG_MONITOR_FOR_CALL ON CACHE BOOL "activate monitoring of calls") -set(USE_SIG_MONITOR_TIMERS ON CACHE BOOL "activate monitoring of call expiration") +option(USE_SIG_MONITOR_DUMPSTACK "activate dump stack on error" ON) +option(USE_SIG_MONITOR_SIGNALS "activate handling of signals" ON) +option(USE_SIG_MONITOR_FOR_CALL "activate monitoring of calls" ON) +option(USE_SIG_MONITOR_TIMERS "activate monitoring of call expiration" ON) +option(WITH_AFB_HOOK "include hooking" ON) +option(WITH_AFB_TRACE "include monitoring trace" ON) -if(USE_SIG_MONITOR_DUMPSTACK) - add_definitions(-DUSE_SIG_MONITOR_DUMPSTACK=1) -else() - add_definitions(-DUSE_SIG_MONITOR_DUMPSTACK=0) -endif() -if(USE_SIG_MONITOR_SIGNALS) - add_definitions(-DUSE_SIG_MONITOR_SIGNALS=1) -else() - add_definitions(-DUSE_SIG_MONITOR_SIGNALS=0) -endif() -if(USE_SIG_MONITOR_FOR_CALL) - add_definitions(-DUSE_SIG_MONITOR_FOR_CALL=1) -else() - add_definitions(-DUSE_SIG_MONITOR_FOR_CALL=0) -endif() -if(USE_SIG_MONITOR_TIMERS) - add_definitions(-DUSE_SIG_MONITOR_TIMERS=1) -else() - add_definitions(-DUSE_SIG_MONITOR_TIMERS=0) -endif() +add_definitions( + -DUSE_SIG_MONITOR_DUMPSTACK=$<BOOL:${USE_SIG_MONITOR_DUMPSTACK}> + -DUSE_SIG_MONITOR_SIGNALS=$<BOOL:${USE_SIG_MONITOR_SIGNALS}> + -DUSE_SIG_MONITOR_FOR_CALL=$<BOOL:${USE_SIG_MONITOR_FOR_CALL}> + -DUSE_SIG_MONITOR_TIMERS=$<BOOL:${USE_SIG_MONITOR_TIMERS}> + -DWITH_AFB_HOOK=$<BOOL:${WITH_AFB_HOOK}> + -DWITH_AFB_TRACE=$<BOOL:${WITH_AFB_TRACE}> +) ############################################################################ SET(AFB_LIB_SOURCES diff --git a/src/afb-api.h b/src/afb-api.h index 7a1e3bb4..d55970c9 100644 --- a/src/afb-api.h +++ b/src/afb-api.h @@ -25,7 +25,9 @@ struct afb_api_itf { void (*call)(void *closure, struct afb_xreq *xreq); int (*service_start)(void *closure); +#if WITH_AFB_HOOK void (*update_hooks)(void *closure); +#endif int (*get_logmask)(void *closure); void (*set_logmask)(void *closure, int level); struct json_object *(*describe)(void *closure); diff --git a/src/afb-apiset.c b/src/afb-apiset.c index 90653d07..468a3646 100644 --- a/src/afb-apiset.c +++ b/src/afb-apiset.c @@ -870,6 +870,7 @@ int afb_apiset_start_all_services(struct afb_apiset *set) return ret; } +#if WITH_AFB_HOOK /** * Ask to update the hook flags of the 'api' * @param set the api set @@ -893,6 +894,7 @@ void afb_apiset_update_hooks(struct afb_apiset *set, const char *name) d->api.itf->update_hooks(d->api.closure); } } +#endif /** * Set the logmask of the 'api' to 'mask' diff --git a/src/afb-apiset.h b/src/afb-apiset.h index f5e40332..d1f968b7 100644 --- a/src/afb-apiset.h +++ b/src/afb-apiset.h @@ -54,7 +54,9 @@ extern const struct afb_api_item *afb_apiset_lookup_started(struct afb_apiset *s extern int afb_apiset_start_service(struct afb_apiset *set, const char *name); extern int afb_apiset_start_all_services(struct afb_apiset *set); +#if WITH_AFB_HOOK extern void afb_apiset_update_hooks(struct afb_apiset *set, const char *name); +#endif extern void afb_apiset_set_logmask(struct afb_apiset *set, const char *name, int mask); extern int afb_apiset_get_logmask(struct afb_apiset *set, const char *name); diff --git a/src/afb-calls.c b/src/afb-calls.c index ad681ebd..e30fe364 100644 --- a/src/afb-calls.c +++ b/src/afb-calls.c @@ -55,10 +55,13 @@ struct modes #define mode_async ((struct modes){ .hooked=0, .sync=0, .legacy=0 }) #define mode_legacy_sync ((struct modes){ .hooked=0, .sync=1, .legacy=1 }) #define mode_legacy_async ((struct modes){ .hooked=0, .sync=0, .legacy=1 }) + +#if WITH_AFB_HOOK #define mode_hooked_sync ((struct modes){ .hooked=1, .sync=1, .legacy=0 }) #define mode_hooked_async ((struct modes){ .hooked=1, .sync=0, .legacy=0 }) #define mode_hooked_legacy_sync ((struct modes){ .hooked=1, .sync=1, .legacy=1 }) #define mode_hooked_legacy_async ((struct modes){ .hooked=1, .sync=0, .legacy=1 }) +#endif union callback { void *any; @@ -177,6 +180,7 @@ static void callreq_reply_cb(struct afb_xreq *xreq, struct json_object *object, { struct callreq *callreq = CONTAINER_OF_XREQ(struct callreq, xreq); +#if WITH_AFB_HOOK /* centralized hooking */ if (callreq->mode.hooked) { if (callreq->mode.sync) { @@ -191,6 +195,7 @@ static void callreq_reply_cb(struct afb_xreq *xreq, struct json_object *object, afb_hook_api_call_result(callreq->export, object, error, info); } } +#endif /* true report of the result */ if (callreq->mode.sync) { @@ -418,18 +423,6 @@ void afb_calls_call( do_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_call, mode_async); } -void afb_calls_hooked_call( - struct afb_export *export, - const char *api, - const char *verb, - struct json_object *args, - void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*), - void *closure) -{ - afb_hook_api_call(export, api, verb, args); - do_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_call, mode_hooked_async); -} - int afb_calls_call_sync( struct afb_export *export, const char *api, @@ -442,19 +435,6 @@ int afb_calls_call_sync( return do_sync(export, NULL, api, verb, args, CALLFLAGS, object, error, info, mode_sync); } -int afb_calls_hooked_call_sync( - struct afb_export *export, - const char *api, - const char *verb, - struct json_object *args, - struct json_object **object, - char **error, - char **info) -{ - afb_hook_api_callsync(export, api, verb, args); - return do_sync(export, NULL, api, verb, args, CALLFLAGS, object, error, info, mode_hooked_sync); -} - void afb_calls_subcall( struct afb_xreq *xreq, const char *api, @@ -467,30 +447,56 @@ void afb_calls_subcall( do_async(NULL, xreq, api, verb, args, flags, callback, closure, final_subcall, mode_async); } -void afb_calls_hooked_subcall( +int afb_calls_subcall_sync( struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, - void (*callback)(void *closure, struct json_object *object, const char *error, const char * info, struct afb_req_x2 *req), - void *closure) + struct json_object **object, + char **error, + char **info) { - afb_hook_xreq_subcall(xreq, api, verb, args, flags); - do_async(NULL, xreq, api, verb, args, flags, callback, closure, final_subcall, mode_hooked_async); + return do_sync(NULL, xreq, api, verb, args, flags, object, error, info, mode_sync); } -int afb_calls_subcall_sync( +#if WITH_AFB_HOOK +void afb_calls_hooked_call( + struct afb_export *export, + const char *api, + const char *verb, + struct json_object *args, + void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*), + void *closure) +{ + afb_hook_api_call(export, api, verb, args); + do_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_call, mode_hooked_async); +} + +int afb_calls_hooked_call_sync( + struct afb_export *export, + const char *api, + const char *verb, + struct json_object *args, + struct json_object **object, + char **error, + char **info) +{ + afb_hook_api_callsync(export, api, verb, args); + return do_sync(export, NULL, api, verb, args, CALLFLAGS, object, error, info, mode_hooked_sync); +} + +void afb_calls_hooked_subcall( struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, - struct json_object **object, - char **error, - char **info) + void (*callback)(void *closure, struct json_object *object, const char *error, const char * info, struct afb_req_x2 *req), + void *closure) { - return do_sync(NULL, xreq, api, verb, args, flags, object, error, info, mode_sync); + afb_hook_xreq_subcall(xreq, api, verb, args, flags); + do_async(NULL, xreq, api, verb, args, flags, callback, closure, final_subcall, mode_hooked_async); } int afb_calls_hooked_subcall_sync( @@ -506,6 +512,7 @@ int afb_calls_hooked_subcall_sync( afb_hook_xreq_subcallsync(xreq, api, verb, args, flags); return do_sync(NULL, xreq, api, verb, args, flags, object, error, info, mode_hooked_sync); } +#endif /******************************************************************************/ /******************************************************************************/ @@ -627,49 +634,50 @@ void afb_calls_legacy_call_v12( do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v12, mode_legacy_async); } -void afb_calls_legacy_hooked_call_v12( +void afb_calls_legacy_call_v3( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*), + void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), void *closure) { - afb_hook_api_call(export, api, verb, args); - do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v12, mode_hooked_legacy_async); + do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v3, mode_legacy_async); } -void afb_calls_legacy_call_v3( +int afb_calls_legacy_call_sync( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), - void *closure) + struct json_object **result) { - do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v3, mode_legacy_async); + return do_legacy_sync(export, NULL, api, verb, args, CALLFLAGS, result, mode_legacy_sync); } -void afb_calls_legacy_hooked_call_v3( +#if WITH_AFB_HOOK +void afb_calls_legacy_hooked_call_v12( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), + void (*callback)(void*, int, struct json_object*), void *closure) { afb_hook_api_call(export, api, verb, args); - do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v3, mode_hooked_legacy_async); + do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v12, mode_hooked_legacy_async); } -int afb_calls_legacy_call_sync( +void afb_calls_legacy_hooked_call_v3( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - struct json_object **result) + void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), + void *closure) { - return do_legacy_sync(export, NULL, api, verb, args, CALLFLAGS, result, mode_legacy_sync); + afb_hook_api_call(export, api, verb, args); + do_legacy_async(export, NULL, api, verb, args, CALLFLAGS, callback, closure, final_legacy_call_v3, mode_hooked_legacy_async); } int afb_calls_legacy_hooked_call_sync( @@ -690,6 +698,7 @@ int afb_calls_legacy_hooked_call_sync( json_object_put(object); return rc; } +#endif /******************************************************************************/ @@ -742,72 +751,73 @@ void afb_calls_legacy_subcall_v1( do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v1, mode_legacy_async); } -void afb_calls_legacy_hooked_subcall_v1( +void afb_calls_legacy_subcall_v2( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*), + void (*callback)(void*, int, struct json_object*, struct afb_req_x1), void *closure) { - afb_hook_xreq_subcall(caller, api, verb, args, LEGACY_SUBCALLFLAGS); - do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v1, mode_hooked_legacy_async); + do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v2, mode_legacy_async); } -void afb_calls_legacy_subcall_v2( +void afb_calls_legacy_subcall_v3( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x1), + void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *closure) { - do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v2, mode_legacy_async); + do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v3, mode_legacy_async); } -void afb_calls_legacy_hooked_subcall_v2( +int afb_calls_legacy_subcall_sync( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x1), - void *closure) + struct json_object **result) { - afb_hook_xreq_subcall(caller, api, verb, args, LEGACY_SUBCALLFLAGS); - do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v2, mode_hooked_legacy_async); + return do_legacy_sync(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, result, mode_legacy_sync); } -void afb_calls_legacy_subcall_v3( +#if WITH_AFB_HOOK +void afb_calls_legacy_hooked_subcall_v1( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void (*callback)(void*, int, struct json_object*), void *closure) { - do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v3, mode_legacy_async); + afb_hook_xreq_subcall(caller, api, verb, args, LEGACY_SUBCALLFLAGS); + do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v1, mode_hooked_legacy_async); } -void afb_calls_legacy_hooked_subcall_v3( +void afb_calls_legacy_hooked_subcall_v2( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void (*callback)(void*, int, struct json_object*, struct afb_req_x1), void *closure) { afb_hook_xreq_subcall(caller, api, verb, args, LEGACY_SUBCALLFLAGS); - do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v3, mode_hooked_legacy_async); + do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v2, mode_hooked_legacy_async); } -int afb_calls_legacy_subcall_sync( +void afb_calls_legacy_hooked_subcall_v3( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - struct json_object **result) + void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void *closure) { - return do_legacy_sync(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, result, mode_legacy_sync); + afb_hook_xreq_subcall(caller, api, verb, args, LEGACY_SUBCALLFLAGS); + do_legacy_async(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, callback, closure, final_legacy_subcall_v3, mode_hooked_legacy_async); } int afb_calls_legacy_hooked_subcall_sync( @@ -820,3 +830,5 @@ int afb_calls_legacy_hooked_subcall_sync( afb_hook_xreq_subcallsync(caller, api, verb, args, LEGACY_SUBCALLFLAGS); return do_legacy_sync(NULL, caller, api, verb, args, LEGACY_SUBCALLFLAGS, result, mode_hooked_legacy_sync); } +#endif + diff --git a/src/afb-calls.h b/src/afb-calls.h index 43a5ceff..2f2d8e2c 100644 --- a/src/afb-calls.h +++ b/src/afb-calls.h @@ -27,7 +27,6 @@ struct afb_req_x1; struct afb_req_x2; /******************************************************************************/ - extern void afb_calls_call( struct afb_export *export, @@ -38,15 +37,6 @@ void afb_calls_call( void *closure); extern -void afb_calls_hooked_call( - struct afb_export *export, - const char *api, - const char *verb, - struct json_object *args, - void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*), - void *closure); - -extern int afb_calls_call_sync( struct afb_export *export, const char *api, @@ -57,16 +47,6 @@ int afb_calls_call_sync( char **info); extern -int afb_calls_hooked_call_sync( - struct afb_export *export, - const char *api, - const char *verb, - struct json_object *args, - struct json_object **object, - char **error, - char **info); - -extern void afb_calls_subcall( struct afb_xreq *xreq, const char *api, @@ -77,25 +57,47 @@ void afb_calls_subcall( void *closure); extern -void afb_calls_hooked_subcall( +int afb_calls_subcall_sync( struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, - void (*callback)(void *closure, struct json_object *object, const char *error, const char * info, struct afb_req_x2 *req), - void *closure); + struct json_object **object, + char **error, + char **info); + +/******************************************************************************/ +#if WITH_AFB_HOOK extern -int afb_calls_subcall_sync( +void afb_calls_hooked_call( + struct afb_export *export, + const char *api, + const char *verb, + struct json_object *args, + void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*), + void *closure); + +extern +int afb_calls_hooked_call_sync( + struct afb_export *export, + const char *api, + const char *verb, + struct json_object *args, + struct json_object **object, + char **error, + char **info); + +extern +void afb_calls_hooked_subcall( struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, - struct json_object **object, - char **error, - char **info); + void (*callback)(void *closure, struct json_object *object, const char *error, const char * info, struct afb_req_x2 *req), + void *closure); extern int afb_calls_hooked_subcall_sync( @@ -108,6 +110,7 @@ int afb_calls_hooked_subcall_sync( char **error, char **info); +#endif /* WITH_AFB_HOOK */ /******************************************************************************/ extern @@ -120,39 +123,42 @@ void afb_calls_legacy_call_v12( void *closure); extern -void afb_calls_legacy_hooked_call_v12( +void afb_calls_legacy_call_v3( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*), + void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), void *closure); extern -void afb_calls_legacy_call_v3( +int afb_calls_legacy_call_sync( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), - void *closure); + struct json_object **result); + +/******************************************************************************/ +#if WITH_AFB_HOOK extern -void afb_calls_legacy_hooked_call_v3( +void afb_calls_legacy_hooked_call_v12( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), + void (*callback)(void*, int, struct json_object*), void *closure); extern -int afb_calls_legacy_call_sync( +void afb_calls_legacy_hooked_call_v3( struct afb_export *export, const char *api, const char *verb, struct json_object *args, - struct json_object **result); + void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *), + void *closure); extern int afb_calls_legacy_hooked_call_sync( @@ -162,6 +168,7 @@ int afb_calls_legacy_hooked_call_sync( struct json_object *args, struct json_object **result); +#endif /* WITH_AFB_HOOK */ /******************************************************************************/ extern @@ -174,57 +181,60 @@ void afb_calls_legacy_subcall_v1( void *closure); extern -void afb_calls_legacy_hooked_subcall_v1( +void afb_calls_legacy_subcall_v2( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*), + void (*callback)(void*, int, struct json_object*, struct afb_req_x1), void *closure); extern -void afb_calls_legacy_subcall_v2( +void afb_calls_legacy_subcall_v3( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x1), + void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *closure); extern -void afb_calls_legacy_hooked_subcall_v2( +int afb_calls_legacy_subcall_sync( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x1), - void *closure); + struct json_object **result); + +/******************************************************************************/ +#if WITH_AFB_HOOK extern -void afb_calls_legacy_subcall_v3( +void afb_calls_legacy_hooked_subcall_v1( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void (*callback)(void*, int, struct json_object*), void *closure); extern -void afb_calls_legacy_hooked_subcall_v3( +void afb_calls_legacy_hooked_subcall_v2( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void (*callback)(void*, int, struct json_object*, struct afb_req_x1), void *closure); extern -int afb_calls_legacy_subcall_sync( +void afb_calls_legacy_hooked_subcall_v3( struct afb_xreq *caller, const char *api, const char *verb, struct json_object *args, - struct json_object **result); + void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), + void *closure); extern int afb_calls_legacy_hooked_subcall_sync( @@ -233,3 +243,6 @@ int afb_calls_legacy_hooked_subcall_sync( const char *verb, struct json_object *args, struct json_object **result); + +#endif /* WITH_AFB_HOOK */ +/******************************************************************************/ diff --git a/src/afb-config.c b/src/afb-config.c index 87fad97e..b9552f69 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -196,6 +196,7 @@ static struct option_desc optdefs[] = { {SET_SESSIONMAX, 1, "session-max", "Max count of session simultaneously [default " d2s(DEFAULT_MAX_SESSION_COUNT) "]"}, +#if WITH_AFB_HOOK {SET_TRACEREQ, 1, "tracereq", "Log the requests: none, common, extra, all"}, {SET_TRACEEVT, 1, "traceevt", "Log the events: none, common, extra, all"}, {SET_TRACESES, 1, "traceses", "Log the sessions: none, all"}, @@ -205,6 +206,7 @@ static struct option_desc optdefs[] = { {SET_TRACEDITF, 1, "traceditf", "Log the daemons: no, common, all"}, {SET_TRACESVC, 1, "tracesvc", "Log the services: no, all"}, #endif +#endif {ADD_CALL, 1, "call", "Call at start, format of val: API/VERB:json-args"}, @@ -332,12 +334,14 @@ static void printVersion(FILE * file) fprintf(file, "\n" " AGL Framework Binder [AFB %s] " + #if defined(WITH_DBUS_TRANSPARENCY) "+" #else "-" #endif "DBUS " + #if defined(WITH_MONITORING_OPTION) "+" #else @@ -349,7 +353,23 @@ static void printVersion(FILE * file) #else "-" #endif - "SUPERVISION [BINDINGS " + "SUPERVISION " + +#if WITH_AFB_HOOK + "+" +#else + "-" +#endif + "HOOK " + +#if WITH_TRACE + "+" +#else + "-" +#endif + "TRACE " + + "[BINDINGS " #if defined(WITH_LEGACY_BINDING_V1) "+" #else @@ -594,6 +614,7 @@ static void config_set_optint(struct json_object *config, int optid, int mini, i return config_set_optint_base(config, optid, mini, maxi, 10); } +__attribute__((unused)) static void config_set_optenum(struct json_object *config, int optid, int (*func)(const char*)) { const char *name = get_arg(optid); @@ -835,6 +856,7 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con break; +#if WITH_AFB_HOOK case SET_TRACEREQ: config_set_optenum(config, optid, afb_hook_flags_xreq_from_text); break; @@ -864,6 +886,7 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con config_set_optenum(config, optid, afb_hook_flags_legacy_svc_from_text); break; #endif +#endif case SET_EXEC: if (optind == argc) { @@ -975,6 +998,7 @@ static void on_environment(struct json_object *config, int optid, const char *na func(config, optid, value); } +__attribute__((unused)) static void on_environment_enum(struct json_object *config, int optid, const char *name, int (*func)(const char*)) { char *value = secure_getenv(name); @@ -1003,17 +1027,19 @@ static void on_environment_bool(struct json_object *config, int optid, const cha static void parse_environment(struct json_object *config) { +#if WITH_AFB_HOOK on_environment_enum(config, SET_TRACEREQ, "AFB_TRACEREQ", afb_hook_flags_xreq_from_text); on_environment_enum(config, SET_TRACEEVT, "AFB_TRACEEVT", afb_hook_flags_evt_from_text); on_environment_enum(config, SET_TRACESES, "AFB_TRACESES", afb_hook_flags_session_from_text); on_environment_enum(config, SET_TRACEAPI, "AFB_TRACEAPI", afb_hook_flags_api_from_text); on_environment_enum(config, SET_TRACEGLOB, "AFB_TRACEGLOB", afb_hook_flags_global_from_text); - on_environment(config, ADD_LDPATH, "AFB_LDPATHS", config_add_str); - on_environment(config, ADD_SET, "AFB_SET", config_mix2_str); #if !defined(REMOVE_LEGACY_TRACE) on_environment_enum(config, SET_TRACEDITF, "AFB_TRACEDITF", afb_hook_flags_legacy_ditf_from_text); on_environment_enum(config, SET_TRACESVC, "AFB_TRACESVC", afb_hook_flags_legacy_svc_from_text); #endif +#endif + on_environment(config, ADD_LDPATH, "AFB_LDPATHS", config_add_str); + on_environment(config, ADD_SET, "AFB_SET", config_mix2_str); on_environment_bool(config, SET_TRAP_FAULTS, "AFB_TRAP_FAULTS"); } diff --git a/src/afb-evt.c b/src/afb-evt.c index 87fce5e2..05d90961 100644 --- a/src/afb-evt.c +++ b/src/afb-evt.c @@ -74,8 +74,10 @@ struct afb_evtid { /* rwlock of the event */ pthread_rwlock_t rwlock; +#if WITH_AFB_HOOK /* hooking */ int hookflags; +#endif /* refcount */ int refcount; @@ -117,14 +119,16 @@ static struct afb_event_x2_itf afb_evt_event_x2_itf = { .addref = (void*)afb_evt_evtid_addref }; +#if WITH_AFB_HOOK /* the interface for events */ -static struct afb_event_x2_itf afb_evt_hooked_eventid_itf = { +static struct afb_event_x2_itf afb_evt_hooked_event_x2_itf = { .broadcast = (void*)afb_evt_evtid_hooked_broadcast, .push = (void*)afb_evt_evtid_hooked_push, .unref = (void*)afb_evt_evtid_hooked_unref, .name = (void*)afb_evt_evtid_hooked_name, .addref = (void*)afb_evt_evtid_hooked_addref }; +#endif /* head of the list of listeners */ static pthread_rwlock_t listeners_rwlock = PTHREAD_RWLOCK_INITIALIZER; @@ -163,6 +167,17 @@ static int broadcast(const char *event, struct json_object *obj, int id) } /* + * Broadcasts the event 'evtid' with its 'object' + * 'object' is released (like json_object_put) + * Returns the count of listener that received the event. + */ +int afb_evt_evtid_broadcast(struct afb_evtid *evtid, struct json_object *object) +{ + return broadcast(evtid->fullname, object, evtid->id); +} + +#if WITH_AFB_HOOK +/* * Broadcasts the 'event' of 'id' with its 'obj' * 'obj' is released (like json_object_put) * calls hooks if hookflags isn't 0 @@ -192,20 +207,11 @@ static int hooked_broadcast(const char *event, struct json_object *obj, int id, * 'object' is released (like json_object_put) * Returns the count of listener that received the event. */ -int afb_evt_evtid_broadcast(struct afb_evtid *evtid, struct json_object *object) -{ - return broadcast(evtid->fullname, object, evtid->id); -} - -/* - * Broadcasts the event 'evtid' with its 'object' - * 'object' is released (like json_object_put) - * Returns the count of listener that received the event. - */ int afb_evt_evtid_hooked_broadcast(struct afb_evtid *evtid, struct json_object *object) { return hooked_broadcast(evtid->fullname, object, evtid->id, evtid->hookflags); } +#endif /* * Broadcasts the 'event' with its 'object' @@ -214,7 +220,11 @@ int afb_evt_evtid_hooked_broadcast(struct afb_evtid *evtid, struct json_object * */ int afb_evt_broadcast(const char *event, struct json_object *object) { +#if WITH_AFB_HOOK return hooked_broadcast(event, object, 0, -1); +#else + return broadcast(event, object, 0); +#endif } /* @@ -246,36 +256,6 @@ int afb_evt_evtid_push(struct afb_evtid *evtid, struct json_object *obj) } /* - * Pushes the event 'evtid' with 'obj' to its listeners - * 'obj' is released (like json_object_put) - * Emits calls to hooks. - * Returns the count of listener taht received the event. - */ -int afb_evt_evtid_hooked_push(struct afb_evtid *evtid, struct json_object *obj) -{ - - int result; - - /* lease the object */ - json_object_get(obj); - - /* hook before push */ - if (evtid->hookflags & afb_hook_flag_evt_push_before) - afb_hook_evt_push_before(evtid->fullname, evtid->id, obj); - - /* push */ - result = afb_evt_evtid_push(evtid, obj); - - /* hook after push */ - if (evtid->hookflags & afb_hook_flag_evt_push_after) - afb_hook_evt_push_after(evtid->fullname, evtid->id, obj, result); - - /* release the object */ - json_object_put(obj); - return result; -} - -/* * remove the 'watch' */ static void remove_watch(struct afb_evt_watch *watch) @@ -342,10 +322,14 @@ struct afb_evtid *afb_evt_evtid_create(const char *fullname) evtid->id = event_id_counter; pthread_rwlock_init(&evtid->rwlock, NULL); evtids = evtid; +#if WITH_AFB_HOOK evtid->hookflags = afb_hook_flags_evt(evtid->fullname); - evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_eventid_itf : &afb_evt_event_x2_itf; + evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_event_x2_itf : &afb_evt_event_x2_itf; if (evtid->hookflags & afb_hook_flag_evt_create) afb_hook_evt_create(evtid->fullname, evtid->id); +#else + evtid->eventid.itf = &afb_evt_event_x2_itf; +#endif pthread_rwlock_unlock(&events_rwlock); /* returns the event */ @@ -384,16 +368,6 @@ struct afb_evtid *afb_evt_evtid_addref(struct afb_evtid *evtid) } /* - * increment the reference count of the event 'evtid' - */ -struct afb_evtid *afb_evt_evtid_hooked_addref(struct afb_evtid *evtid) -{ - if (evtid->hookflags & afb_hook_flag_evt_addref) - afb_hook_evt_addref(evtid->fullname, evtid->id); - return afb_evt_evtid_addref(evtid); -} - -/* * decrement the reference count of the event 'evtid' * and destroy it when the count reachs zero */ @@ -436,17 +410,6 @@ void afb_evt_evtid_unref(struct afb_evtid *evtid) } /* - * decrement the reference count of the event 'evtid' - * and destroy it when the count reachs zero - */ -void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid) -{ - if (evtid->hookflags & afb_hook_flag_evt_unref) - afb_hook_evt_unref(evtid->fullname, evtid->id); - afb_evt_evtid_unref(evtid); -} - -/* * Returns the true name of the 'event' */ const char *afb_evt_evtid_fullname(struct afb_evtid *evtid) @@ -464,17 +427,6 @@ const char *afb_evt_evtid_name(struct afb_evtid *evtid) } /* - * Returns the name associated to the event 'evtid'. - */ -const char *afb_evt_evtid_hooked_name(struct afb_evtid *evtid) -{ - const char *result = afb_evt_evtid_name(evtid); - if (evtid->hookflags & afb_hook_flag_evt_name) - afb_hook_evt_name(evtid->fullname, evtid->id, result); - return result; -} - -/* * Returns the id of the 'event' */ int afb_evt_evtid_id(struct afb_evtid *evtid) @@ -642,21 +594,6 @@ int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb_evtid return -1; } -/* - * update the hooks for events - */ -void afb_evt_update_hooks() -{ - struct afb_evtid *evtid; - - pthread_rwlock_rdlock(&events_rwlock); - for (evtid = evtids ; evtid ; evtid = evtid->next) { - evtid->hookflags = afb_hook_flags_evt(evtid->fullname); - evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_eventid_itf : &afb_evt_event_x2_itf; - } - pthread_rwlock_unlock(&events_rwlock); -} - inline struct afb_evtid *afb_evt_event_x2_to_evtid(struct afb_event_x2 *eventid) { return (struct afb_evtid*)eventid; @@ -740,6 +677,7 @@ int afb_evt_event_x2_remove_watch(struct afb_evt_listener *listener, struct afb_ } int afb_evt_event_x2_push(struct afb_event_x2 *eventid, struct json_object *object) +#if WITH_AFB_HOOK { struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid); if (evtid) @@ -747,6 +685,9 @@ int afb_evt_event_x2_push(struct afb_event_x2 *eventid, struct json_object *obje json_object_put(object); return 0; } +#else + __attribute__((alias("afb_evt_event_x2_unhooked_push"))); +#endif int afb_evt_event_x2_unhooked_push(struct afb_event_x2 *eventid, struct json_object *object) { @@ -760,7 +701,11 @@ int afb_evt_event_x2_unhooked_push(struct afb_event_x2 *eventid, struct json_obj struct afb_event_x1 afb_evt_event_from_evtid(struct afb_evtid *evtid) { return evtid - ? (struct afb_event_x1){ .itf = &afb_evt_hooked_eventid_itf, .closure = &evtid->eventid } +#if WITH_AFB_HOOK + ? (struct afb_event_x1){ .itf = &afb_evt_hooked_event_x2_itf, .closure = &evtid->eventid } +#else + ? (struct afb_event_x1){ .itf = &afb_evt_event_x2_itf, .closure = &evtid->eventid } +#endif : (struct afb_event_x1){ .itf = NULL, .closure = NULL }; } @@ -779,3 +724,82 @@ struct afb_event_x2 *afb_evt_event_x2_addref(struct afb_event_x2 *eventid) return eventid; } +#if WITH_AFB_HOOK +/* + * Pushes the event 'evtid' with 'obj' to its listeners + * 'obj' is released (like json_object_put) + * Emits calls to hooks. + * Returns the count of listener taht received the event. + */ +int afb_evt_evtid_hooked_push(struct afb_evtid *evtid, struct json_object *obj) +{ + + int result; + + /* lease the object */ + json_object_get(obj); + + /* hook before push */ + if (evtid->hookflags & afb_hook_flag_evt_push_before) + afb_hook_evt_push_before(evtid->fullname, evtid->id, obj); + + /* push */ + result = afb_evt_evtid_push(evtid, obj); + + /* hook after push */ + if (evtid->hookflags & afb_hook_flag_evt_push_after) + afb_hook_evt_push_after(evtid->fullname, evtid->id, obj, result); + + /* release the object */ + json_object_put(obj); + return result; +} + +/* + * increment the reference count of the event 'evtid' + */ +struct afb_evtid *afb_evt_evtid_hooked_addref(struct afb_evtid *evtid) +{ + if (evtid->hookflags & afb_hook_flag_evt_addref) + afb_hook_evt_addref(evtid->fullname, evtid->id); + return afb_evt_evtid_addref(evtid); +} + +/* + * decrement the reference count of the event 'evtid' + * and destroy it when the count reachs zero + */ +void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid) +{ + if (evtid->hookflags & afb_hook_flag_evt_unref) + afb_hook_evt_unref(evtid->fullname, evtid->id); + afb_evt_evtid_unref(evtid); +} + +/* + * Returns the name associated to the event 'evtid'. + */ +const char *afb_evt_evtid_hooked_name(struct afb_evtid *evtid) +{ + const char *result = afb_evt_evtid_name(evtid); + if (evtid->hookflags & afb_hook_flag_evt_name) + afb_hook_evt_name(evtid->fullname, evtid->id, result); + return result; +} + +/* + * update the hooks for events + */ +void afb_evt_update_hooks() +{ + struct afb_evtid *evtid; + + pthread_rwlock_rdlock(&events_rwlock); + for (evtid = evtids ; evtid ; evtid = evtid->next) { + evtid->hookflags = afb_hook_flags_evt(evtid->fullname); + evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_event_x2_itf : &afb_evt_event_x2_itf; + } + pthread_rwlock_unlock(&events_rwlock); +} +#endif + diff --git a/src/afb-evt.h b/src/afb-evt.h index 28a4eddd..5ba6ce9b 100644 --- a/src/afb-evt.h +++ b/src/afb-evt.h @@ -43,27 +43,21 @@ extern struct afb_evtid *afb_evt_evtid_create(const char *fullname); extern struct afb_evtid *afb_evt_evtid_create2(const char *prefix, const char *name); extern struct afb_evtid *afb_evt_evtid_addref(struct afb_evtid *evtid); -extern struct afb_evtid *afb_evt_evtid_hooked_addref(struct afb_evtid *evtid); extern void afb_evt_evtid_unref(struct afb_evtid *evtid); -extern void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid); extern const char *afb_evt_evtid_fullname(struct afb_evtid *evtid); extern int afb_evt_evtid_id(struct afb_evtid *evtid); extern const char *afb_evt_evtid_name(struct afb_evtid *evtid); -extern const char *afb_evt_evtid_hooked_name(struct afb_evtid *evtid); extern int afb_evt_evtid_push(struct afb_evtid *evtid, struct json_object *obj); -extern int afb_evt_evtid_hooked_push(struct afb_evtid *evtid, struct json_object *obj); extern int afb_evt_evtid_broadcast(struct afb_evtid *evtid, struct json_object *object); -extern int afb_evt_evtid_hooked_broadcast(struct afb_evtid *evtid, struct json_object *object); extern int afb_evt_watch_add_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid); extern int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid); -extern void afb_evt_update_hooks(); extern struct afb_event_x2 *afb_evt_event_x2_create(const char *fullname); @@ -83,3 +77,11 @@ extern struct afb_evtid *afb_evt_event_x2_to_evtid(struct afb_event_x2 *eventid) extern struct afb_event_x2 *afb_evt_event_x2_from_evtid(struct afb_evtid *evtid); extern struct afb_event_x1 afb_evt_event_from_evtid(struct afb_evtid *evtid); +#if WITH_AFB_HOOK +extern struct afb_evtid *afb_evt_evtid_hooked_addref(struct afb_evtid *evtid); +extern void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid); +extern const char *afb_evt_evtid_hooked_name(struct afb_evtid *evtid); +extern int afb_evt_evtid_hooked_push(struct afb_evtid *evtid, struct json_object *obj); +extern int afb_evt_evtid_hooked_broadcast(struct afb_evtid *evtid, struct json_object *object); +extern void afb_evt_update_hooks(); +#endif
\ No newline at end of file diff --git a/src/afb-export.c b/src/afb-export.c index 37089566..5b0975dc 100644 --- a/src/afb-export.c +++ b/src/afb-export.c @@ -105,9 +105,11 @@ struct afb_export /* unsealed */ unsigned unsealed: 1; +#if WITH_AFB_HOOK /* hooking flags */ int hookditf; int hooksvc; +#endif /* session for service */ struct afb_session *session; @@ -419,9 +421,24 @@ static struct afb_api_x3 *api_new_api_cb( return apiv3 ? to_api_x3(afb_api_v3_export(apiv3)) : NULL; } -/********************************************** -* hooked flow -**********************************************/ +static const struct afb_daemon_itf_x1 daemon_itf = { + .vverbose_v1 = legacy_vverbose_v1_cb, + .vverbose_v2 = vverbose_cb, + .event_make = legacy_event_x1_make_cb, + .event_broadcast = event_broadcast_cb, + .get_event_loop = get_event_loop, + .get_user_bus = get_user_bus, + .get_system_bus = get_system_bus, + .rootdir_get_fd = afb_common_rootdir_get_fd, + .rootdir_open_locale = rootdir_open_locale_cb, + .queue_job = queue_job_cb, + .unstore_req = legacy_unstore_req_cb, + .require_api = require_api_cb, + .add_alias = add_alias_cb, + .new_api = api_new_api_cb, +}; + +#if WITH_AFB_HOOK static void hooked_vverbose_cb(struct afb_api_x3 *closure, int level, const char *file, int line, const char *function, const char *fmt, va_list args) { struct afb_export *export = from_api_x3(closure); @@ -556,26 +573,6 @@ static struct afb_api_x3 *hooked_api_new_api_cb( return result; } -/********************************************** -* vectors -**********************************************/ -static const struct afb_daemon_itf_x1 daemon_itf = { - .vverbose_v1 = legacy_vverbose_v1_cb, - .vverbose_v2 = vverbose_cb, - .event_make = legacy_event_x1_make_cb, - .event_broadcast = event_broadcast_cb, - .get_event_loop = get_event_loop, - .get_user_bus = get_user_bus, - .get_system_bus = get_system_bus, - .rootdir_get_fd = afb_common_rootdir_get_fd, - .rootdir_open_locale = rootdir_open_locale_cb, - .queue_job = queue_job_cb, - .unstore_req = legacy_unstore_req_cb, - .require_api = require_api_cb, - .add_alias = add_alias_cb, - .new_api = api_new_api_cb, -}; - static const struct afb_daemon_itf_x1 hooked_daemon_itf = { .vverbose_v1 = legacy_hooked_vverbose_v1_cb, .vverbose_v2 = hooked_vverbose_cb, @@ -592,6 +589,7 @@ static const struct afb_daemon_itf_x1 hooked_daemon_itf = { .add_alias = hooked_add_alias_cb, .new_api = hooked_api_new_api_cb, }; +#endif /****************************************************************************** ****************************************************************************** @@ -676,6 +674,13 @@ static int legacy_call_sync( return afb_calls_legacy_call_sync(export, api, verb, args, result); } +/* the interface for services */ +static const struct afb_service_itf_x1 service_itf = { + .call = legacy_call_v12, + .call_sync = legacy_call_sync +}; + +#if WITH_AFB_HOOK static void hooked_call_x3( struct afb_api_x3 *apix3, const char *api, @@ -737,16 +742,11 @@ static int legacy_hooked_call_sync( } /* the interface for services */ -static const struct afb_service_itf_x1 service_itf = { - .call = legacy_call_v12, - .call_sync = legacy_call_sync -}; - -/* the interface for services */ static const struct afb_service_itf_x1 hooked_service_itf = { .call = legacy_hooked_call_v12, .call_sync = legacy_hooked_call_sync }; +#endif /****************************************************************************** ****************************************************************************** @@ -954,6 +954,48 @@ static struct json_object *settings_cb(struct afb_api_x3 *api) return result; } +static const struct afb_api_x3_itf api_x3_itf = { + + .vverbose = (void*)vverbose_cb, + + .get_event_loop = get_event_loop, + .get_user_bus = get_user_bus, + .get_system_bus = get_system_bus, + .rootdir_get_fd = afb_common_rootdir_get_fd, + .rootdir_open_locale = rootdir_open_locale_cb, + .queue_job = queue_job_cb, + + .require_api = require_api_cb, + .add_alias = add_alias_cb, + + .event_broadcast = event_broadcast_cb, + .event_make = event_x2_make_cb, + + .legacy_call = legacy_call_x3, + .legacy_call_sync = legacy_call_sync, + + .api_new_api = api_new_api_cb, + .api_set_verbs_v2 = api_set_verbs_v2_cb, + .api_add_verb = api_add_verb_cb, + .api_del_verb = api_del_verb_cb, + .api_set_on_event = api_set_on_event_cb, + .api_set_on_init = api_set_on_init_cb, + .api_seal = api_seal_cb, + .api_set_verbs_v3 = api_set_verbs_v3_cb, + .event_handler_add = event_handler_add_cb, + .event_handler_del = event_handler_del_cb, + + .call = call_x3, + .call_sync = call_sync_x3, + + .class_provide = class_provide_cb, + .class_require = class_require_cb, + + .delete_api = delete_api_cb, + .settings = settings_cb, +}; + +#if WITH_AFB_HOOK static int hooked_api_set_verbs_v2_cb( struct afb_api_x3 *api, const struct afb_verb_v2 *verbs) @@ -1075,47 +1117,6 @@ static struct json_object *hooked_settings_cb(struct afb_api_x3 *api) return result; } -static const struct afb_api_x3_itf api_x3_itf = { - - .vverbose = (void*)vverbose_cb, - - .get_event_loop = get_event_loop, - .get_user_bus = get_user_bus, - .get_system_bus = get_system_bus, - .rootdir_get_fd = afb_common_rootdir_get_fd, - .rootdir_open_locale = rootdir_open_locale_cb, - .queue_job = queue_job_cb, - - .require_api = require_api_cb, - .add_alias = add_alias_cb, - - .event_broadcast = event_broadcast_cb, - .event_make = event_x2_make_cb, - - .legacy_call = legacy_call_x3, - .legacy_call_sync = legacy_call_sync, - - .api_new_api = api_new_api_cb, - .api_set_verbs_v2 = api_set_verbs_v2_cb, - .api_add_verb = api_add_verb_cb, - .api_del_verb = api_del_verb_cb, - .api_set_on_event = api_set_on_event_cb, - .api_set_on_init = api_set_on_init_cb, - .api_seal = api_seal_cb, - .api_set_verbs_v3 = api_set_verbs_v3_cb, - .event_handler_add = event_handler_add_cb, - .event_handler_del = event_handler_del_cb, - - .call = call_x3, - .call_sync = call_sync_x3, - - .class_provide = class_provide_cb, - .class_require = class_require_cb, - - .delete_api = delete_api_cb, - .settings = settings_cb, -}; - static const struct afb_api_x3_itf hooked_api_x3_itf = { .vverbose = hooked_vverbose_cb, @@ -1156,6 +1157,7 @@ static const struct afb_api_x3_itf hooked_api_x3_itf = { .delete_api = hooked_delete_api_cb, .settings = hooked_settings_cb, }; +#endif /****************************************************************************** ****************************************************************************** @@ -1176,22 +1178,28 @@ static void listener_of_events(void *closure, const char *event, int eventid, st void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*); struct afb_export *export = from_api_x3(closure); +#if WITH_AFB_HOOK /* hook the event before */ if (export->hooksvc & afb_hook_flag_api_on_event) afb_hook_api_on_event_before(export, event, eventid, object); +#endif /* transmit to specific handlers */ /* search the handler */ handler = export->event_handlers ? globset_match(export->event_handlers, event) : NULL; if (handler) { callback = handler->callback; +#if WITH_AFB_HOOK if (!(export->hooksvc & afb_hook_flag_api_on_event_handler)) +#endif callback(handler->closure, event, object, to_api_x3(export)); +#if WITH_AFB_HOOK else { afb_hook_api_on_event_handler_before(export, event, eventid, object, handler->pattern); callback(handler->closure, event, object, to_api_x3(export)); afb_hook_api_on_event_handler_after(export, event, eventid, object, handler->pattern); } +#endif } else { /* transmit to default handler */ if (export->on_any_event_v3) @@ -1200,9 +1208,11 @@ static void listener_of_events(void *closure, const char *event, int eventid, st export->on_any_event_v12(event, object); } +#if WITH_AFB_HOOK /* hook the event after */ if (export->hooksvc & afb_hook_flag_api_on_event) afb_hook_api_on_event_after(export, event, eventid, object); +#endif json_object_put(object); } @@ -1282,6 +1292,43 @@ int afb_export_event_handler_del( ****************************************************************************** ******************************************************************************/ +static void set_interfaces(struct afb_export *export) +{ +#if WITH_AFB_HOOK + export->hookditf = afb_hook_flags_api(export->api.apiname); + export->hooksvc = afb_hook_flags_api(export->api.apiname); + export->api.itf = export->hookditf|export->hooksvc ? &hooked_api_x3_itf : &api_x3_itf; + + switch (export->version) { +#if defined(WITH_LEGACY_BINDING_V1) + case Api_Version_1: + export->export.v1.daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf; + break; +#endif + case Api_Version_2: + export->export.v2->daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf; + export->export.v2->service.itf = export->hooksvc ? &hooked_service_itf : &service_itf; + break; + } +#else + + export->api.itf = &api_x3_itf; + + switch (export->version) { +#if defined(WITH_LEGACY_BINDING_V1) + case Api_Version_1: + export->export.v1.daemon.itf = &daemon_itf; + break; +#endif + case Api_Version_2: + export->export.v2->daemon.itf = &daemon_itf; + export->export.v2->service.itf = &service_itf; + break; + } + +#endif +} + static struct afb_export *create( struct afb_apiset *declare_set, struct afb_apiset *call_set, @@ -1360,7 +1407,7 @@ struct afb_export *afb_export_create_none_for_path( struct afb_export *export = create(declare_set, call_set, path, path, Api_Version_None); if (export) { afb_export_logmask_set(export, logmask); - afb_export_update_hooks(export); + set_interfaces(export); if (creator && creator(closure, to_api_x3(export)) < 0) { afb_export_unref(export); export = NULL; @@ -1384,7 +1431,7 @@ struct afb_export *afb_export_create_v1(struct afb_apiset *declare_set, export->export.v1.mode = AFB_MODE_LOCAL; export->export.v1.daemon.closure = to_api_x3(export); afb_export_logmask_set(export, logmask); - afb_export_update_hooks(export); + set_interfaces(export); } return export; } @@ -1408,7 +1455,7 @@ struct afb_export *afb_export_create_v2(struct afb_apiset *declare_set, data->daemon.closure = to_api_x3(export); data->service.closure = to_api_x3(export); afb_export_logmask_set(export, logmask); - afb_export_update_hooks(export); + set_interfaces(export); } return export; } @@ -1426,7 +1473,7 @@ struct afb_export *afb_export_create_v3(struct afb_apiset *declare_set, export->desc.v3 = apiv3; export->creator = afb_export_addref(creator); afb_export_logmask_set(export, logmask); - afb_export_update_hooks(export); + set_interfaces(export); } return export; } @@ -1456,7 +1503,7 @@ int afb_export_rename(struct afb_export *export, const char *apiname) free((void*)export->api.apiname); export->api.apiname = name; - afb_export_update_hooks(export); + set_interfaces(export); return 0; } @@ -1465,25 +1512,6 @@ const char *afb_export_apiname(const struct afb_export *export) return export->api.apiname; } -void afb_export_update_hooks(struct afb_export *export) -{ - export->hookditf = afb_hook_flags_api(export->api.apiname); - export->hooksvc = afb_hook_flags_api(export->api.apiname); - export->api.itf = export->hookditf|export->hooksvc ? &hooked_api_x3_itf : &api_x3_itf; - - switch (export->version) { -#if defined(WITH_LEGACY_BINDING_V1) - case Api_Version_1: - export->export.v1.daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf; - break; -#endif - case Api_Version_2: - export->export.v2->daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf; - export->export.v2->service.itf = export->hooksvc ? &hooked_service_itf : &service_itf; - break; - } -} - int afb_export_unshare_session(struct afb_export *export) { if (export->session == common_session) { @@ -1619,7 +1647,11 @@ static void do_init(int sig, void *closure) case Api_Version_1: rc = export->init.v1 ? export->init.v1( (struct afb_service_x1){ +#if WITH_AFB_HOOK .itf = &hooked_service_itf, +#else + .itf = &service_itf, +#endif .closure = to_api_x3(export) }) : 0; break; #endif @@ -1677,9 +1709,11 @@ int afb_export_start(struct afb_export *export) return -1; } +#if WITH_AFB_HOOK /* Starts the service */ if (export->hooksvc & afb_hook_flag_api_start) afb_hook_api_start_before(export); +#endif export->state = Api_State_Init; init.export = export; @@ -1687,8 +1721,10 @@ int afb_export_start(struct afb_export *export) rc = init.return_code; export->state = Api_State_Run; +#if WITH_AFB_HOOK if (export->hooksvc & afb_hook_flag_api_start) afb_hook_api_start_after(export, rc); +#endif if (rc < 0) { /* initialisation error */ @@ -1754,12 +1790,13 @@ static int api_service_start_cb(void *closure) return afb_export_start(export); } +#if WITH_AFB_HOOK static void api_update_hooks_cb(void *closure) -{ - struct afb_export *export = closure; + __attribute__((alias("set_interfaces"))); - afb_export_update_hooks(export); -} +void afb_export_update_hooks(struct afb_export *export) + __attribute__((alias("set_interfaces"))); +#endif static int api_get_logmask_cb(void *closure) { @@ -1786,7 +1823,9 @@ static struct afb_api_itf export_api_itf = { .call = api_call_cb, .service_start = api_service_start_cb, +#if WITH_AFB_HOOK .update_hooks = api_update_hooks_cb, +#endif .get_logmask = api_get_logmask_cb, .set_logmask = api_set_logmask_cb, .describe = api_describe_cb, diff --git a/src/afb-export.h b/src/afb-export.h index 57839b2f..e8b9a9d4 100644 --- a/src/afb-export.h +++ b/src/afb-export.h @@ -66,7 +66,6 @@ extern void afb_export_undeclare(struct afb_export *export); extern const char *afb_export_apiname(const struct afb_export *export); extern int afb_export_add_alias(struct afb_export *export, const char *apiname, const char *aliasname); extern int afb_export_rename(struct afb_export *export, const char *apiname); -extern void afb_export_update_hooks(struct afb_export *export); extern int afb_export_unshare_session(struct afb_export *export); @@ -115,6 +114,10 @@ extern void afb_export_context_init(struct afb_export *export, struct afb_contex extern struct afb_export *afb_export_from_api_x3(struct afb_api_x3 *api); extern struct afb_api_x3 *afb_export_to_api_x3(struct afb_export *export); +#if WITH_AFB_HOOK +extern void afb_export_update_hooks(struct afb_export *export); +#endif + #if defined(WITH_LEGACY_BINDING_V1) struct afb_service_x1; diff --git a/src/afb-hook-flags.c b/src/afb-hook-flags.c index 87b8dcf3..874d21b6 100644 --- a/src/afb-hook-flags.c +++ b/src/afb-hook-flags.c @@ -15,6 +15,8 @@ * limitations under the License. */ +#if WITH_AFB_HOOK /***********************************************************/ + #define _GNU_SOURCE #include <stdlib.h> @@ -358,3 +360,4 @@ char *afb_hook_flags_legacy_svc_to_text(int value) } #endif +#endif /* WITH_AFB_HOOK *******************************************************/ diff --git a/src/afb-hook-flags.h b/src/afb-hook-flags.h index 40b8d96a..d9619be5 100644 --- a/src/afb-hook-flags.h +++ b/src/afb-hook-flags.h @@ -17,6 +17,8 @@ #pragma once +#if WITH_AFB_HOOK /***********************************************************/ + extern int afb_hook_flags_xreq_from_text(const char *text); extern int afb_hook_flags_api_from_text(const char *text); extern int afb_hook_flags_evt_from_text(const char *text); @@ -36,3 +38,4 @@ extern char *afb_hook_flags_legacy_ditf_to_text(int value); extern char *afb_hook_flags_legacy_svc_to_text(int value); #endif +#endif /* WITH_AFB_HOOK *******************************************************/ diff --git a/src/afb-hook.c b/src/afb-hook.c index f11ce0d3..f8b593df 100644 --- a/src/afb-hook.c +++ b/src/afb-hook.c @@ -15,6 +15,8 @@ * limitations under the License. */ +#if WITH_AFB_HOOK /***********************************************************/ + #define _GNU_SOURCE #include <limits.h> @@ -1848,3 +1850,4 @@ void afb_hook_unref_global(struct afb_hook_global *hook) } } +#endif /* WITH_AFB_HOOK *******************************************************/ diff --git a/src/afb-hook.h b/src/afb-hook.h index f2b51e7c..9131621c 100644 --- a/src/afb-hook.h +++ b/src/afb-hook.h @@ -17,6 +17,8 @@ #pragma once +#if WITH_AFB_HOOK /***********************************************************/ + #include <stdarg.h> #include <time.h> @@ -459,3 +461,4 @@ extern struct afb_hook_global *afb_hook_addref_global(struct afb_hook_global *ho extern void afb_hook_unref_global(struct afb_hook_global *hook); +#endif /* WITH_AFB_HOOK *******************************************************/ diff --git a/src/afb-monitor.c b/src/afb-monitor.c index 92399b01..15dd1a49 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -326,6 +326,7 @@ static void f_set(afb_req_t req) afb_req_success(req, NULL, NULL); } +#if WITH_AFB_TRACE static void *context_create(void *closure) { return afb_trace_create(_afb_binding_monitor.api, NULL); @@ -360,7 +361,14 @@ static void f_trace(afb_req_t req) end: afb_apiset_update_hooks(target_set, NULL); afb_evt_update_hooks(); + return; } +#else +static void f_trace(afb_req_t req) +{ + afb_req_reply(req, NULL, "not-available", NULL); +} +#endif static void f_session(afb_req_t req) { diff --git a/src/afb-session.c b/src/afb-session.c index 19a5ebfc..70e8c3cd 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -240,8 +240,10 @@ static void session_close(struct afb_session *session) /* close it now */ session->closed = 1; +#if WITH_AFB_HOOK /* emit the hook */ afb_hook_session_close(session); +#endif /* release cookies */ for (idx = 0 ; idx < COOKIECOUNT ; idx++) { @@ -258,7 +260,9 @@ static void session_close(struct afb_session *session) /* destroy the 'session' */ static void session_destroy (struct afb_session *session) { +#if WITH_AFB_HOOK afb_hook_session_destroy(session); +#endif pthread_mutex_destroy(&session->mutex); free(session->lang); free(session); @@ -316,7 +320,9 @@ static struct afb_session *session_add(const char *uuid, int timeout, time_t now return NULL; } +#if WITH_AFB_HOOK afb_hook_session_create(session); +#endif return session; } @@ -513,7 +519,9 @@ end: struct afb_session *afb_session_addref(struct afb_session *session) { if (session != NULL) { +#if WITH_AFB_HOOK afb_hook_session_addref(session); +#endif session_lock(session); session->refcount++; session_unlock(session); @@ -527,7 +535,9 @@ void afb_session_unref(struct afb_session *session) if (session == NULL) return; +#if WITH_AFB_HOOK afb_hook_session_unref(session); +#endif session_lock(session); if (!--session->refcount) { if (session->autoclose) @@ -590,7 +600,9 @@ void afb_session_new_token (struct afb_session *session) session_lock(session); new_uuid(session->token); session_update_expiration(session, NOW); +#if WITH_AFB_HOOK afb_hook_session_renew(session); +#endif session_unlock(session); } diff --git a/src/afb-supervision.c b/src/afb-supervision.c index b6af92ca..63462017 100644 --- a/src/afb-supervision.c +++ b/src/afb-supervision.c @@ -53,7 +53,9 @@ /* api and apiset name */ static const char supervision_apiname[] = AFS_SUPERVISION_APINAME; +#if WITH_AFB_TRACE static const char supervisor_apiname[] = AFS_SUPERVISOR_APINAME; +#endif /* path of the supervision socket */ static const char supervisor_socket_path[] = AFS_SUPERVISION_SOCKET; @@ -80,8 +82,10 @@ static struct afb_api_itf supervision_api_itf = /* the supervisor link */ static struct afb_stub_ws *supervisor; +#if WITH_AFB_TRACE /* the trace api */ static struct afb_trace *trace; +#endif /* open the socket */ static int open_supervisor_socket(const char *path) @@ -121,15 +125,17 @@ static int open_supervisor_socket(const char *path) static void disconnect_supervisor() { struct afb_stub_ws *s; - struct afb_trace *t; INFO("Disconnecting supervision"); s = __atomic_exchange_n(&supervisor, NULL, __ATOMIC_RELAXED); - t = __atomic_exchange_n(&trace, NULL, __ATOMIC_RELAXED); if (s) afb_stub_ws_unref(s); + +#if WITH_AFB_TRACE + struct afb_trace *t = __atomic_exchange_n(&trace, NULL, __ATOMIC_RELAXED); if (t) afb_trace_unref(t); +#endif } static void on_supervisor_hangup(struct afb_stub_ws *s) @@ -302,12 +308,16 @@ enum { Break , Config , Do , Exit , Sclose , Slist , Trace , Wait }; static void on_supervision_call(void *closure, struct afb_xreq *xreq) { - int i, rc; - struct json_object *args, *drop, *add, *sub, *list; + int i; + struct json_object *args, *sub, *list; const char *api, *verb, *uuid; struct afb_session *session; const struct afb_api_item *xapi; afb_req_t req; +#if WITH_AFB_TRACE + struct json_object *drop, *add; + int rc; +#endif /* search the verb */ i = (int)(sizeof verbs / sizeof *verbs); @@ -354,10 +364,11 @@ static void on_supervision_call(void *closure, struct afb_xreq *xreq) afb_xreq_reply(xreq, json_object_get(global.config), NULL, NULL); break; case Trace: + req = xreq_to_req_x2(xreq); +#if WITH_AFB_TRACE if (!trace) trace = afb_trace_create(supervisor_apiname, NULL /* not bound to any session */); - req = xreq_to_req_x2(xreq); add = drop = NULL; wrap_json_unpack(args, "{s?o s?o}", "add", &add, "drop", &drop); if (add) { @@ -371,6 +382,9 @@ static void on_supervision_call(void *closure, struct afb_xreq *xreq) return; } afb_req_success(req, NULL, NULL); +#else + afb_req_reply(req, NULL, "not-available", NULL); +#endif break; case Do: sub = NULL; diff --git a/src/afb-trace.c b/src/afb-trace.c index 8366b7a2..802015fa 100644 --- a/src/afb-trace.c +++ b/src/afb-trace.c @@ -15,6 +15,8 @@ * limitations under the License. */ +#if WITH_AFB_HOOK && WITH_AFB_TRACE + #define _GNU_SOURCE #include <assert.h> @@ -1605,3 +1607,5 @@ int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *tr free(context.errors); return -1; } + +#endif diff --git a/src/afb-trace.h b/src/afb-trace.h index c86ca9fd..e173e015 100644 --- a/src/afb-trace.h +++ b/src/afb-trace.h @@ -18,6 +18,13 @@ #pragma once +#if !WITH_AFB_HOOK && WITH_AFB_TRACE +# undef WITH_AFB_TRACE +# define WITH_AFB_TRACE 0 +#endif + +#if WITH_AFB_TRACE + struct afb_trace; extern struct afb_trace *afb_trace_create(const char *api, struct afb_session *bound); @@ -28,4 +35,5 @@ extern void afb_trace_unref(struct afb_trace *trace); extern int afb_trace_add(afb_req_t req, struct json_object *args, struct afb_trace *trace); extern int afb_trace_drop(afb_req_t req, struct json_object *args, struct afb_trace *trace); +#endif diff --git a/src/afb-xreq.c b/src/afb-xreq.c index c6ce4a7f..f4756a9f 100644 --- a/src/afb-xreq.c +++ b/src/afb-xreq.c @@ -53,8 +53,10 @@ static void xreq_finalize(struct afb_xreq *xreq) { if (!xreq->replied) afb_xreq_reply(xreq, NULL, "error", "no reply"); +#if WITH_AFB_HOOK if (xreq->hookflags) afb_hook_xreq_end(xreq); +#endif if (xreq->caller) afb_xreq_unhooked_unref(xreq->caller); xreq->queryitf->unref(xreq); @@ -347,6 +349,42 @@ static int xreq_subcallsync_cb( /******************************************************************************/ +const struct afb_req_x2_itf xreq_itf = { + .json = xreq_json_cb, + .get = xreq_get_cb, + .legacy_success = xreq_legacy_success_cb, + .legacy_fail = xreq_legacy_fail_cb, + .legacy_vsuccess = xreq_legacy_vsuccess_cb, + .legacy_vfail = xreq_legacy_vfail_cb, + .legacy_context_get = xreq_legacy_context_get_cb, + .legacy_context_set = xreq_legacy_context_set_cb, + .addref = xreq_addref_cb, + .unref = xreq_unref_cb, + .session_close = xreq_session_close_cb, + .session_set_LOA = xreq_session_set_LOA_cb, + .legacy_subscribe_event_x1 = xreq_legacy_subscribe_event_x1_cb, + .legacy_unsubscribe_event_x1 = xreq_legacy_unsubscribe_event_x1_cb, + .legacy_subcall = xreq_legacy_subcall_cb, + .legacy_subcallsync = xreq_legacy_subcallsync_cb, + .vverbose = xreq_vverbose_cb, + .legacy_store_req = xreq_legacy_store_cb, + .legacy_subcall_req = xreq_legacy_subcall_req_cb, + .has_permission = xreq_has_permission_cb, + .get_application_id = xreq_get_application_id_cb, + .context_make = xreq_context_make_cb, + .subscribe_event_x2 = xreq_subscribe_event_x2_cb, + .unsubscribe_event_x2 = xreq_unsubscribe_event_x2_cb, + .legacy_subcall_request = xreq_legacy_subcall_request_cb, + .get_uid = xreq_get_uid_cb, + .reply = xreq_reply_cb, + .vreply = xreq_vreply_cb, + .get_client_info = xreq_get_client_info_cb, + .subcall = xreq_subcall_cb, + .subcallsync = xreq_subcallsync_cb, +}; +/******************************************************************************/ +#if WITH_AFB_HOOK + static struct json_object *xreq_hooked_json_cb(struct afb_req_x2 *closure) { struct json_object *r = xreq_json_cb(closure); @@ -569,40 +607,6 @@ static int xreq_hooked_subcallsync_cb( /******************************************************************************/ -const struct afb_req_x2_itf xreq_itf = { - .json = xreq_json_cb, - .get = xreq_get_cb, - .legacy_success = xreq_legacy_success_cb, - .legacy_fail = xreq_legacy_fail_cb, - .legacy_vsuccess = xreq_legacy_vsuccess_cb, - .legacy_vfail = xreq_legacy_vfail_cb, - .legacy_context_get = xreq_legacy_context_get_cb, - .legacy_context_set = xreq_legacy_context_set_cb, - .addref = xreq_addref_cb, - .unref = xreq_unref_cb, - .session_close = xreq_session_close_cb, - .session_set_LOA = xreq_session_set_LOA_cb, - .legacy_subscribe_event_x1 = xreq_legacy_subscribe_event_x1_cb, - .legacy_unsubscribe_event_x1 = xreq_legacy_unsubscribe_event_x1_cb, - .legacy_subcall = xreq_legacy_subcall_cb, - .legacy_subcallsync = xreq_legacy_subcallsync_cb, - .vverbose = xreq_vverbose_cb, - .legacy_store_req = xreq_legacy_store_cb, - .legacy_subcall_req = xreq_legacy_subcall_req_cb, - .has_permission = xreq_has_permission_cb, - .get_application_id = xreq_get_application_id_cb, - .context_make = xreq_context_make_cb, - .subscribe_event_x2 = xreq_subscribe_event_x2_cb, - .unsubscribe_event_x2 = xreq_unsubscribe_event_x2_cb, - .legacy_subcall_request = xreq_legacy_subcall_request_cb, - .get_uid = xreq_get_uid_cb, - .reply = xreq_reply_cb, - .vreply = xreq_vreply_cb, - .get_client_info = xreq_get_client_info_cb, - .subcall = xreq_subcall_cb, - .subcallsync = xreq_subcallsync_cb, -}; - const struct afb_req_x2_itf xreq_hooked_itf = { .json = xreq_hooked_json_cb, .get = xreq_hooked_get_cb, @@ -636,14 +640,17 @@ const struct afb_req_x2_itf xreq_hooked_itf = { .subcall = xreq_hooked_subcall_cb, .subcallsync = xreq_hooked_subcallsync_cb, }; +#endif /******************************************************************************/ struct afb_req_x1 afb_xreq_unstore(struct afb_stored_req *sreq) { struct afb_xreq *xreq = (struct afb_xreq *)sreq; +#if WITH_AFB_HOOK if (xreq->hookflags) afb_hook_xreq_legacy_unstore(xreq); +#endif return xreq_to_req_x1(xreq); } @@ -675,39 +682,39 @@ const char *afb_xreq_raw(struct afb_xreq *xreq, size_t *size) return result; } -void afb_xreq_addref(struct afb_xreq *xreq) +void afb_xreq_unhooked_legacy_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *cb_closure) { - afb_req_x2_addref(xreq_to_req_x2(xreq)); + xreq_legacy_subcall_request_cb(xreq_to_req_x2(xreq), api, verb, args, callback, cb_closure); } -void afb_xreq_unref(struct afb_xreq *xreq) +void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_req_x2 *), void *closure) { - afb_req_x2_unref(xreq_to_req_x2(xreq)); + xreq_subcall_cb(xreq_to_req_x2(xreq), api, verb, args, flags, callback, closure); } -void afb_xreq_unhooked_legacy_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *cb_closure) +int afb_xreq_unhooked_legacy_subcall_sync(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, struct json_object **result) { - xreq_legacy_subcall_request_cb(xreq_to_req_x2(xreq), api, verb, args, callback, cb_closure); + return xreq_legacy_subcallsync_cb(xreq_to_req_x2(xreq), api, verb, args, result); } -void afb_xreq_legacy_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *cb_closure) +void afb_xreq_addref(struct afb_xreq *xreq) { - afb_req_x2_subcall_legacy(xreq_to_req_x2(xreq), api, verb, args, callback, cb_closure); + afb_req_x2_addref(xreq_to_req_x2(xreq)); } -void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_req_x2 *), void *closure) +void afb_xreq_unref(struct afb_xreq *xreq) { - xreq_subcall_cb(xreq_to_req_x2(xreq), api, verb, args, flags, callback, closure); + afb_req_x2_unref(xreq_to_req_x2(xreq)); } -void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_req_x2 *), void *closure) +void afb_xreq_legacy_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_req_x2 *), void *cb_closure) { - afb_req_x2_subcall(xreq_to_req_x2(xreq), api, verb, args, flags, callback, closure); + afb_req_x2_subcall_legacy(xreq_to_req_x2(xreq), api, verb, args, callback, cb_closure); } -int afb_xreq_unhooked_legacy_subcall_sync(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, struct json_object **result) +void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, int flags, void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_req_x2 *), void *closure) { - return xreq_legacy_subcallsync_cb(xreq_to_req_x2(xreq), api, verb, args, result); + afb_req_x2_subcall(xreq_to_req_x2(xreq), api, verb, args, flags, callback, closure); } int afb_xreq_legacy_subcall_sync(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, struct json_object **result) @@ -838,6 +845,7 @@ void afb_xreq_reply_unknown_verb(struct afb_xreq *xreq) afb_xreq_reply_f(xreq, NULL, "unknown-verb", "verb %s unknown within api %s", xreq->request.called_verb, xreq->request.called_api); } +#if WITH_AFB_HOOK static void init_hooking(struct afb_xreq *xreq) { afb_hook_init_xreq(xreq); @@ -846,6 +854,7 @@ static void init_hooking(struct afb_xreq *xreq) afb_hook_xreq_begin(xreq); } } +#endif /** * job callback for asynchronous and secured processing of the request. @@ -859,8 +868,10 @@ static void process_async(int signum, void *arg) /* emit the error (assumes that hooking is initialised) */ afb_xreq_reply_f(xreq, NULL, "aborted", "signal %s(%d) caught", strsignal(signum), signum); } else { +#if WITH_AFB_HOOK /* init hooking */ init_hooking(xreq); +#endif /* invoke api call method to process the request */ api = (const struct afb_api_item*)xreq->context.api_key; api->itf->call(api->closure, xreq); @@ -879,8 +890,10 @@ static void early_failure(struct afb_xreq *xreq, const char *status, const char { va_list args; +#if WITH_AFB_HOOK /* init hooking */ init_hooking(xreq); +#endif /* send error */ va_start(args, info); diff --git a/src/afb-xreq.h b/src/afb-xreq.h index 270de1bb..da966a44 100644 --- a/src/afb-xreq.h +++ b/src/afb-xreq.h @@ -55,8 +55,10 @@ struct afb_xreq const struct afb_xreq_query_itf *queryitf; /**< interface of xreq implementation functions */ int refcount; /**< current ref count */ int replied; /**< is replied? */ +#if WITH_AFB_HOOK int hookflags; /**< flags for hooking */ int hookindex; /**< hook index of the request if hooked */ +#endif struct afb_evt_listener *listener; /**< event listener for the request */ struct afb_cred *cred; /**< client credential if revelant */ struct afb_xreq *caller; /**< caller request if any */ diff --git a/src/main-afb-daemon.c b/src/main-afb-daemon.c index beb08d38..75706b7a 100644 --- a/src/main-afb-daemon.c +++ b/src/main-afb-daemon.c @@ -55,8 +55,10 @@ #include "afb-common.h" #include "afb-export.h" #include "afb-monitor.h" +#if WITH_AFB_HOOK #include "afb-hook.h" #include "afb-hook-flags.h" +#endif #include "afb-debug.h" #if defined(WITH_SUPERVISION) # include "afb-supervision.h" @@ -675,7 +677,13 @@ static void run_startup_calls() static void start(int signum, void *arg) { - const char *tracereq, *traceapi, *traceevt, *traceses, *tracesvc, *traceditf, *traceglob; +#if WITH_AFB_HOOK + const char *tracereq = NULL, *traceapi = NULL, *traceevt = NULL, +#if !defined(REMOVE_LEGACY_TRACE) + *tracesvc = NULL, *traceditf = NULL, +#endif + *traceses = NULL, *traceglob = NULL; +#endif const char *workdir, *rootdir, *token, *rootapi; struct json_object *settings; struct afb_hsrv *hsrv; @@ -692,19 +700,20 @@ static void start(int signum, void *arg) } settings = NULL; - token = rootapi = tracesvc = traceditf = tracereq = - traceapi = traceevt = traceses = traceglob = NULL; no_httpd = 0; http_port = -1; + rootapi = token = NULL; rc = wrap_json_unpack(main_config, "{" "ss ss s?s" "si si si" "s?b s?i s?s" - "s?o" +#if WITH_AFB_HOOK #if !defined(REMOVE_LEGACY_TRACE) "s?s s?s" #endif "s?s s?s s?s s?s s?s" +#endif + "s?o" "}", "rootdir", &rootdir, @@ -719,7 +728,7 @@ static void start(int signum, void *arg) "port", &http_port, "rootapi", &rootapi, - "set", &settings, +#if WITH_AFB_HOOK #if !defined(REMOVE_LEGACY_TRACE) "tracesvc", &tracesvc, "traceditf", &traceditf, @@ -728,7 +737,9 @@ static void start(int signum, void *arg) "traceapi", &traceapi, "traceevt", &traceevt, "traceses", &traceses, - "traceglob", &traceglob + "traceglob", &traceglob, +#endif + "set", &settings ); if (rc < 0) { ERROR("Unable to get start config"); @@ -792,6 +803,7 @@ static void start(int signum, void *arg) } #endif +#if WITH_AFB_HOOK /* install hooks */ if (tracereq) afb_hook_create_xreq(NULL, NULL, NULL, afb_hook_flags_xreq_from_text(tracereq), NULL, NULL); @@ -810,6 +822,7 @@ static void start(int signum, void *arg) afb_hook_create_session(NULL, afb_hook_flags_session_from_text(traceses), NULL, NULL); if (traceglob) afb_hook_create_global(afb_hook_flags_global_from_text(traceglob), NULL, NULL); +#endif /* load bindings and apis */ afb_debug("start-load"); diff --git a/src/tests/apiset/test-apiset.c b/src/tests/apiset/test-apiset.c index b49ade90..96fbf4b5 100644 --- a/src/tests/apiset/test-apiset.c +++ b/src/tests/apiset/test-apiset.c @@ -58,7 +58,9 @@ const char *extras[] = { struct afb_api_itf api_itf_null = { .call = NULL, .service_start = NULL, +#if WITH_AFB_HOOK .update_hooks = NULL, +#endif .get_logmask = NULL, .set_logmask = NULL, .describe = NULL, @@ -395,7 +397,9 @@ int set_cb_start(void *closure) struct afb_api_itf set_api_itf = { .call = NULL, .service_start = set_cb_start, +#if WITH_AFB_HOOK .update_hooks = set_cb0, +#endif .get_logmask = set_cb_getmask, .set_logmask = set_cb_setmask, .describe = NULL, @@ -426,7 +430,9 @@ START_TEST (check_settings) ck_assert_int_eq(nn, set_count); set_count = 0; +#if WITH_AFB_HOOK afb_apiset_update_hooks(a, NULL); +#endif ck_assert_int_eq(nn, set_count); for (mask = 1 ; !(mask >> 10) ; mask <<= 1) { @@ -505,7 +511,9 @@ int clacb_start(void *closure) struct afb_api_itf clitf = { .call = NULL, .service_start = clacb_start, +#if WITH_AFB_HOOK .update_hooks = NULL, +#endif .get_logmask = NULL, .set_logmask = NULL, .describe = NULL, diff --git a/src/tests/session/test-session.c b/src/tests/session/test-session.c index 637b0a16..fdbb0435 100644 --- a/src/tests/session/test-session.c +++ b/src/tests/session/test-session.c @@ -187,6 +187,7 @@ END_TEST /*********************************************************************/ /* check hooking */ +#if WITH_AFB_HOOK int hookflag; void on_create(void *closure, const struct afb_hookid *hookid, struct afb_session *session) @@ -299,6 +300,8 @@ START_TEST (check_hooking) } END_TEST +#endif + /*********************************************************************/ @@ -327,6 +330,8 @@ int main(int ac, char **av) addtest(check_creation); addtest(check_capacity); addtest(check_cookies); +#if WITH_AFB_HOOK addtest(check_hooking); +#endif return !!srun(); } |