- verbose(level, file, line, "%s {binding %s}", p, desc->binding->v1.prefix);
- free(p);
- }
-}
-
-static int afb_api_so_rootdir_get_fd(void *closure)
-{
- return afb_common_rootdir_get_fd();
-}
-
-static int afb_api_so_rootdir_open_locale(void *closure, const char *filename, int flags, const char *locale)
-{
- return afb_common_rootdir_open_locale(filename, flags, locale);
-}
-
-static int call_check(struct afb_req req, struct afb_context *context, const struct afb_verb_desc_v1 *verb)
-{
- int stag = (int)verb->session;
-
- if ((stag & (AFB_SESSION_CREATE|AFB_SESSION_CLOSE|AFB_SESSION_RENEW|AFB_SESSION_CHECK|AFB_SESSION_LOA_EQ)) != 0) {
- if (!afb_context_check(context)) {
- afb_context_close(context);
- afb_req_fail(req, "failed", "invalid token's identity");
- return 0;
- }
- }
-
- if ((stag & AFB_SESSION_CREATE) != 0) {
- if (afb_context_check_loa(context, 1)) {
- afb_req_fail(req, "failed", "invalid creation state");
- return 0;
- }
- afb_context_change_loa(context, 1);
- afb_context_refresh(context);
- }
-
- if ((stag & (AFB_SESSION_CREATE | AFB_SESSION_RENEW)) != 0)
- afb_context_refresh(context);
-
- if ((stag & AFB_SESSION_CLOSE) != 0) {
- afb_context_change_loa(context, 0);
- afb_context_close(context);
- }
-
- if ((stag & AFB_SESSION_LOA_GE) != 0) {
- int loa = (stag >> AFB_SESSION_LOA_SHIFT) & AFB_SESSION_LOA_MASK;
- if (!afb_context_check_loa(context, loa)) {
- afb_req_fail(req, "failed", "invalid LOA");
- return 0;
- }
- }
-
- if ((stag & AFB_SESSION_LOA_LE) != 0) {
- int loa = (stag >> AFB_SESSION_LOA_SHIFT) & AFB_SESSION_LOA_MASK;
- if (afb_context_check_loa(context, loa + 1)) {
- afb_req_fail(req, "failed", "invalid LOA");
- return 0;
- }
- }
- return 1;
-}
-
-static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *strverb, size_t lenverb)
-{
- const struct afb_verb_desc_v1 *verb;
- struct api_so_desc *desc = closure;
-
- verb = desc->binding->v1.verbs;
- while (verb->name && (strncasecmp(verb->name, strverb, lenverb) || verb->name[lenverb]))
- verb++;
- if (!verb->name)
- afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, strverb, desc->binding->v1.prefix);
- else if (call_check(req, context, verb)) {
- if (0)
- /* not threaded */
- afb_sig_req_timeout(req, verb->callback, api_timeout);
- else
- /* threaded */
- afb_thread_call(req, verb->callback, api_timeout, desc);
- }
-}
-
-static int service_start_cb(void *closure, int share_session, int onneed)
-{
- int (*init)(struct afb_service service);
- void (*onevent)(const char *event, struct json_object *object);
-
- struct api_so_desc *desc = closure;
-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->binding->v1.prefix);
- return -1;
- }
-
- /* get the initialisation */
- init = dlsym(desc->handle, binding_service_init_function_v1);
- if (init == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->binding->v1.prefix);
- return -1;