Provide efficient store/unstore for afb_req
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 2 Jun 2017 14:32:44 +0000 (16:32 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 2 Jun 2017 15:05:37 +0000 (17:05 +0200)
Change-Id: I231e2506f58227fb8d192df042539b1551a765c5
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
21 files changed:
include/afb/afb-binding-v1.h
include/afb/afb-binding-v2.h
include/afb/afb-binding.h
include/afb/afb-daemon-common.h
include/afb/afb-daemon-v2.h
include/afb/afb-req-common.h [new file with mode: 0644]
include/afb/afb-req-itf.h
include/afb/afb-req-v1.h [new file with mode: 0644]
include/afb/afb-req-v2.h [new file with mode: 0644]
src/afb-api-dbus.c
src/afb-apiset.c
src/afb-ditf.c
src/afb-hook.c
src/afb-hook.h
src/afb-hreq.c
src/afb-hswitch.c
src/afb-stub-ws.c
src/afb-subcall.c
src/afb-ws-json1.c
src/afb-xreq.c
src/afb-xreq.h

index a36d5e3..f3ccae2 100644 (file)
 
 struct json_object;
 
-#include "afb-req-itf.h"
+#include "afb-req-common.h"
 #include "afb-event-itf.h"
 #include "afb-service-common.h"
 #include "afb-daemon-common.h"
 
+#include "afb-req-v1.h"
 #include "afb-session-v1.h"
 #include "afb-service-v1.h"
 #include "afb-daemon-v1.h"
index 66601b2..b1cff27 100644 (file)
 #include <stdint.h>
 
 #include "afb-auth.h"
-#include "afb-req-itf.h"
 #include "afb-event-itf.h"
+#include "afb-req-common.h"
 #include "afb-service-common.h"
 #include "afb-daemon-common.h"
 
+#include "afb-req-v2.h"
 #include "afb-session-v2.h"
 
 struct json_object;
index 82f702e..706ca81 100644 (file)
@@ -167,6 +167,9 @@ typedef struct afb_service_itf          afb_service_itf;
 #define afb_service_call               afb_service_call_v1
 #define afb_service_call_sync          afb_service_call_sync_v1
 
+#define afb_req_store                  afb_req_store_v1
+#define afb_req_unstore                        afb_req_unstore_v1
+
 #endif
 
 /***************************************************************************************************/
@@ -213,9 +216,13 @@ typedef struct afb_service_itf          afb_service_itf;
 #define afb_daemon_rootdir_get_fd      afb_daemon_rootdir_get_fd_v2
 #define afb_daemon_rootdir_open_locale afb_daemon_rootdir_open_locale_v2
 #define afb_daemon_queue_job           afb_daemon_queue_job_v2
+#define afb_daemon_unstore_req         afb_daemon_unstore_req_v2
 
 #define afb_service_call               afb_service_call_v2
 #define afb_service_call_sync          afb_service_call_sync_v2
 
+#define afb_req_store                  afb_req_store_v2
+#define afb_req_unstore                        afb_daemon_unstore_req_v2
+
 #endif
 
index e1308d6..d3d1b3d 100644 (file)
@@ -22,6 +22,8 @@
 /* declaration of features of libsystemd */
 struct sd_event;
 struct sd_bus;
+struct afb_stored_req;
+struct afb_req;
 
 /*
  * Definition of the facilities provided by the daemon.
@@ -38,6 +40,7 @@ struct afb_daemon_itf
        int (*rootdir_open_locale)(void *closure, const char *filename, int flags, const char *locale);
        int (*queue_job)(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout);
        void (*vverbose_v2)(void*closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
+       struct afb_req (*unstore_req)(void*closure, struct afb_stored_req *sreq);
 };
 
 /*
index 3a3706f..4c4c656 100644 (file)
@@ -128,3 +128,16 @@ static inline int afb_daemon_queue_job_v2(void (*callback)(int signum, void *arg
 {
        return afb_get_daemon_v2().itf->queue_job(afb_get_daemon_v2().closure, callback, argument, group, timeout);
 }
+
+/*
+ * Retrieves the afb_req stored at 'sreq'.
+ * Returns the stored request.
+ * The count of reference is UNCHANGED, thus, the
+ * function 'afb_req_unref' should be called on the result
+ * after that the asynchronous reply if sent.
+ */
+static inline struct afb_req afb_daemon_unstore_req_v2(struct afb_stored_req *sreq)
+{
+       return afb_get_daemon_v2().itf->unstore_req(afb_get_daemon_v2().closure, sreq);
+}
+
diff --git a/include/afb/afb-req-common.h b/include/afb/afb-req-common.h
new file mode 100644 (file)
index 0000000..8ff1b39
--- /dev/null
@@ -0,0 +1,400 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdarg.h>
+
+#include "afb-event-itf.h"
+
+struct json_object;
+struct afb_stored_req;
+
+/*
+ * Describes an argument (or parameter) of a request
+ */
+struct afb_arg
+{
+       const char *name;       /* name of the argument or NULL if invalid */
+       const char *value;      /* string representation of the value of the argument */
+                               /* original filename of the argument if path != NULL */
+       const char *path;       /* if not NULL, path of the received file for the argument */
+                               /* when the request is finalized this file is removed */
+};
+
+/*
+ * Interface for handling requests.
+ * It records the functions to be called for the request.
+ * Don't use this structure directly.
+ * Use the helper functions documented below.
+ */
+struct afb_req_itf
+{
+       /* CAUTION: respect the order, add at the end */
+
+       struct json_object *(*json)(void *closure);
+       struct afb_arg (*get)(void *closure, const char *name);
+
+       void (*success)(void *closure, struct json_object *obj, const char *info);
+       void (*fail)(void *closure, const char *status, const char *info);
+
+       void (*vsuccess)(void *closure, struct json_object *obj, const char *fmt, va_list args);
+       void (*vfail)(void *closure, const char *status, const char *fmt, va_list args);
+
+       void *(*context_get)(void *closure);
+       void (*context_set)(void *closure, void *value, void (*free_value)(void*));
+
+       void (*addref)(void *closure);
+       void (*unref)(void *closure);
+
+       void (*session_close)(void *closure);
+       int (*session_set_LOA)(void *closure, unsigned level);
+
+       int (*subscribe)(void *closure, struct afb_event event);
+       int (*unsubscribe)(void *closure, struct afb_event event);
+
+       void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
+       int (*subcallsync)(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result);
+
+       void (*vverbose)(void *closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
+       struct afb_stored_req *(*store)(void *closure);
+};
+
+/*
+ * Describes the request by bindings from afb-daemon
+ */
+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*))
+{
+       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);
+}
+
+/*
+ * 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, you must not call json_object_put
+ * on the result.
+ *
+ * For convenience, the function calls 'json_object_put' for 'args'.
+ * Thus, in the case where 'args' should remain available after
+ * the function returns, the function 'json_object_get' shall be used.
+ */
+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);
+}
+
+/*
+ * 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.
+ * It returns 0 on an error answer and returns 1 when no error was detected.
+ * The object pointed by 'result' is filled and must be released by the caller
+ * after its use by calling 'json_object_put'.
+ *
+ * For convenience, the function calls 'json_object_put' for 'args'.
+ * Thus, in the case where 'args' should remain available after
+ * the function returns, the function 'json_object_get' shall be used.
+ */
+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)
+{
+       return req.itf->subcallsync(req.closure, api, verb, args, result);
+}
+
+/*
+ * Send associated to 'req' a message described by 'fmt' and following parameters
+ * to the journal for the verbosity 'level'.
+ *
+ * 'file', 'line' and 'func' are indicators of position of the code in source files
+ * (see macros __FILE__, __LINE__ and __func__).
+ *
+ * 'level' is defined by syslog standard:
+ *      EMERGENCY         0        System is unusable
+ *      ALERT             1        Action must be taken immediately
+ *      CRITICAL          2        Critical conditions
+ *      ERROR             3        Error conditions
+ *      WARNING           4        Warning conditions
+ *      NOTICE            5        Normal but significant condition
+ *      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, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       req.itf->vverbose(req.closure, level, file, line, func, fmt, args);
+       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
index dcbbb8a..bf044f1 100644 (file)
 
 #pragma once
 
-#include <stdarg.h>
+#pragma GCC warning "\n\n\
+    This header file <afb/afb-req-itf.h> is OBSOLETE.\n\
+    It is provided for COMPATIBILITY ONLY.\n\n\
+    Please USE <afb/afb-binding.h> and ADAPT YOUR CODE to new names.\n"
 
-#include "afb-event-itf.h"
+#include "afb-binding.h"
 
-/* avoid inclusion of <json-c/json.h> */
-struct json_object;
-
-/*
- * Describes an argument (or parameter) of a request
- */
-struct afb_arg
-{
-       const char *name;       /* name of the argument or NULL if invalid */
-       const char *value;      /* string representation of the value of the argument */
-                               /* original filename of the argument if path != NULL */
-       const char *path;       /* if not NULL, path of the received file for the argument */
-                               /* when the request is finalized this file is removed */
-};
-
-/*
- * Interface for handling requests.
- * It records the functions to be called for the request.
- * Don't use this structure directly.
- * Use the helper functions documented below.
- */
-struct afb_req_itf
-{
-       /* CAUTION: respect the order, add at the end */
-
-       struct json_object *(*json)(void *closure);
-       struct afb_arg (*get)(void *closure, const char *name);
-
-       void (*success)(void *closure, struct json_object *obj, const char *info);
-       void (*fail)(void *closure, const char *status, const char *info);
-
-       void (*vsuccess)(void *closure, struct json_object *obj, const char *fmt, va_list args);
-       void (*vfail)(void *closure, const char *status, const char *fmt, va_list args);
-
-       void *(*context_get)(void *closure);
-       void (*context_set)(void *closure, void *value, void (*free_value)(void*));
-
-       void (*addref)(void *closure);
-       void (*unref)(void *closure);
-
-       void (*session_close)(void *closure);
-       int (*session_set_LOA)(void *closure, unsigned level);
-
-       int (*subscribe)(void *closure, struct afb_event event);
-       int (*unsubscribe)(void *closure, struct afb_event event);
-
-       void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
-       int (*subcallsync)(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result);
-
-       void (*vverbose)(void*closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
-};
-
-/*
- * Describes the request by bindings from afb-daemon
- */
-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*))
-{
-       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 = (struct afb_req*)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, you must not call json_object_put
- * on the result.
- *
- * For convenience, the function calls 'json_object_put' for 'args'.
- * Thus, in the case where 'args' should remain available after
- * the function returns, the function 'json_object_get' shall be used.
- */
-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);
-}
-
-/*
- * 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.
- * It returns 0 on an error answer and returns 1 when no error was detected.
- * The object pointed by 'result' is filled and must be released by the caller
- * after its use by calling 'json_object_put'.
- *
- * For convenience, the function calls 'json_object_put' for 'args'.
- * Thus, in the case where 'args' should remain available after
- * the function returns, the function 'json_object_get' shall be used.
- */
-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)
-{
-       return req.itf->subcallsync(req.closure, api, verb, args, result);
-}
-
-/*
- * Send associated to 'req' a message described by 'fmt' and following parameters
- * to the journal for the verbosity 'level'.
- *
- * 'file', 'line' and 'func' are indicators of position of the code in source files
- * (see macros __FILE__, __LINE__ and __func__).
- *
- * 'level' is defined by syslog standard:
- *      EMERGENCY         0        System is unusable
- *      ALERT             1        Action must be taken immediately
- *      CRITICAL          2        Critical conditions
- *      ERROR             3        Error conditions
- *      WARNING           4        Warning conditions
- *      NOTICE            5        Normal but significant condition
- *      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, ...)
-{
-       va_list args;
-       va_start(args, fmt);
-       req.itf->vverbose(req.closure, level, file, line, func, fmt, args);
-       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
diff --git a/include/afb/afb-req-v1.h b/include/afb/afb-req-v1.h
new file mode 100644 (file)
index 0000000..03b4ee6
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdlib.h>
+#include "afb-req-common.h"
+
+/*
+ * 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_v1(struct afb_req req)
+{
+       struct afb_req *result = (struct afb_req*)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_v1(struct afb_req *req)
+{
+       struct afb_req result = *req;
+       free(req);
+       return result;
+}
+
diff --git a/include/afb/afb-req-v2.h b/include/afb/afb-req-v2.h
new file mode 100644 (file)
index 0000000..fe94e89
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "afb-req-common.h"
+
+/*
+ * Stores 'req' on heap for asynchrnous use.
+ * Returns a handler 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_stored_req *afb_req_store_v2(struct afb_req req)
+{
+       return req.itf->store(req.closure);
+}
+
index 4689ad1..0e51c63 100644 (file)
@@ -27,7 +27,7 @@
 #include <systemd/sd-bus.h>
 #include <json-c/json.h>
 
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
 
 #include "afb-common.h"
 
index 410ff27..c934e8c 100644 (file)
@@ -31,8 +31,6 @@
 #include "afb-xreq.h"
 #include "jobs.h"
 
-#include <afb/afb-req-itf.h>
-
 #define INCR 8         /* CAUTION: must be a power of 2 */
 
 /**
index b5a5093..6613676 100644 (file)
@@ -29,6 +29,7 @@
 #include "afb-ditf.h"
 #include "afb-evt.h"
 #include "afb-common.h"
+#include "afb-xreq.h"
 #include "afb-hook.h"
 #include "jobs.h"
 #include "verbose.h"
@@ -100,6 +101,11 @@ static int queue_job_cb(void *closure, void (*callback)(int signum, void *arg),
        return jobs_queue(group, timeout, callback, argument);
 }
 
+static struct afb_req unstore_req_cb(void *closure, struct afb_stored_req *sreq)
+{
+       return afb_xreq_unstore(sreq);
+}
+
 /**********************************************
 * hooked flow
 **********************************************/
@@ -179,6 +185,16 @@ static int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void
        return afb_hook_ditf_queue_job(ditf, callback, argument, group, timeout, r);
 }
 
+static struct afb_req hooked_unstore_req_cb(void *closure, struct afb_stored_req *sreq)
+{
+       struct afb_ditf *ditf = closure;
+       afb_hook_ditf_unstore_req(ditf, sreq);
+       return unstore_req_cb(closure, sreq);
+}
+
+/**********************************************
+* vectors
+**********************************************/
 static const struct afb_daemon_itf daemon_itf = {
        .vverbose_v1 = old_vverbose_cb,
        .vverbose_v2 = vverbose_cb,
@@ -189,7 +205,8 @@ static const struct afb_daemon_itf daemon_itf = {
        .get_system_bus = afb_common_get_system_bus,
        .rootdir_get_fd = afb_common_rootdir_get_fd,
        .rootdir_open_locale = rootdir_open_locale_cb,
-       .queue_job = queue_job_cb
+       .queue_job = queue_job_cb,
+       .unstore_req = unstore_req_cb
 };
 
 static const struct afb_daemon_itf hooked_daemon_itf = {
@@ -202,7 +219,8 @@ static const struct afb_daemon_itf hooked_daemon_itf = {
        .get_system_bus = hooked_get_system_bus,
        .rootdir_get_fd = hooked_rootdir_get_fd,
        .rootdir_open_locale = hooked_rootdir_open_locale_cb,
-       .queue_job = hooked_queue_job_cb
+       .queue_job = hooked_queue_job_cb,
+       .unstore_req = hooked_unstore_req_cb
 };
 
 void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding_data_v2 *data)
index 6a11341..bf90732 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <json-c/json.h>
 
-#include <afb/afb-req-itf.h>
+#include <afb/afb-req-common.h>
 #include <afb/afb-event-itf.h>
 
 #include "afb-context.h"
@@ -271,6 +271,16 @@ static void hook_xreq_vverbose_default_cb(void * closure, const struct afb_xreq
        }
 }
 
+static void hook_xreq_store_default_cb(void * closure, const struct afb_xreq *xreq, struct afb_stored_req *sreq)
+{
+       _hook_xreq_(xreq, "store() -> %p", sreq);
+}
+
+static void hook_xreq_unstore_default_cb(void * closure, const struct afb_xreq *xreq)
+{
+       _hook_xreq_(xreq, "unstore()");
+}
+
 static struct afb_hook_xreq_itf hook_xreq_default_itf = {
        .hook_xreq_begin = hook_xreq_begin_default_cb,
        .hook_xreq_end = hook_xreq_end_default_cb,
@@ -290,7 +300,9 @@ static struct afb_hook_xreq_itf hook_xreq_default_itf = {
        .hook_xreq_subcall_result = hook_xreq_subcall_result_default_cb,
        .hook_xreq_subcallsync = hook_xreq_subcallsync_default_cb,
        .hook_xreq_subcallsync_result = hook_xreq_subcallsync_result_default_cb,
-       .hook_xreq_vverbose = hook_xreq_vverbose_default_cb
+       .hook_xreq_vverbose = hook_xreq_vverbose_default_cb,
+       .hook_xreq_store = hook_xreq_store_default_cb,
+       .hook_xreq_unstore = hook_xreq_unstore_default_cb
 };
 
 /******************************************************************************
@@ -416,6 +428,16 @@ void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *
        _HOOK_XREQ_(vverbose, xreq, level, file ?: "?", line, func ?: "?", fmt, args);
 }
 
+void afb_hook_xreq_store(const struct afb_xreq *xreq, struct afb_stored_req *sreq)
+{
+       _HOOK_XREQ_(store, xreq, sreq);
+}
+
+void afb_hook_xreq_unstore(const struct afb_xreq *xreq)
+{
+       _HOOK_XREQ_(unstore, xreq);
+}
+
 /******************************************************************************
  * section: hooking xreqs
  *****************************************************************************/
@@ -615,11 +637,16 @@ static void hook_ditf_rootdir_open_locale_cb(void *closure, const struct afb_dit
        }
 }
 
-static void hook_ditf_queue_job(void *closure, const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result)
+static void hook_ditf_queue_job_cb(void *closure, const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result)
 {
        _hook_ditf_(ditf, "queue_job(%p, %p, %p, %d) -> %d", callback, argument, group, timeout, result);
 }
 
+static void hook_ditf_unstore_req_cb(void * closure,  const struct afb_ditf *ditf, struct afb_stored_req *sreq)
+{
+       _hook_ditf_(ditf, "unstore_req(%p)", sreq);
+}
+
 static struct afb_hook_ditf_itf hook_ditf_default_itf = {
        .hook_ditf_event_broadcast_before = hook_ditf_event_broadcast_before_cb,
        .hook_ditf_event_broadcast_after = hook_ditf_event_broadcast_after_cb,
@@ -630,7 +657,8 @@ static struct afb_hook_ditf_itf hook_ditf_default_itf = {
        .hook_ditf_event_make = hook_ditf_event_make_cb,
        .hook_ditf_rootdir_get_fd = hook_ditf_rootdir_get_fd_cb,
        .hook_ditf_rootdir_open_locale = hook_ditf_rootdir_open_locale_cb,
-       .hook_ditf_queue_job = hook_ditf_queue_job
+       .hook_ditf_queue_job = hook_ditf_queue_job_cb,
+       .hook_ditf_unstore_req = hook_ditf_unstore_req_cb
 };
 
 /******************************************************************************
@@ -709,6 +737,11 @@ int afb_hook_ditf_queue_job(const struct afb_ditf *ditf, void (*callback)(int si
        return result;
 }
 
+void afb_hook_ditf_unstore_req(const struct afb_ditf *ditf, struct afb_stored_req *sreq)
+{
+       _HOOK_DITF_(unstore_req, ditf, sreq);
+}
+
 /******************************************************************************
  * section: hooking ditf
  *****************************************************************************/
index 9173638..4070021 100644 (file)
@@ -28,6 +28,7 @@ struct afb_session;
 struct afb_xreq;
 struct afb_ditf;
 struct afb_svc;
+struct afb_stored_req;
 struct sd_bus;
 struct sd_event;
 
@@ -56,6 +57,8 @@ struct afb_hook_xreq;
 #define afb_hook_flag_req_subcallsync          0x020000
 #define afb_hook_flag_req_subcallsync_result   0x040000
 #define afb_hook_flag_req_vverbose             0x080000
+#define afb_hook_flag_req_store                        0x100000
+#define afb_hook_flag_req_unstore              0x200000
 
 /* common flags */
 #define afb_hook_flags_req_life                (afb_hook_flag_req_begin|afb_hook_flag_req_end)
@@ -69,12 +72,14 @@ struct afb_hook_xreq;
 /* extra flags */
 #define afb_hook_flags_req_ref         (afb_hook_flag_req_addref|afb_hook_flag_req_unref)
 #define afb_hook_flags_req_context     (afb_hook_flag_req_context_get|afb_hook_flag_req_context_set)
+#define afb_hook_flags_req_store       (afb_hook_flag_req_store|afb_hook_flag_req_unstore)
 
 /* predefined groups */
 #define afb_hook_flags_req_common      (afb_hook_flags_req_life|afb_hook_flags_req_args|afb_hook_flags_req_result\
                                        |afb_hook_flags_req_session|afb_hook_flags_req_event|afb_hook_flags_req_subcall\
                                        |afb_hook_flag_req_vverbose)
-#define afb_hook_flags_req_extra       (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context)
+#define afb_hook_flags_req_extra       (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context\
+                                       |afb_hook_flags_req_store)
 #define afb_hook_flags_req_all         (afb_hook_flags_req_extra)
 
 struct afb_hook_xreq_itf {
@@ -97,6 +102,8 @@ struct afb_hook_xreq_itf {
        void (*hook_xreq_subcallsync)(void * closure, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
        void (*hook_xreq_subcallsync_result)(void * closure, const struct afb_xreq *xreq, int status, struct json_object *result);
        void (*hook_xreq_vverbose)(void * closure, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
+       void (*hook_xreq_store)(void * closure, const struct afb_xreq *xreq, struct afb_stored_req *sreq);
+       void (*hook_xreq_unstore)(void * closure, const struct afb_xreq *xreq);
 };
 
 extern void afb_hook_init_xreq(struct afb_xreq *xreq);
@@ -125,6 +132,8 @@ extern void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, int status
 extern void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
 extern int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, struct json_object *result);
 extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
+extern void afb_hook_xreq_store(const struct afb_xreq *xreq, struct afb_stored_req *sreq);
+extern void afb_hook_xreq_unstore(const struct afb_xreq *xreq);
 
 /*********************************************************
 * section hooking ditf (daemon interface)
@@ -140,6 +149,7 @@ extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const
 #define afb_hook_flag_ditf_rootdir_get_fd              0x000080
 #define afb_hook_flag_ditf_rootdir_open_locale         0x000100
 #define afb_hook_flag_ditf_queue_job                   0x000200
+#define afb_hook_flag_ditf_unstore_req                 0x000400
 
 #define afb_hook_flags_ditf_common     (afb_hook_flag_ditf_vverbose\
                                        |afb_hook_flag_ditf_event_make\
@@ -150,7 +160,8 @@ extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const
                                        |afb_hook_flag_ditf_get_system_bus\
                                        |afb_hook_flag_ditf_rootdir_get_fd\
                                        |afb_hook_flag_ditf_rootdir_open_locale\
-                                       |afb_hook_flag_ditf_queue_job)
+                                       |afb_hook_flag_ditf_queue_job\
+                                       |afb_hook_flag_ditf_unstore_req)
 
 #define afb_hook_flags_ditf_all                (afb_hook_flags_ditf_common|afb_hook_flags_ditf_extra)
 
@@ -165,6 +176,7 @@ struct afb_hook_ditf_itf {
        void (*hook_ditf_rootdir_get_fd)(void *closure, const struct afb_ditf *ditf, int result);
        void (*hook_ditf_rootdir_open_locale)(void *closure, const struct afb_ditf *ditf, const char *filename, int flags, const char *locale, int result);
        void (*hook_ditf_queue_job)(void *closure, const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
+       void (*hook_ditf_unstore_req)(void *closure, const struct afb_ditf *ditf, struct afb_stored_req *sreq);
 };
 
 extern void afb_hook_ditf_event_broadcast_before(const struct afb_ditf *ditf, const char *name, struct json_object *object);
@@ -177,6 +189,7 @@ extern struct afb_event afb_hook_ditf_event_make(const struct afb_ditf *ditf, co
 extern int afb_hook_ditf_rootdir_get_fd(const struct afb_ditf *ditf, int result);
 extern int afb_hook_ditf_rootdir_open_locale(const struct afb_ditf *ditf, const char *filename, int flags, const char *locale, int result);
 extern int afb_hook_ditf_queue_job(const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
+extern void afb_hook_ditf_unstore_req(const struct afb_ditf *ditf, struct afb_stored_req *sreq);
 
 extern int afb_hook_flags_ditf(const char *api);
 extern struct afb_hook_ditf *afb_hook_create_ditf(const char *api, int flags, struct afb_hook_ditf_itf *itf, void *closure);
index b87251b..9c63091 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 
 #include "afb-method.h"
-#include <afb/afb-req-itf.h>
+#include <afb/afb-req-common.h>
 #include "afb-msg-json.h"
 #include "afb-context.h"
 #include "afb-hreq.h"
index 34eafd5..8132f23 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <microhttpd.h>
 
-#include <afb/afb-req-itf.h>
 #include "afb-context.h"
 #include "afb-hreq.h"
 #include "afb-apiset.h"
index 43837e5..1dc19fb 100644 (file)
@@ -35,7 +35,7 @@
 #include <json-c/json.h>
 #include <systemd/sd-event.h>
 
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
 
 #include "afb-common.h"
 
index 857f48e..3c75b17 100644 (file)
@@ -21,7 +21,7 @@
 #include <string.h>
 
 #include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
 
 #include "afb-subcall.h"
 #include "afb-msg-json.h"
index 4b6c04e..45e1cdb 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <json-c/json.h>
 
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
 
 #include "afb-wsj1.h"
 #include "afb-ws-json1.h"
index 9c4cab8..80fa963 100644 (file)
@@ -279,6 +279,12 @@ static void xreq_vverbose_cb(void*closure, int level, const char *file, int line
        vverbose(level, file, line, func, fmt, args);
 }
 
+static struct afb_stored_req *xreq_store_cb(void *closure)
+{
+       xreq_addref_cb(closure);
+       return closure;
+}
+
 /******************************************************************************/
 
 static struct json_object *xreq_hooked_json_cb(void *closure)
@@ -429,6 +435,14 @@ static void xreq_hooked_vverbose_cb(void*closure, int level, const char *file, i
        va_end(ap);
 }
 
+static struct afb_stored_req *xreq_hooked_store_cb(void *closure)
+{
+       struct afb_xreq *xreq = closure;
+       struct afb_stored_req *r = xreq_store_cb(closure);
+       afb_hook_xreq_store(xreq, r);
+       return r;
+}
+
 /******************************************************************************/
 
 const struct afb_req_itf xreq_itf = {
@@ -448,7 +462,8 @@ const struct afb_req_itf xreq_itf = {
        .unsubscribe = xreq_unsubscribe_cb,
        .subcall = xreq_subcall_cb,
        .subcallsync = xreq_subcallsync_cb,
-       .vverbose = xreq_vverbose_cb
+       .vverbose = xreq_vverbose_cb,
+       .store = xreq_store_cb
 };
 
 const struct afb_req_itf xreq_hooked_itf = {
@@ -468,7 +483,8 @@ const struct afb_req_itf xreq_hooked_itf = {
        .unsubscribe = xreq_hooked_unsubscribe_cb,
        .subcall = xreq_hooked_subcall_cb,
        .subcallsync = xreq_hooked_subcallsync_cb,
-       .vverbose = xreq_hooked_vverbose_cb
+       .vverbose = xreq_hooked_vverbose_cb,
+       .store = xreq_hooked_store_cb
 };
 
 static inline struct afb_req to_req(struct afb_xreq *xreq)
@@ -478,6 +494,14 @@ static inline struct afb_req to_req(struct afb_xreq *xreq)
 
 /******************************************************************************/
 
+struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq)
+{
+       struct afb_xreq *xreq = (struct afb_xreq *)sreq;
+       if (xreq->hookflags)
+               afb_hook_xreq_unstore(xreq);
+       return to_req(xreq);
+}
+
 struct json_object *afb_xreq_json(struct afb_xreq *xreq)
 {
        return afb_req_json(to_req(xreq));
index a37b6bf..4230774 100644 (file)
@@ -27,6 +27,8 @@ struct afb_apiset;
 struct afb_event;
 struct afb_verb_desc_v1;
 struct afb_verb_v2;
+struct afb_req;
+struct afb_stored_req;
 
 struct afb_xreq_query_itf {
        struct json_object *(*json)(struct afb_xreq *xreq);
@@ -85,6 +87,7 @@ struct afb_xreq
 #define CONTAINER_OF_XREQ(type,x) CONTAINER_OF(type,xreq,x)
 
 /* req wrappers for xreq */
+extern struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq);
 extern void afb_xreq_addref(struct afb_xreq *xreq);
 extern void afb_xreq_unref(struct afb_xreq *xreq);