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' )
############################################################################
# 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
{
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);
return ret;
}
+#if WITH_AFB_HOOK
/**
* Ask to update the hook flags of the 'api'
* @param set the api set
d->api.itf->update_hooks(d->api.closure);
}
}
+#endif
/**
* Set the logmask of the 'api' to 'mask'
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);
#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;
{
struct callreq *callreq = CONTAINER_OF_XREQ(struct callreq, xreq);
+#if WITH_AFB_HOOK
/* centralized hooking */
if (callreq->mode.hooked) {
if (callreq->mode.sync) {
afb_hook_api_call_result(callreq->export, object, error, info);
}
}
+#endif
/* true report of the result */
if (callreq->mode.sync) {
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,
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,
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(
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
/******************************************************************************/
/******************************************************************************/
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(
json_object_put(object);
return rc;
}
+#endif
/******************************************************************************/
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(
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
+
struct afb_req_x2;
/******************************************************************************/
-
extern
void afb_calls_call(
struct afb_export *export,
void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*),
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,
char **error,
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,
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(
char **error,
char **info);
+#endif /* WITH_AFB_HOOK */
/******************************************************************************/
extern
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(
struct json_object *args,
struct json_object **result);
+#endif /* WITH_AFB_HOOK */
/******************************************************************************/
extern
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(
const char *verb,
struct json_object *args,
struct json_object **result);
+
+#endif /* WITH_AFB_HOOK */
+/******************************************************************************/
{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"},
#if !defined(REMOVE_LEGACY_TRACE)
{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"},
fprintf(file,
"\n"
" AGL Framework Binder [AFB %s] "
+
#if defined(WITH_DBUS_TRANSPARENCY)
"+"
#else
"-"
#endif
"DBUS "
+
#if defined(WITH_MONITORING_OPTION)
"+"
#else
#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
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);
break;
+#if WITH_AFB_HOOK
case SET_TRACEREQ:
config_set_optenum(config, optid, afb_hook_flags_xreq_from_text);
break;
case SET_TRACESVC:
config_set_optenum(config, optid, afb_hook_flags_legacy_svc_from_text);
break;
+#endif
#endif
case SET_EXEC:
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);
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");
}
/* rwlock of the event */
pthread_rwlock_t rwlock;
+#if WITH_AFB_HOOK
/* hooking */
int hookflags;
+#endif
/* refcount */
int refcount;
.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;
return result;
}
+/*
+ * 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)
return result;
}
-/*
- * 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);
-}
-
/*
* Broadcasts the event 'evtid' with its 'object'
* 'object' is released (like json_object_put)
{
return hooked_broadcast(evtid->fullname, object, evtid->id, evtid->hookflags);
}
+#endif
/*
* Broadcasts the 'event' with its '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
}
/*
return result;
}
-/*
- * 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'
*/
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 */
return 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
}
}
-/*
- * 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'
*/
return name ? name + 1 : evtid->fullname;
}
-/*
- * 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'
*/
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;
}
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)
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)
{
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 };
}
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
+
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);
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
/* unsealed */
unsigned unsealed: 1;
+#if WITH_AFB_HOOK
/* hooking flags */
int hookditf;
int hooksvc;
+#endif
/* session for service */
struct afb_session *session;
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);
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,
.add_alias = hooked_add_alias_cb,
.new_api = hooked_api_new_api_cb,
};
+#endif
/******************************************************************************
******************************************************************************
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,
return afb_calls_legacy_hooked_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
-};
-
/* 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
/******************************************************************************
******************************************************************************
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)
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,
.delete_api = hooked_delete_api_cb,
.settings = hooked_settings_cb,
};
+#endif
/******************************************************************************
******************************************************************************
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)
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);
}
******************************************************************************
******************************************************************************/
+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,
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;
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;
}
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;
}
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;
}
free((void*)export->api.apiname);
export->api.apiname = name;
- afb_export_update_hooks(export);
+ set_interfaces(export);
return 0;
}
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) {
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
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;
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 */
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)
{
{
.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,
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);
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;
* limitations under the License.
*/
+#if WITH_AFB_HOOK /***********************************************************/
+
#define _GNU_SOURCE
#include <stdlib.h>
}
#endif
+#endif /* WITH_AFB_HOOK *******************************************************/
#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);
extern char *afb_hook_flags_legacy_svc_to_text(int value);
#endif
+#endif /* WITH_AFB_HOOK *******************************************************/
* limitations under the License.
*/
+#if WITH_AFB_HOOK /***********************************************************/
+
#define _GNU_SOURCE
#include <limits.h>
}
}
+#endif /* WITH_AFB_HOOK *******************************************************/
#pragma once
+#if WITH_AFB_HOOK /***********************************************************/
+
#include <stdarg.h>
#include <time.h>
extern void afb_hook_unref_global(struct afb_hook_global *hook);
+#endif /* WITH_AFB_HOOK *******************************************************/
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);
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)
{
/* 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++) {
/* 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);
return NULL;
}
+#if WITH_AFB_HOOK
afb_hook_session_create(session);
+#endif
return session;
}
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);
if (session == NULL)
return;
+#if WITH_AFB_HOOK
afb_hook_session_unref(session);
+#endif
session_lock(session);
if (!--session->refcount) {
if (session->autoclose)
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);
}
/* 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;
/* 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)
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)
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);
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) {
return;
}
afb_req_success(req, NULL, NULL);
+#else
+ afb_req_reply(req, NULL, "not-available", NULL);
+#endif
break;
case Do:
sub = NULL;
* limitations under the License.
*/
+#if WITH_AFB_HOOK && WITH_AFB_TRACE
+
#define _GNU_SOURCE
#include <assert.h>
free(context.errors);
return -1;
}
+
+#endif
#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);
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
{
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);
/******************************************************************************/
+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);
/******************************************************************************/
-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,
.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);
}
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)
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);
afb_hook_xreq_begin(xreq);
}
}
+#endif
/**
* job callback for asynchronous and secured processing of the request.
/* 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);
{
va_list args;
+#if WITH_AFB_HOOK
/* init hooking */
init_hooking(xreq);
+#endif
/* send error */
va_start(args, info);
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 */
#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"
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;
}
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,
"port", &http_port,
"rootapi", &rootapi,
- "set", &settings,
+#if WITH_AFB_HOOK
#if !defined(REMOVE_LEGACY_TRACE)
"tracesvc", &tracesvc,
"traceditf", &traceditf,
"traceapi", &traceapi,
"traceevt", &traceevt,
"traceses", &traceses,
- "traceglob", &traceglob
+ "traceglob", &traceglob,
+#endif
+ "set", &settings
);
if (rc < 0) {
ERROR("Unable to get start config");
}
#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);
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");
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,
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,
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) {
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,
/*********************************************************************/
/* check hooking */
+#if WITH_AFB_HOOK
int hookflag;
void on_create(void *closure, const struct afb_hookid *hookid, struct afb_session *session)
}
END_TEST
+#endif
+
/*********************************************************************/
addtest(check_creation);
addtest(check_capacity);
addtest(check_cookies);
+#if WITH_AFB_HOOK
addtest(check_hooking);
+#endif
return !!srun();
}