+ struct afb_ditf *ditf = closure;
+ struct sd_bus *r = afb_common_get_system_bus();
+ return afb_hook_ditf_get_system_bus(ditf, r);
+}
+
+static int hooked_rootdir_get_fd(void *closure)
+{
+ struct afb_ditf *ditf = closure;
+ int r = afb_common_rootdir_get_fd();
+ return afb_hook_ditf_rootdir_get_fd(ditf, r);
+}
+
+static int hooked_rootdir_open_locale_cb(void *closure, const char *filename, int flags, const char *locale)
+{
+ struct afb_ditf *ditf = closure;
+ int r = rootdir_open_locale_cb(closure, filename, flags, locale);
+ return afb_hook_ditf_rootdir_open_locale(ditf, filename, flags, locale, r);
+}
+
+static int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
+{
+ struct afb_ditf *ditf = closure;
+ int r = queue_job_cb(closure, callback, argument, group, timeout);
+ return afb_hook_ditf_queue_job(ditf, callback, argument, group, timeout, r);
+}
+
+static const struct afb_daemon_itf daemon_itf = {
+ .vverbose_v1 = old_vverbose_cb,
+ .vverbose_v2 = vverbose_cb,
+ .event_make = event_make_cb,
+ .event_broadcast = event_broadcast_cb,
+ .get_event_loop = afb_common_get_event_loop,
+ .get_user_bus = afb_common_get_user_bus,
+ .get_system_bus = afb_common_get_system_bus,
+ .rootdir_get_fd = afb_common_rootdir_get_fd,
+ .rootdir_open_locale = rootdir_open_locale_cb,
+ .queue_job = queue_job_cb
+};
+
+static const struct afb_daemon_itf hooked_daemon_itf = {
+ .vverbose_v1 = hooked_old_vverbose_cb,
+ .vverbose_v2 = hooked_vverbose_cb,
+ .event_make = hooked_event_make_cb,
+ .event_broadcast = hooked_event_broadcast_cb,
+ .get_event_loop = hooked_get_event_loop,
+ .get_user_bus = hooked_get_user_bus,
+ .get_system_bus = hooked_get_system_bus,
+ .rootdir_get_fd = hooked_rootdir_get_fd,
+ .rootdir_open_locale = hooked_rootdir_open_locale_cb,
+ .queue_job = hooked_queue_job_cb
+};
+
+void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding_data_v2 *data)
+{
+ ditf->version = 2;
+ ditf->v2 = data;
+ data->daemon.closure = ditf;
+ afb_ditf_rename(ditf, api);
+}
+
+void afb_ditf_init_v1(struct afb_ditf *ditf, const char *api, struct afb_binding_interface_v1 *itf)
+{
+ ditf->version = 1;
+ ditf->v1 = itf;
+ itf->verbosity = verbosity;
+ itf->mode = AFB_MODE_LOCAL;
+ itf->daemon.closure = ditf;
+ afb_ditf_rename(ditf, api);
+}
+
+void afb_ditf_rename(struct afb_ditf *ditf, const char *api)
+{
+ ditf->api = api;
+ afb_ditf_update_hook(ditf);
+}
+
+void afb_ditf_update_hook(struct afb_ditf *ditf)
+{
+ int hooked = !!afb_hook_flags_ditf(ditf->api);
+ switch (ditf->version) {
+ case 1:
+ ditf->v1->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf;
+ break;
+ default:
+ case 2:
+ ditf->v2->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf;
+ break;
+ }