X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so-v1.c;h=66de002244a6fd9e5f1be0b06e6bd9f47cbb186a;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=7db686d87c881e378f37e8754d18a594cc84ec74;hpb=4521c1e7ae5371ab9d639adc617d17fb4e8ded0c;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c index 7db686d8..66de0022 100644 --- a/src/afb-api-so-v1.c +++ b/src/afb-api-so-v1.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +15,8 @@ * limitations under the License. */ +#if WITH_LEGACY_BINDING_V1 && WITH_DYNAMIC_BINDING + #define _GNU_SOURCE #include @@ -34,6 +36,7 @@ #include "afb-context.h" #include "afb-api-so.h" #include "afb-xreq.h" +#include "afb-auth.h" #include "verbose.h" /* @@ -61,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]; @@ -122,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); @@ -162,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; @@ -217,3 +178,5 @@ error: return -1; } +#endif +