+ struct afb_svc *svc = closure;
+ struct svc_req *svcreq;
+
+ /* allocates the request */
+ svcreq = calloc(1, sizeof *svcreq);
+ if (svcreq == NULL) {
+ ERROR("out of memory");
+ json_object_put(args);
+ callback(cbclosure, 1, afb_msg_json_internal_error());
+ return;
+ }
+
+ /* initialises the request */
+ afb_xreq_init(&svcreq->xreq, &afb_svc_xreq_itf);
+ afb_context_init(&svcreq->xreq.context, svc->session, NULL);
+ svcreq->xreq.context.validated = 1;
+ svcreq->xreq.cred = afb_cred_current();
+ svcreq->xreq.api = api;
+ svcreq->xreq.verb = verb;
+ svcreq->xreq.listener = svc->listener;
+ svcreq->xreq.json = args;
+ svcreq->callback = callback;
+ svcreq->closure = cbclosure;
+
+ /* terminates and frees ressources if needed */
+ afb_xreq_process(&svcreq->xreq, svc->apiset);