Update copyright dates
[src/app-framework-binder.git] / src / afb-api-so-v1.c
index c7b40e8..66de002 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-#if defined(WITH_LEGACY_BINDING_V1)
+#if WITH_LEGACY_BINDING_V1 && WITH_DYNAMIC_BINDING
 
 #define _GNU_SOURCE
 
@@ -36,6 +36,7 @@
 #include "afb-context.h"
 #include "afb-api-so.h"
 #include "afb-xreq.h"
+#include "afb-auth.h"
 #include "verbose.h"
 
 /*
@@ -63,40 +64,6 @@ void afb_api_so_v1_process_call(struct afb_binding_v1 *binding, struct afb_xreq
        afb_xreq_call_verb_v1(xreq, verb);
 }
 
-static struct json_object *addperm(struct json_object *o, struct json_object *x)
-{
-       struct json_object *a;
-
-       if (!o)
-               return x;
-
-       if (!json_object_object_get_ex(o, "allOf", &a)) {
-               a = json_object_new_array();
-               json_object_array_add(a, o);
-               o = json_object_new_object();
-               json_object_object_add(o, "allOf", a);
-       }
-       json_object_array_add(a, x);
-       return o;
-}
-
-static struct json_object *addperm_key_val(struct json_object *o, const char *key, struct json_object *val)
-{
-       struct json_object *x = json_object_new_object();
-       json_object_object_add(x, key, val);
-       return addperm(o, x);
-}
-
-static struct json_object *addperm_key_valstr(struct json_object *o, const char *key, const char *val)
-{
-       return addperm_key_val(o, key, json_object_new_string(val));
-}
-
-static struct json_object *addperm_key_valint(struct json_object *o, const char *key, int val)
-{
-       return addperm_key_val(o, key, json_object_new_int(val));
-}
-
 struct json_object *afb_api_so_v1_make_description_openAPIv3(struct afb_binding_v1 *binding, const char *apiname)
 {
        char buffer[256];
@@ -124,15 +91,7 @@ struct json_object *afb_api_so_v1_make_description_openAPIv3(struct afb_binding_
                g = json_object_new_object();
                json_object_object_add(f, "get", g);
 
-               a = NULL;
-               if (verb->session & AFB_SESSION_CLOSE_X1)
-                       a = addperm_key_valstr(a, "session", "close");
-               if (verb->session & AFB_SESSION_CHECK_X1)
-                       a = addperm_key_valstr(a, "session", "check");
-               if (verb->session & AFB_SESSION_RENEW_X1)
-                       a = addperm_key_valstr(a, "token", "refresh");
-               if (verb->session & AFB_SESSION_LOA_MASK_X1)
-                       a = addperm_key_valint(a, "LOA", (verb->session >> AFB_SESSION_LOA_SHIFT_X1) & AFB_SESSION_LOA_MASK_X1);
+               a = afb_auth_json_x1(verb->session);
                if (a)
                        json_object_object_add(g, "x-permissions", a);
 
@@ -164,7 +123,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *declare
        /* allocates the description */
        init = dlsym(handle, afb_api_so_v1_service_init);
        onevent = dlsym(handle, afb_api_so_v1_service_event);
-       export = afb_export_create_v1(declare_set, call_set, path, init, onevent);
+       export = afb_export_create_v1(declare_set, call_set, path, init, onevent, path);
        if (export == NULL) {
                ERROR("binding [%s] creation failure...", path);
                goto error;