-struct afb_req {
- const struct afb_req_itf *itf; /* the interface to use */
- void *closure; /* the closure argument for functions of 'itf' */
-};
-
-/*
- * Checks wether the request 'req' is valid or not.
- *
- * Returns 0 if not valid or 1 if valid.
- */
-static inline int afb_req_is_valid(struct afb_req req)
-{
- return req.itf != NULL;
-}
-
-/*
- * Gets from the request 'req' the argument of 'name'.
- * Returns a PLAIN structure of type 'struct afb_arg'.
- * When the argument of 'name' is not found, all fields of result are set to NULL.
- * When the argument of 'name' is found, the fields are filled,
- * in particular, the field 'result.name' is set to 'name'.
- *
- * There is a special name value: the empty string.
- * The argument of name "" is defined only if the request was made using
- * an HTTP POST of Content-Type "application/json". In that case, the
- * argument of name "" receives the value of the body of the HTTP request.
- */
-static inline struct afb_arg afb_req_get(struct afb_req req, const char *name)
-{
- return req.itf->get(req.closure, name);
-}
-
-/*
- * Gets from the request 'req' the string value of the argument of 'name'.
- * Returns NULL if when there is no argument of 'name'.
- * Returns the value of the argument of 'name' otherwise.
- *
- * Shortcut for: afb_req_get(req, name).value
- */
-static inline const char *afb_req_value(struct afb_req req, const char *name)
-{
- return afb_req_get(req, name).value;
-}
-
-/*
- * Gets from the request 'req' the path for file attached to the argument of 'name'.
- * Returns NULL if when there is no argument of 'name' or when there is no file.
- * Returns the path of the argument of 'name' otherwise.
- *
- * Shortcut for: afb_req_get(req, name).path
- */
-static inline const char *afb_req_path(struct afb_req req, const char *name)
-{
- return afb_req_get(req, name).path;
-}
-
-/*
- * Gets from the request 'req' the json object hashing the arguments.
- * The returned object must not be released using 'json_object_put'.
- */
-static inline struct json_object *afb_req_json(struct afb_req req)
-{
- return req.itf->json(req.closure);
-}
-
-/*
- * Sends a reply of kind success to the request 'req'.
- * The status of the reply is automatically set to "success".
- * Its send the object 'obj' (can be NULL) with an
- * informationnal comment 'info (can also be NULL).
- *
- * For convenience, the function calls 'json_object_put' for 'obj'.
- * Thus, in the case where 'obj' should remain available after
- * the function returns, the function 'json_object_get' shall be used.
- */
-static inline void afb_req_success(struct afb_req req, struct json_object *obj, const char *info)
-{
- req.itf->success(req.closure, obj, info);
-}
-
-/*
- * Same as 'afb_req_success' but the 'info' is a formatting
- * string followed by arguments.
- *
- * For convenience, the function calls 'json_object_put' for 'obj'.
- * Thus, in the case where 'obj' should remain available after
- * the function returns, the function 'json_object_get' shall be used.
- */
-static inline void afb_req_success_f(struct afb_req req, struct json_object *obj, const char *info, ...) __attribute__((format(printf, 3, 4)));
-static inline void afb_req_success_f(struct afb_req req, struct json_object *obj, const char *info, ...)
-{
- va_list args;
- va_start(args, info);
- req.itf->vsuccess(req.closure, obj, info, args);
- va_end(args);
-}
-
-/*
- * Same as 'afb_req_success_f' but the arguments to the format 'info'
- * are given as a variable argument list instance.
- *
- * For convenience, the function calls 'json_object_put' for 'obj'.
- * Thus, in the case where 'obj' should remain available after
- * the function returns, the function 'json_object_get' shall be used.
- */
-static inline void afb_req_success_v(struct afb_req req, struct json_object *obj, const char *info, va_list args)
-{
- req.itf->vsuccess(req.closure, obj, info, args);
-}
-
-/*
- * Sends a reply of kind failure to the request 'req'.
- * The status of the reply is set to 'status' and an
- * informationnal comment 'info' (can also be NULL) can be added.
- *
- * Note that calling afb_req_fail("success", info) is equivalent
- * to call afb_req_success(NULL, info). Thus even if possible it
- * is strongly recommanded to NEVER use "success" for status.
- */
-static inline void afb_req_fail(struct afb_req req, const char *status, const char *info)
-{
- req.itf->fail(req.closure, status, info);
-}
-
-/*
- * Same as 'afb_req_fail' but the 'info' is a formatting
- * string followed by arguments.
- */
-static inline void afb_req_fail_f(struct afb_req req, const char *status, const char *info, ...) __attribute__((format(printf, 3, 4)));
-static inline void afb_req_fail_f(struct afb_req req, const char *status, const char *info, ...)
-{
- va_list args;
- va_start(args, info);
- req.itf->vfail(req.closure, status, info, args);
- va_end(args);
-}
-
-/*
- * Same as 'afb_req_fail_f' but the arguments to the format 'info'
- * are given as a variable argument list instance.
- */
-static inline void afb_req_fail_v(struct afb_req req, const char *status, const char *info, va_list args)
-{
- req.itf->vfail(req.closure, status, info, args);
-}
-
-/*
- * 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*))