+struct xreq_sync
+{
+ struct afb_xreq *caller;
+ const char *api;
+ const char *verb;
+ struct json_object *args;
+ struct jobloop *jobloop;
+ struct json_object *result;
+ int iserror;
+};
+
+static void xreq_sync_leave(struct xreq_sync *sync)
+{
+ struct jobloop *jobloop = sync->jobloop;
+ if (jobloop) {
+ sync->jobloop = NULL;
+ jobs_leave(jobloop);
+ }
+}
+
+static void xreq_sync_reply(void *closure, int iserror, struct json_object *obj)
+{
+ struct xreq_sync *sync = closure;
+
+ sync->iserror = iserror;
+ sync->result = json_object_get(obj);
+ xreq_sync_leave(sync);
+}
+
+static void xreq_sync_enter(int signum, void *closure, struct jobloop *jobloop)
+{
+ struct xreq_sync *sync = closure;
+
+ if (!signum) {
+ sync->jobloop = jobloop;
+ xreq_subcall_cb(sync->caller, sync->api, sync->verb, sync->args, xreq_sync_reply, sync);
+ } else {
+ sync->iserror = 1;
+ xreq_sync_leave(sync);
+ }
+}
+