diff options
author | Loïc Collignon <loic.collignon@iot.bzh> | 2017-11-09 15:01:54 +0100 |
---|---|---|
committer | Loïc Collignon <loic.collignon@iot.bzh> | 2017-11-09 15:01:54 +0100 |
commit | 21a76c1dff9efe890ac17e43b2e8c81e4818d193 (patch) | |
tree | 2274b5aed5e3cd8d99d907eb4ce613dac0bd8b34 | |
parent | b2301e492fc10be35a48ae1561a6ab90bcef1f2c (diff) |
make it use the nfc-binding.
Change-Id: Ia9e032d0a04f2712b7778732314cadee3ffdedbb
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
-rw-r--r-- | agl-identity-service/CMakeLists.txt | 3 | ||||
-rw-r--r-- | agl-identity-service/etc/config.json (renamed from agl-identity-service/src/config.json) | 4 | ||||
-rw-r--r-- | agl-identity-service/src/agl-forgerock.c | 1 | ||||
-rw-r--r-- | agl-identity-service/src/agl-identity-binding.c | 56 |
4 files changed, 60 insertions, 4 deletions
diff --git a/agl-identity-service/CMakeLists.txt b/agl-identity-service/CMakeLists.txt index 14b6d55..b70c1d1 100644 --- a/agl-identity-service/CMakeLists.txt +++ b/agl-identity-service/CMakeLists.txt @@ -19,3 +19,6 @@ cmake_minimum_required(VERSION 3.6) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/) include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake) + + +install(DIRECTORY etc DESTINATION ./) diff --git a/agl-identity-service/src/config.json b/agl-identity-service/etc/config.json index 613fc7a..d33b263 100644 --- a/agl-identity-service/src/config.json +++ b/agl-identity-service/etc/config.json @@ -1,6 +1,6 @@ { - "endpoint": "https://agl-graphapi.forgerocklabs.org/getuserprofilefromtoken", - "vin": "4T1BF1FK5GU260429", + "endpoint": "https://agl-graphapi.forgerocklabs.org:443/getuserprofilefromtoken", + "vin": "WVGGF7BP7HD005986", "autoadvise": true, "delay": 5, "idp": { diff --git a/agl-identity-service/src/agl-forgerock.c b/agl-identity-service/src/agl-forgerock.c index 9306c7a..2a0d3da 100644 --- a/agl-identity-service/src/agl-forgerock.c +++ b/agl-identity-service/src/agl-forgerock.c @@ -140,6 +140,7 @@ void agl_forgerock_setconfig(struct json_object *conf) confsetstr(conf, "endpoint", &endpoint, endpoint ? : default_endpoint); confsetint(conf, "delay", &expiration_delay, expiration_delay); confsetoidc(conf, "oidc-aia"); + AFB_NOTICE("Forgerock endpoint is: %s", endpoint); } void agl_forgerock_setcb(void (*callback)(struct json_object *data, const char *error)) diff --git a/agl-identity-service/src/agl-identity-binding.c b/agl-identity-service/src/agl-identity-binding.c index afb815d..e850c12 100644 --- a/agl-identity-service/src/agl-identity-binding.c +++ b/agl-identity-service/src/agl-identity-binding.c @@ -50,7 +50,12 @@ static struct json_object *readjson(int fd) buffer = alloca((size_t)(s.st_size)+1); if (read(fd, buffer, (size_t)s.st_size) == (ssize_t)s.st_size) { buffer[s.st_size] = 0; + //AFB_NOTICE("Config file: %s", buffer); result = json_tokener_parse(buffer); + //if (!result) + //{ + // AFB_ERROR("Config file is not a valid JSON: %s", json_tokener_error_desc(json_tokener_get_error(NULL))); + //} } } close(fd); @@ -61,6 +66,7 @@ static struct json_object *readjson(int fd) static struct json_object *get_global_config(const char *name, const char *locale) { int fd = afb_daemon_rootdir_open_locale(name, O_RDONLY, locale); + if (fd < 0) AFB_ERROR("Config file not found: %s", name); return fd < 0 ? NULL : readjson(fd); } @@ -94,7 +100,7 @@ static void setconfig(struct json_object *conf) static void readconfig() { - setconfig(get_global_config("config.json", NULL)); + setconfig(get_global_config("etc/config.json", NULL)); setconfig(get_local_config("/etc/agl/identity-agent-config.json")); setconfig(get_local_config("config.json")); } @@ -187,6 +193,23 @@ static void success (struct afb_req request) afb_req_success(request, NULL, NULL); } +static void on_nfc_subscribed(void *closure, int status, struct json_object *result) +{ + if(!status) + { + } + else AFB_ERROR("Failed to subscribe to nfc events."); +} + +static void on_nfc_started(void *closure, int status, struct json_object *result) +{ + if (!status) + { + afb_service_call("nfc", "subscribe", NULL, on_nfc_subscribed, NULL); + } + else AFB_ERROR("Failed to start nfc polling."); +} + static int service_init() { int rc; @@ -198,9 +221,38 @@ static int service_init() readconfig(); + if (afb_daemon_require_api("nfc", 1)) + return -1; + + afb_service_call("nfc", "start", NULL, on_nfc_started, NULL); + return 0; } +static void on_nfc_target_add(struct json_object *object) +{ + struct json_object * json_uid; + char *uid; + + if (json_object_object_get_ex(object, "UID", &json_uid)) + { + uid = json_object_get_string(json_uid); + AFB_NOTICE("nfc tag detected, call forgerock with vincode=%s and key=%s", vin ? vin : default_vin, uid); + agl_forgerock_download_request(vin ? vin : default_vin, "nfc", uid); + } + else AFB_ERROR("nfc target add event is received but no UID found: %s", json_object_to_json_string(object)); +} + +static void onevent(const char *event, struct json_object *object) +{ + AFB_NOTICE("Received event: %s", event); + if (!strcmp("nfc/on-nfc-target-add", event)) + { + on_nfc_target_add(object); + return; + } + AFB_WARNING("Unhandled event: %s", event); +} // NOTE: this sample does not use session to keep test a basic as possible // in real application most APIs should be protected with AFB_SESSION_CHECK @@ -221,7 +273,7 @@ const struct afb_binding_v2 afbBindingV2 = .verbs = verbs, .preinit = NULL, .init = service_init, - .onevent = NULL, + .onevent = onevent, .noconcurrency = 0 }; |