2 * Copyright (C) 2017 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO
26 #include <json-c/json.h>
27 #include <afb/afb-binding-v1.h>
28 #include <afb/afb-binding-v2.h>
30 #include "afb-context.h"
33 #include "afb-msg-json.h"
37 #include "afb-apiset.h"
42 /******************************************************************************/
44 static inline void xreq_addref(struct afb_xreq *xreq)
46 __atomic_add_fetch(&xreq->refcount, 1, __ATOMIC_RELAXED);
49 static inline void xreq_unref(struct afb_xreq *xreq)
51 if (!__atomic_sub_fetch(&xreq->refcount, 1, __ATOMIC_RELAXED)) {
53 afb_hook_xreq_end(xreq);
54 xreq->queryitf->unref(xreq);
58 /******************************************************************************/
63 struct afb_xreq *caller;
64 void (*callback)(void*, int, struct json_object*);
68 struct jobloop *jobloop;
69 struct json_object *result;
73 void (*callback)(void*, int, struct json_object*);
79 static int subcall_subscribe(struct afb_xreq *xreq, struct afb_event event)
81 struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
83 return afb_xreq_subscribe(subcall->caller, event);
86 static int subcall_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
88 struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
90 return afb_xreq_unsubscribe(subcall->caller, event);
93 static void subcall_reply(struct afb_xreq *xreq, int status, struct json_object *obj)
95 struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
97 if (subcall->callback)
98 subcall->callback(subcall->closure, status, obj);
102 static void subcall_destroy(struct afb_xreq *xreq)
104 struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
106 json_object_put(subcall->xreq.json);
107 afb_cred_unref(subcall->xreq.cred);
108 xreq_unref(subcall->caller);
112 const struct afb_xreq_query_itf afb_xreq_subcall_itf = {
113 .reply = subcall_reply,
114 .unref = subcall_destroy,
115 .subscribe = subcall_subscribe,
116 .unsubscribe = subcall_unsubscribe
119 static struct subcall *subcall_alloc(
120 struct afb_xreq *caller,
123 struct json_object *args
126 struct subcall *subcall;
127 size_t lenapi, lenverb;
130 lenapi = 1 + strlen(api);
131 lenverb = 1 + strlen(verb);
132 subcall = malloc(lenapi + lenverb + sizeof *subcall);
134 ERROR("out of memory");
136 copy = (char*)&subcall[1];
137 memcpy(copy, api, lenapi);
139 copy = ©[lenapi];
140 memcpy(copy, verb, lenverb);
143 afb_xreq_init(&subcall->xreq, &afb_xreq_subcall_itf);
144 afb_context_subinit(&subcall->xreq.context, &caller->context);
145 subcall->xreq.cred = afb_cred_addref(caller->cred);
146 subcall->xreq.json = args;
147 subcall->xreq.api = api;
148 subcall->xreq.verb = verb;
149 subcall->caller = caller;
155 static void subcall_process(struct subcall *subcall)
157 if (subcall->caller->queryitf->subcall) {
158 subcall->caller->queryitf->subcall(
159 subcall->caller, subcall->xreq.api, subcall->xreq.verb,
160 subcall->xreq.json, subcall->callback, subcall->closure);
161 xreq_unref(&subcall->xreq);
163 afb_xreq_process(&subcall->xreq, subcall->caller->apiset);
166 static void subcall_sync_leave(struct subcall *subcall)
168 struct jobloop *jobloop = __atomic_exchange_n(&subcall->jobloop, NULL, __ATOMIC_RELAXED);
173 static void subcall_sync_reply(void *closure, int status, struct json_object *obj)
175 struct subcall *subcall = closure;
177 subcall->status = status;
178 subcall->result = json_object_get(obj);
179 subcall_sync_leave(subcall);
182 static void subcall_sync_enter(int signum, void *closure, struct jobloop *jobloop)
184 struct subcall *subcall = closure;
187 subcall->jobloop = jobloop;
188 subcall_process(subcall);
190 subcall->status = -1;
191 subcall_sync_leave(subcall);
195 /******************************************************************************/
197 static void vinfo(void *first, void *second, const char *fmt, va_list args, void (*fun)(void*,void*,const char*))
200 if (fmt == NULL || vasprintf(&info, fmt, args) < 0)
202 fun(first, second, info);
206 /******************************************************************************/
208 static struct json_object *xreq_json_cb(void *closure)
210 struct afb_xreq *xreq = closure;
211 if (!xreq->json && xreq->queryitf->json)
212 xreq->json = xreq->queryitf->json(xreq);
216 static struct afb_arg xreq_get_cb(void *closure, const char *name)
218 struct afb_xreq *xreq = closure;
220 struct json_object *object, *value;
222 if (xreq->queryitf->get)
223 arg = xreq->queryitf->get(xreq, name);
225 object = xreq_json_cb(closure);
226 if (json_object_object_get_ex(object, name, &value)) {
228 arg.value = json_object_get_string(value);
238 static void xreq_success_cb(void *closure, struct json_object *obj, const char *info)
240 struct afb_xreq *xreq = closure;
243 ERROR("reply called more than one time!!");
244 json_object_put(obj);
247 if (xreq->queryitf->success)
248 xreq->queryitf->success(xreq, obj, info);
250 xreq->queryitf->reply(xreq, 0, afb_msg_json_reply_ok(info, obj, &xreq->context, NULL));
254 static void xreq_fail_cb(void *closure, const char *status, const char *info)
256 struct afb_xreq *xreq = closure;
259 ERROR("reply called more than one time!!");
262 if (xreq->queryitf->fail)
263 xreq->queryitf->fail(xreq, status, info);
265 xreq->queryitf->reply(xreq, -1, afb_msg_json_reply_error(status, info, &xreq->context, NULL));
269 static void xreq_vsuccess_cb(void *closure, struct json_object *obj, const char *fmt, va_list args)
271 vinfo(closure, obj, fmt, args, (void*)xreq_success_cb);
274 static void xreq_vfail_cb(void *closure, const char *status, const char *fmt, va_list args)
276 vinfo(closure, (void*)status, fmt, args, (void*)xreq_fail_cb);
279 static void *xreq_context_get_cb(void *closure)
281 struct afb_xreq *xreq = closure;
282 return afb_context_get(&xreq->context);
285 static void xreq_context_set_cb(void *closure, void *value, void (*free_value)(void*))
287 struct afb_xreq *xreq = closure;
288 afb_context_set(&xreq->context, value, free_value);
291 static void xreq_addref_cb(void *closure)
293 struct afb_xreq *xreq = closure;
297 static void xreq_unref_cb(void *closure)
299 struct afb_xreq *xreq = closure;
303 static void xreq_session_close_cb(void *closure)
305 struct afb_xreq *xreq = closure;
306 afb_context_close(&xreq->context);
309 static int xreq_session_set_LOA_cb(void *closure, unsigned level)
311 struct afb_xreq *xreq = closure;
312 return afb_context_change_loa(&xreq->context, level);
315 static int xreq_subscribe_cb(void *closure, struct afb_event event)
317 struct afb_xreq *xreq = closure;
318 return afb_xreq_subscribe(xreq, event);
321 int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_event event)
324 return afb_evt_add_watch(xreq->listener, event);
325 if (xreq->queryitf->subscribe)
326 return xreq->queryitf->subscribe(xreq, event);
327 ERROR("no event listener, subscription impossible");
332 static int xreq_unsubscribe_cb(void *closure, struct afb_event event)
334 struct afb_xreq *xreq = closure;
335 return afb_xreq_unsubscribe(xreq, event);
338 int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
341 return afb_evt_remove_watch(xreq->listener, event);
342 if (xreq->queryitf->unsubscribe)
343 return xreq->queryitf->unsubscribe(xreq, event);
344 ERROR("no event listener, unsubscription impossible");
349 static void xreq_subcall_cb(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
351 struct afb_xreq *xreq = closure;
352 struct subcall *subcall;
354 subcall = subcall_alloc(xreq, api, verb, args);
355 if (subcall == NULL) {
357 callback(cb_closure, 1, afb_msg_json_internal_error());
358 json_object_put(args);
360 subcall->callback = callback;
361 subcall->closure = cb_closure;
362 subcall_process(subcall);
366 static int xreq_subcallsync_cb(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result)
369 struct subcall *subcall;
370 struct afb_xreq *xreq = closure;
371 struct json_object *resu;
373 subcall = subcall_alloc(xreq, api, verb, args);
376 resu = afb_msg_json_internal_error();
377 json_object_put(args);
379 subcall->callback = subcall_sync_reply;
380 subcall->closure = subcall;
381 subcall->jobloop = NULL;
382 subcall->result = NULL;
384 rc = jobs_enter(NULL, 0, subcall_sync_enter, subcall);
385 resu = subcall->result;
386 if (rc < 0 || subcall->status < 0) {
387 resu = resu ?: afb_msg_json_internal_error();
394 json_object_put(resu);
398 static void xreq_vverbose_cb(void*closure, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
400 /* TODO: improves the implementation. example: on condition make a list of log messages that will be returned */
401 vverbose(level, file, line, func, fmt, args);
404 static struct afb_stored_req *xreq_store_cb(void *closure)
406 xreq_addref_cb(closure);
410 /******************************************************************************/
412 static struct json_object *xreq_hooked_json_cb(void *closure)
414 struct json_object *r = xreq_json_cb(closure);
415 struct afb_xreq *xreq = closure;
416 return afb_hook_xreq_json(xreq, r);
419 static struct afb_arg xreq_hooked_get_cb(void *closure, const char *name)
421 struct afb_arg r = xreq_get_cb(closure, name);
422 struct afb_xreq *xreq = closure;
423 return afb_hook_xreq_get(xreq, name, r);
426 static void xreq_hooked_success_cb(void *closure, struct json_object *obj, const char *info)
428 struct afb_xreq *xreq = closure;
429 afb_hook_xreq_success(xreq, obj, info);
430 xreq_success_cb(closure, obj, info);
433 static void xreq_hooked_fail_cb(void *closure, const char *status, const char *info)
435 struct afb_xreq *xreq = closure;
436 afb_hook_xreq_fail(xreq, status, info);
437 xreq_fail_cb(closure, status, info);
440 static void xreq_hooked_vsuccess_cb(void *closure, struct json_object *obj, const char *fmt, va_list args)
442 vinfo(closure, obj, fmt, args, (void*)xreq_hooked_success_cb);
445 static void xreq_hooked_vfail_cb(void *closure, const char *status, const char *fmt, va_list args)
447 vinfo(closure, (void*)status, fmt, args, (void*)xreq_hooked_fail_cb);
450 static void *xreq_hooked_context_get_cb(void *closure)
452 void *r = xreq_context_get_cb(closure);
453 struct afb_xreq *xreq = closure;
454 return afb_hook_xreq_context_get(xreq, r);
457 static void xreq_hooked_context_set_cb(void *closure, void *value, void (*free_value)(void*))
459 struct afb_xreq *xreq = closure;
460 afb_hook_xreq_context_set(xreq, value, free_value);
461 xreq_context_set_cb(closure, value, free_value);
464 static void xreq_hooked_addref_cb(void *closure)
466 struct afb_xreq *xreq = closure;
467 afb_hook_xreq_addref(xreq);
468 xreq_addref_cb(closure);
471 static void xreq_hooked_unref_cb(void *closure)
473 struct afb_xreq *xreq = closure;
474 afb_hook_xreq_unref(xreq);
475 xreq_unref_cb(closure);
478 static void xreq_hooked_session_close_cb(void *closure)
480 struct afb_xreq *xreq = closure;
481 afb_hook_xreq_session_close(xreq);
482 xreq_session_close_cb(closure);
485 static int xreq_hooked_session_set_LOA_cb(void *closure, unsigned level)
487 int r = xreq_session_set_LOA_cb(closure, level);
488 struct afb_xreq *xreq = closure;
489 return afb_hook_xreq_session_set_LOA(xreq, level, r);
492 static int xreq_hooked_subscribe_cb(void *closure, struct afb_event event)
494 int r = xreq_subscribe_cb(closure, event);
495 struct afb_xreq *xreq = closure;
496 return afb_hook_xreq_subscribe(xreq, event, r);
499 static int xreq_hooked_unsubscribe_cb(void *closure, struct afb_event event)
501 int r = xreq_unsubscribe_cb(closure, event);
502 struct afb_xreq *xreq = closure;
503 return afb_hook_xreq_unsubscribe(xreq, event, r);
506 static void xreq_hooked_subcall_reply_cb(void *closure, int status, struct json_object *result)
508 struct subcall *subcall = closure;
510 afb_hook_xreq_subcall_result(subcall->caller, status, result);
511 subcall->hooked.callback(subcall->hooked.closure, status, result);
514 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)
516 struct afb_xreq *xreq = closure;
517 struct subcall *subcall;
519 afb_hook_xreq_subcall(xreq, api, verb, args);
520 subcall = subcall_alloc(xreq, api, verb, args);
521 if (subcall == NULL) {
523 callback(cb_closure, 1, afb_msg_json_internal_error());
524 json_object_put(args);
526 subcall->callback = xreq_hooked_subcall_reply_cb;
527 subcall->closure = subcall;
528 subcall->hooked.callback = callback;
529 subcall->hooked.closure = cb_closure;
530 subcall_process(subcall);
534 static int xreq_hooked_subcallsync_cb(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result)
537 struct afb_xreq *xreq = closure;
538 afb_hook_xreq_subcallsync(xreq, api, verb, args);
539 r = xreq_subcallsync_cb(closure, api, verb, args, result);
540 return afb_hook_xreq_subcallsync_result(xreq, r, *result);
543 static void xreq_hooked_vverbose_cb(void*closure, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
545 struct afb_xreq *xreq = closure;
548 xreq_vverbose_cb(closure, level, file, line, func, fmt, args);
549 afb_hook_xreq_vverbose(xreq, level, file, line, func, fmt, ap);
553 static struct afb_stored_req *xreq_hooked_store_cb(void *closure)
555 struct afb_xreq *xreq = closure;
556 struct afb_stored_req *r = xreq_store_cb(closure);
557 afb_hook_xreq_store(xreq, r);
561 /******************************************************************************/
563 const struct afb_req_itf xreq_itf = {
564 .json = xreq_json_cb,
566 .success = xreq_success_cb,
567 .fail = xreq_fail_cb,
568 .vsuccess = xreq_vsuccess_cb,
569 .vfail = xreq_vfail_cb,
570 .context_get = xreq_context_get_cb,
571 .context_set = xreq_context_set_cb,
572 .addref = xreq_addref_cb,
573 .unref = xreq_unref_cb,
574 .session_close = xreq_session_close_cb,
575 .session_set_LOA = xreq_session_set_LOA_cb,
576 .subscribe = xreq_subscribe_cb,
577 .unsubscribe = xreq_unsubscribe_cb,
578 .subcall = xreq_subcall_cb,
579 .subcallsync = xreq_subcallsync_cb,
580 .vverbose = xreq_vverbose_cb,
581 .store = xreq_store_cb
584 const struct afb_req_itf xreq_hooked_itf = {
585 .json = xreq_hooked_json_cb,
586 .get = xreq_hooked_get_cb,
587 .success = xreq_hooked_success_cb,
588 .fail = xreq_hooked_fail_cb,
589 .vsuccess = xreq_hooked_vsuccess_cb,
590 .vfail = xreq_hooked_vfail_cb,
591 .context_get = xreq_hooked_context_get_cb,
592 .context_set = xreq_hooked_context_set_cb,
593 .addref = xreq_hooked_addref_cb,
594 .unref = xreq_hooked_unref_cb,
595 .session_close = xreq_hooked_session_close_cb,
596 .session_set_LOA = xreq_hooked_session_set_LOA_cb,
597 .subscribe = xreq_hooked_subscribe_cb,
598 .unsubscribe = xreq_hooked_unsubscribe_cb,
599 .subcall = xreq_hooked_subcall_cb,
600 .subcallsync = xreq_hooked_subcallsync_cb,
601 .vverbose = xreq_hooked_vverbose_cb,
602 .store = xreq_hooked_store_cb
605 static inline struct afb_req to_req(struct afb_xreq *xreq)
607 return (struct afb_req){ .itf = xreq->hookflags ? &xreq_hooked_itf : &xreq_itf, .closure = xreq };
610 /******************************************************************************/
612 struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq)
614 struct afb_xreq *xreq = (struct afb_xreq *)sreq;
616 afb_hook_xreq_unstore(xreq);
620 struct json_object *afb_xreq_json(struct afb_xreq *xreq)
622 return afb_req_json(to_req(xreq));
625 void afb_xreq_success(struct afb_xreq *xreq, struct json_object *obj, const char *info)
627 afb_req_success(to_req(xreq), obj, info);
630 void afb_xreq_success_f(struct afb_xreq *xreq, struct json_object *obj, const char *info, ...)
634 va_start(args, info);
635 if (info == NULL || vasprintf(&message, info, args) < 0)
638 afb_xreq_success(xreq, obj, message);
642 void afb_xreq_fail(struct afb_xreq *xreq, const char *status, const char *info)
644 afb_req_fail(to_req(xreq), status, info);
647 void afb_xreq_fail_f(struct afb_xreq *xreq, const char *status, const char *info, ...)
651 va_start(args, info);
652 if (info == NULL || vasprintf(&message, info, args) < 0)
655 afb_xreq_fail(xreq, status, message);
659 const char *afb_xreq_raw(struct afb_xreq *xreq, size_t *size)
661 struct json_object *obj = xreq_json_cb(xreq);
662 const char *result = json_object_to_json_string(obj);
664 *size = strlen(result);
668 void afb_xreq_addref(struct afb_xreq *xreq)
670 afb_req_addref(to_req(xreq));
673 void afb_xreq_unref(struct afb_xreq *xreq)
675 afb_req_unref(to_req(xreq));
678 void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
680 xreq_subcall_cb(xreq, api, verb, args, callback, cb_closure);
683 void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
685 afb_req_subcall(to_req(xreq), api, verb, args, callback, cb_closure);
688 int afb_xreq_unhooked_subcall_sync(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, struct json_object **result)
690 return xreq_subcallsync_cb(xreq, api, verb, args, result);
693 int afb_xreq_subcall_sync(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, struct json_object **result)
695 return afb_req_subcall_sync(to_req(xreq), api, verb, args, result);
698 static int xreq_session_check_apply_v1(struct afb_xreq *xreq, int sessionflags)
702 if ((sessionflags & (AFB_SESSION_CLOSE_V1|AFB_SESSION_RENEW_V1|AFB_SESSION_CHECK_V1|AFB_SESSION_LOA_EQ_V1)) != 0) {
703 if (!afb_context_check(&xreq->context)) {
704 afb_context_close(&xreq->context);
705 afb_xreq_fail_f(xreq, "denied", "invalid token's identity");
711 if ((sessionflags & AFB_SESSION_LOA_GE_V1) != 0) {
712 loa = (sessionflags >> AFB_SESSION_LOA_SHIFT_V1) & AFB_SESSION_LOA_MASK_V1;
713 if (!afb_context_check_loa(&xreq->context, loa)) {
714 afb_xreq_fail_f(xreq, "denied", "invalid LOA");
720 if ((sessionflags & AFB_SESSION_LOA_LE_V1) != 0) {
721 loa = (sessionflags >> AFB_SESSION_LOA_SHIFT_V1) & AFB_SESSION_LOA_MASK_V1;
722 if (afb_context_check_loa(&xreq->context, loa + 1)) {
723 afb_xreq_fail_f(xreq, "denied", "invalid LOA");
729 if ((sessionflags & AFB_SESSION_RENEW_V1) != 0) {
730 afb_context_refresh(&xreq->context);
732 if ((sessionflags & AFB_SESSION_CLOSE_V1) != 0) {
733 afb_context_change_loa(&xreq->context, 0);
734 afb_context_close(&xreq->context);
740 static int xreq_session_check_apply_v2(struct afb_xreq *xreq, uint32_t sessionflags, const struct afb_auth *auth)
744 if (sessionflags != 0) {
745 if (!afb_context_check(&xreq->context)) {
746 afb_context_close(&xreq->context);
747 afb_xreq_fail_f(xreq, "denied", "invalid token's identity");
753 loa = (int)(sessionflags & AFB_SESSION_LOA_MASK_V2);
754 if (loa && !afb_context_check_loa(&xreq->context, loa)) {
755 afb_xreq_fail_f(xreq, "denied", "invalid LOA");
760 if (auth && !afb_auth_check(auth, xreq)) {
761 afb_xreq_fail_f(xreq, "denied", "authorisation refused");
766 if ((sessionflags & AFB_SESSION_REFRESH_V2) != 0) {
767 afb_context_refresh(&xreq->context);
769 if ((sessionflags & AFB_SESSION_CLOSE_V2) != 0) {
770 afb_context_close(&xreq->context);
776 void afb_xreq_call_verb_v1(struct afb_xreq *xreq, const struct afb_verb_desc_v1 *verb)
779 afb_xreq_fail_unknown_verb(xreq);
781 if (!xreq_session_check_apply_v1(xreq, verb->session))
782 verb->callback(to_req(xreq));
785 void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb)
788 afb_xreq_fail_unknown_verb(xreq);
790 if (!xreq_session_check_apply_v2(xreq, verb->session, verb->auth))
791 verb->callback(to_req(xreq));
794 void afb_xreq_init(struct afb_xreq *xreq, const struct afb_xreq_query_itf *queryitf)
796 memset(xreq, 0, sizeof *xreq);
798 xreq->queryitf = queryitf;
801 void afb_xreq_fail_unknown_api(struct afb_xreq *xreq)
803 afb_xreq_fail_f(xreq, "unknown-api", "api %s not found (for verb %s)", xreq->api, xreq->verb);
806 void afb_xreq_fail_unknown_verb(struct afb_xreq *xreq)
808 afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->verb, xreq->api);
811 static void process_sync(struct afb_xreq *xreq)
816 afb_hook_init_xreq(xreq);
818 afb_hook_xreq_begin(xreq);
821 if (afb_apiset_get_started(xreq->apiset, xreq->api, &api) < 0) {
823 afb_xreq_fail_f(xreq, "unknown-api", "api %s not found", xreq->api);
825 afb_xreq_fail_f(xreq, "bad-api-state", "api %s not started correctly: %m", xreq->api);
827 xreq->context.api_key = api.closure;
828 api.itf->call(api.closure, xreq);
832 static void process_async(int signum, void *arg)
834 struct afb_xreq *xreq = arg;
837 afb_xreq_fail_f(xreq, "aborted", "signal %s(%d) caught", strsignal(signum), signum);
844 void afb_xreq_process(struct afb_xreq *xreq, struct afb_apiset *apiset)
846 xreq->apiset = apiset;
849 if (jobs_queue(NULL, afb_apiset_timeout_get(apiset), process_async, xreq) < 0) {
850 /* TODO: allows or not to proccess it directly as when no threading? (see above) */
851 ERROR("can't process job with threads: %m");
852 afb_xreq_fail_f(xreq, "cancelled", "not able to create a job for the task");