- char *message;
- va_list args;
- va_start(args, info);
- if (info == NULL || vasprintf(&message, info, args) < 0)
- message = NULL;
- va_end(args);
- afb_req_fail(req, status, message);
- free(message);
-}
-
-/*
- * Gets the pointer stored by the binding for the session of 'req'.
- * When the binding has not yet recorded a pointer, NULL is returned.
- */
-static inline void *afb_req_context_get(struct afb_req req)
-{
- return req.itf->context_get(req.closure);
-}
-
-/*
- * Stores for the binding the pointer 'context' to the session of 'req'.
- * The function 'free_context' will be called when the session is closed
- * or if binding stores an other pointer.
- */
-static inline void afb_req_context_set(struct afb_req req, void *context, void (*free_context)(void*))
-{
- req.itf->context_set(req.closure, context, free_context);
-}
-
-/*
- * Gets the pointer stored by the binding for the session of 'req'.
- * If the stored pointer is NULL, indicating that no pointer was
- * already stored, afb_req_context creates a new context by calling
- * the function 'create_context' and stores it with the freeing function
- * 'free_context'.
- */
-static inline void *afb_req_context(struct afb_req req, void *(*create_context)(), void (*free_context)(void*))
-{
- void *result = afb_req_context_get(req);
- if (result == NULL) {
- result = create_context();
- afb_req_context_set(req, result, free_context);
- }
- return result;
-}
-
-/*
- * Frees the pointer stored by the binding for the session of 'req'
- * and sets it to NULL.
- *
- * Shortcut for: afb_req_context_set(req, NULL, NULL)
- */
-static inline void afb_req_context_clear(struct afb_req req)
-{
- afb_req_context_set(req, NULL, NULL);
-}
-
-/*
- * Adds one to the count of references of 'req'.
- * This function MUST be called by asynchronous implementations
- * of verbs if no reply was sent before returning.
- */
-static inline void afb_req_addref(struct afb_req req)
-{
- req.itf->addref(req.closure);
-}
-
-/*
- * Substracts one to the count of references of 'req'.
- * This function MUST be called by asynchronous implementations
- * of verbs after sending the asynchronous reply.
- */
-static inline void afb_req_unref(struct afb_req req)
-{
- req.itf->unref(req.closure);
-}
-
-/*
- * Closes the session associated with 'req'
- * and delete all associated contexts.
- */
-static inline void afb_req_session_close(struct afb_req req)
-{
- req.itf->session_close(req.closure);
-}
-
-/*
- * Sets the level of assurance of the session of 'req'
- * to 'level'. The effect of this function is subject of
- * security policies.
- * Returns 1 on success or 0 if failed.
- */
-static inline int afb_req_session_set_LOA(struct afb_req req, unsigned level)
-{
- return req.itf->session_set_LOA(req.closure, level);
-}
-
-/*
- * Stores 'req' on heap for asynchrnous use.
- * Returns a pointer to the stored 'req' or NULL on memory depletion.
- * The count of reference to 'req' is incremented on success
- * (see afb_req_addref).
- */
-static inline struct afb_req *afb_req_store(struct afb_req req)
-{
- struct afb_req *result = malloc(sizeof *result);
- if (result != NULL) {
- *result = req;
- afb_req_addref(req);
- }
- return result;
-}
-
-/*
- * Retrieves the afb_req stored at 'req' and frees the memory.
- * Returns the stored request.
- * The count of reference is UNCHANGED, thus, normally, the
- * function 'afb_req_unref' should be called on the result
- * after that the asynchronous reply if sent.
- */
-static inline struct afb_req afb_req_unstore(struct afb_req *req)
-{
- struct afb_req result = *req;
- free(req);
- return result;
-}
-
-/*
- * Establishes for the client link identified by 'req' a subscription
- * to the 'event'.
- * Returns 0 in case of successful subscription or -1 in case of error.
- */
-static inline int afb_req_subscribe(struct afb_req req, struct afb_event event)
-{
- return req.itf->subscribe(req.closure, event);
-}
-
-/*
- * Revokes the subscription established to the 'event' for the client
- * link identified by 'req'.
- * Returns 0 in case of successful subscription or -1 in case of error.
- */
-static inline int afb_req_unsubscribe(struct afb_req req, struct afb_event event)
-{
- return req.itf->unsubscribe(req.closure, event);
-}
-
-/*
- * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
- * This call is made in the context of the request 'req'.
- * On completion, the function 'callback' is invoked with the
- * 'closure' given at call and two other parameters: 'iserror' and 'result'.
- * 'iserror' is a boolean that indicates if the reply is an error reply.
- * 'result' is the json object of the reply.
- */
-static inline void afb_req_subcall(struct afb_req req, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result), void *closure)
-{
- req.itf->subcall(req.closure, api, verb, args, callback, closure);
-}
-
-/* internal use */
-static inline const char *afb_req_raw(struct afb_req req, size_t *size)
-{
- return req.itf->raw(req.closure, size);
-}
-
-/* internal use */
-static inline void afb_req_send(struct afb_req req, const char *buffer, size_t size)
-{
- req.itf->send(req.closure, buffer, size);
-}