api-v3: First draft
[src/app-framework-binder.git] / include / afb / afb-req-x1.h
similarity index 62%
rename from include/afb/afb-req.h
rename to include/afb/afb-req-x1.h
index 77153ef..cea17d0 100644 (file)
 
 #pragma once
 
-#include "afb-req-itf.h"
-#include "afb-event.h"
+#include "afb-req-x1-itf.h"
+#include "afb-event-x1.h"
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Converts the 'req' to an afb_request.
  */
-static inline struct afb_request *afb_req_to_request(struct afb_req req)
+static inline struct afb_req_x2 *afb_req_x1_to_req_x2(struct afb_req_x1 req)
 {
        return req.closure;
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Checks whether 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)
+static inline int afb_req_x1_is_valid(struct afb_req_x1 req)
 {
        return !!req.itf;
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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.
@@ -50,157 +56,141 @@ static inline int afb_req_is_valid(struct afb_req req)
  * 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)
+static inline struct afb_arg afb_req_x1_get(struct afb_req_x1 req, const char *name)
 {
        return req.itf->get(req.closure, name);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline const char *afb_req_x1_value(struct afb_req_x1 req, const char *name)
 {
-       return afb_req_get(req, name).value;
+       return afb_req_x1_get(req, name).value;
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline const char *afb_req_x1_path(struct afb_req_x1 req, const char *name)
 {
-       return afb_req_get(req, name).path;
+       return afb_req_x1_get(req, name).path;
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline struct json_object *afb_req_x1_json(struct afb_req_x1 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".
+/**
+ * @deprecated use bindings version 3
+ *
+ * Sends a reply to the request 'req'.
+ * The status of the reply is set to 'error' (that must be NULL on success).
  * Its send the object 'obj' (can be NULL) with an
- * informationnal comment 'info (can also be NULL).
+ * informational 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)
+static inline void afb_req_x1_reply(struct afb_req_x1 req, struct json_object *obj, const char *error, const char *info)
 {
-       req.itf->success(req.closure, obj, info);
+       req.itf->reply(req.closure, obj, error, info);
 }
 
-/*
- * Same as 'afb_req_success' but the 'info' is a formatting
+/**
+ * @deprecated use bindings version 3
+ *
+ * Same as 'afb_req_x1_reply' 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, ...)
+static inline void afb_req_x1_reply_f(struct afb_req_x1 req, struct json_object *obj, const char *error, const char *info, ...) __attribute__((format(printf, 4, 5)));
+static inline void afb_req_x1_reply_f(struct afb_req_x1 req, struct json_object *obj, const char *error, const char *info, ...)
 {
        va_list args;
        va_start(args, info);
-       req.itf->vsuccess(req.closure, obj, info, args);
+       req.itf->vreply(req.closure, obj, error, info, args);
        va_end(args);
 }
 
-/*
- * Same as 'afb_req_success_f' but the arguments to the format 'info'
+/**
+ * @deprecated use bindings version 3
+ *
+ * Same as 'afb_req_x1_reply_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)
+static inline void afb_req_x1_reply_v(struct afb_req_x1 req, struct json_object *obj, const char *error, const char *info, va_list args)
 {
-       req.itf->vsuccess(req.closure, obj, info, args);
+       req.itf->vreply(req.closure, obj, error, 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.
+/**
+ * @deprecated use bindings version 3
  *
- * 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)
+static inline void *afb_req_x1_context_get(struct afb_req_x1 req)
 {
-       return req.itf->context_get(req.closure);
+       return req.itf->context_make(req.closure, 0, 0, 0, 0);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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*))
+static inline void afb_req_x1_context_set(struct afb_req_x1 req, void *context, void (*free_context)(void*))
 {
-       req.itf->context_set(req.closure, context, free_context);
+       req.itf->context_make(req.closure, 1, 0, free_context, context);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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*))
+static inline void *afb_req_x1_context(struct afb_req_x1 req, void *(*create_context)(), void (*free_context)(void*))
 {
        return req.itf->context_make(req.closure, 0, (void *(*)(void*))(void*)create_context, free_context, 0);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Gets the pointer stored by the binding for the session of 'request'.
  * If no previous pointer is stored or if 'replace' is not zero, a new value
  * is generated using the function 'create_context' called with the 'closure'.
@@ -210,83 +200,99 @@ static inline void *afb_req_context(struct afb_req req, void *(*create_context)(
  * it is not more used.
  * This function is atomic: it ensures that 2 threads will not race together.
  */
-static inline void *afb_req_context_make(struct afb_req req, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure)
+static inline void *afb_req_x1_context_make(struct afb_req_x1 req, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure)
 {
        return req.itf->context_make(req.closure, replace, create_context, free_context, closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline void afb_req_x1_context_clear(struct afb_req_x1 req)
 {
-       afb_req_context_set(req, 0, 0);
+       req.itf->context_make(req.closure, 1, 0, 0, 0);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline void afb_req_x1_addref(struct afb_req_x1 req)
 {
        req.itf->addref(req.closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline void afb_req_x1_unref(struct afb_req_x1 req)
 {
        req.itf->unref(req.closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Closes the session associated with 'req'
  * and delete all associated contexts.
  */
-static inline void afb_req_session_close(struct afb_req req)
+static inline void afb_req_x1_session_close(struct afb_req_x1 req)
 {
        req.itf->session_close(req.closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline int afb_req_x1_session_set_LOA(struct afb_req_x1 req, unsigned level)
 {
-       return req.itf->session_set_LOA(req.closure, level);
+       return 1 + req.itf->session_set_LOA(req.closure, level);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline int afb_req_x1_subscribe(struct afb_req_x1 req, struct afb_event_x1 event)
 {
-       return req.itf->subscribe(req.closure, event);
+       return req.itf->legacy_subscribe_event_x1(req.closure, event);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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)
+static inline int afb_req_x1_unsubscribe(struct afb_req_x1 req, struct afb_event_x1 event)
 {
-       return req.itf->unsubscribe(req.closure, event);
+       return req.itf->legacy_unsubscribe_event_x1(req.closure, event);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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
@@ -303,12 +309,14 @@ static inline int afb_req_unsubscribe(struct afb_req req, struct afb_event event
  *  - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
  *  - 'afb_req_subcall_sync' the synchronous version
  */
-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)
+static inline void afb_req_x1_subcall(struct afb_req_x1 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);
+       req.itf->legacy_subcall(req.closure, api, verb, args, callback, closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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
@@ -326,12 +334,14 @@ static inline void afb_req_subcall(struct afb_req req, const char *api, const ch
  *  - 'afb_req_subcall' that doesn't keep request alive automatically.
  *  - 'afb_req_subcall_sync' the synchronous version
  */
-static inline void afb_req_subcall_req(struct afb_req req, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result, struct afb_req req), void *closure)
+static inline void afb_req_x1_subcall_req(struct afb_req_x1 req, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result, struct afb_req_x1 req), void *closure)
 {
-       req.itf->subcall_req(req.closure, api, verb, args, callback, closure);
+       req.itf->legacy_subcall_req(req.closure, api, verb, args, callback, closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * 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'.
  * This call is synchronous, it waits untill completion of the request.
@@ -347,12 +357,14 @@ static inline void afb_req_subcall_req(struct afb_req req, const char *api, cons
  *  - 'afb_req_subcall_req' that is convenient to keep request alive automatically.
  *  - 'afb_req_subcall' that doesn't keep request alive automatically.
  */
-static inline int afb_req_subcall_sync(struct afb_req req, const char *api, const char *verb, struct json_object *args, struct json_object **result)
+static inline int afb_req_x1_subcall_sync(struct afb_req_x1 req, const char *api, const char *verb, struct json_object *args, struct json_object **result)
 {
-       return req.itf->subcallsync(req.closure, api, verb, args, result);
+       return req.itf->legacy_subcallsync(req.closure, api, verb, args, result);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Send associated to 'req' a message described by 'fmt' and following parameters
  * to the journal for the verbosity 'level'.
  *
@@ -369,8 +381,8 @@ static inline int afb_req_subcall_sync(struct afb_req req, const char *api, cons
  *      INFO              6        Informational
  *      DEBUG             7        Debug-level messages
  */
-static inline void afb_req_verbose(struct afb_req req, int level, const char *file, int line, const char * func, const char *fmt, ...) __attribute__((format(printf, 6, 7)));
-static inline void afb_req_verbose(struct afb_req req, int level, const char *file, int line, const char * func, const char *fmt, ...)
+static inline void afb_req_x1_verbose(struct afb_req_x1 req, int level, const char *file, int line, const char * func, const char *fmt, ...) __attribute__((format(printf, 6, 7)));
+static inline void afb_req_x1_verbose(struct afb_req_x1 req, int level, const char *file, int line, const char * func, const char *fmt, ...)
 {
        va_list args;
        va_start(args, fmt);
@@ -378,25 +390,22 @@ static inline void afb_req_verbose(struct afb_req req, int level, const char *fi
        va_end(args);
 }
 
-/* macro for setting file, line and function automatically */
-# if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
-#define AFB_REQ_VERBOSE(req,level,...) afb_req_verbose(req,level,__FILE__,__LINE__,__func__,__VA_ARGS__)
-#else
-#define AFB_REQ_VERBOSE(req,level,...) afb_req_verbose(req,level,NULL,0,NULL,__VA_ARGS__)
-#endif
-
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Check whether the 'permission' is granted or not to the client
  * identified by 'req'.
  *
  * Returns 1 if the permission is granted or 0 otherwise.
  */
-static inline int afb_req_has_permission(struct afb_req req, const char *permission)
+static inline int afb_req_x1_has_permission(struct afb_req_x1 req, const char *permission)
 {
        return req.itf->has_permission(req.closure, permission);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Get the application identifier of the client application for the
  * request 'req'.
  *
@@ -405,19 +414,40 @@ static inline int afb_req_has_permission(struct afb_req req, const char *permiss
  *
  * The returned value if not NULL must be freed by the caller
  */
-static inline char *afb_req_get_application_id(struct afb_req req)
+static inline char *afb_req_x1_get_application_id(struct afb_req_x1 req)
 {
        return req.itf->get_application_id(req.closure);
 }
 
-/*
+/**
+ * @deprecated use bindings version 3
+ *
  * Get the user identifier (UID) of the client application for the
  * request 'req'.
  *
  * Returns -1 when the application can not be identified.
  */
-static inline int afb_req_get_uid(struct afb_req req)
+static inline int afb_req_x1_get_uid(struct afb_req_x1 req)
 {
        return req.itf->get_uid(req.closure);
 }
 
+/**
+ * @deprecated use bindings version 3
+ *
+ * Get informations about the client of the
+ * request 'req'.
+ *
+ * Returns an object with client informations:
+ *  {
+ *    "pid": int, "uid": int, "gid": int,
+ *    "smack": string, "appid": string,
+ *    "uuid": string, "LOA": int
+ *  }
+ */
+static inline struct json_object *afb_req_x1_get_client_info(struct afb_req_x1 req)
+{
+       return req.itf->get_client_info(req.closure);
+}
+
+