+static void xreq_hooked_session_close_cb(void *closure)
+{
+ struct afb_xreq *xreq = closure;
+ afb_hook_xreq_session_close(xreq);
+ xreq_session_close_cb(closure);
+}
+
+static int xreq_hooked_session_set_LOA_cb(void *closure, unsigned level)
+{
+ int r = xreq_session_set_LOA_cb(closure, level);
+ struct afb_xreq *xreq = closure;
+ return afb_hook_xreq_session_set_LOA(xreq, level, r);
+}
+
+static int xreq_hooked_subscribe_cb(void *closure, struct afb_event event)
+{
+ int r = xreq_subscribe_cb(closure, event);
+ struct afb_xreq *xreq = closure;
+ return afb_hook_xreq_subscribe(xreq, event, r);
+}
+
+static int xreq_hooked_unsubscribe_cb(void *closure, struct afb_event event)
+{
+ int r = xreq_unsubscribe_cb(closure, event);
+ struct afb_xreq *xreq = closure;
+ return afb_hook_xreq_unsubscribe(xreq, event, r);
+}
+
+/*
+static void xreq_hooked_subcall_cb(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
+{
+ struct afb_xreq *xreq = closure;
+
+ afb_xreq_subcall(xreq, api, verb, args, callback, cb_closure);
+}
+
+static int xreq_hooked_subcallsync_cb(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result)
+{
+ struct afb_xreq *xreq = closure;
+ return afb_subcall_sync(xreq, api, verb, args, result);
+}
+*/
+const struct afb_req_itf xreq_itf = {
+ .json = xreq_json_cb,
+ .get = xreq_get_cb,
+ .success = xreq_success_cb,
+ .fail = xreq_fail_cb,
+ .raw = xreq_raw_cb,
+ .send = xreq_send_cb,
+ .context_get = xreq_context_get_cb,
+ .context_set = xreq_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,
+ .subscribe = xreq_subscribe_cb,
+ .unsubscribe = xreq_unsubscribe_cb,
+ .subcall = xreq_subcall_cb,
+ .subcallsync = xreq_subcallsync_cb
+};
+
+const struct afb_req_itf xreq_hooked_itf = {
+ .json = xreq_hooked_json_cb,
+ .get = xreq_hooked_get_cb,
+ .success = xreq_hooked_success_cb,
+ .fail = xreq_hooked_fail_cb,
+ .raw = xreq_hooked_raw_cb,
+ .send = xreq_hooked_send_cb,
+ .context_get = xreq_hooked_context_get_cb,
+ .context_set = xreq_hooked_context_set_cb,
+ .addref = xreq_hooked_addref_cb,
+.unref = xreq_unref_cb,
+ .session_close = xreq_hooked_session_close_cb,
+ .session_set_LOA = xreq_hooked_session_set_LOA_cb,
+ .subscribe = xreq_hooked_subscribe_cb,
+ .unsubscribe = xreq_hooked_unsubscribe_cb,
+.subcall = xreq_subcall_cb,
+.subcallsync = xreq_subcallsync_cb
+};
+
+static inline struct afb_req to_req(struct afb_xreq *xreq)
+{
+ return (struct afb_req){ .itf = xreq->hookflags ? &xreq_hooked_itf : &xreq_itf, .closure = xreq };