aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2019-07-04 09:58:31 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2019-07-04 09:58:31 +0200
commite352daf17414bc5dc347bc844b76607475878124 (patch)
tree6c62270cb171dfe2990710d844b86418e287259e
parente822529742de0fc8039f61ce8b3d2726015bc478 (diff)
Update supervisor config fields name
ws_servers and ws_clients fields have been renamed in afs-supervisor and now these fields may also be missing. Change-Id: Icafdbeeb503b7ada732075449b1819f035ff5a27
-rw-r--r--.vscode/launch.json2
-rw-r--r--src/plugins/supervisor-api.c5
-rw-r--r--src/plugins/supervisor.c17
3 files changed, 14 insertions, 10 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 2546d49..8473608 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -14,7 +14,7 @@
"--name=afb-xds",
"--ws-client=unix:/tmp/supervisor",
"--ws-client=unix:/tmp/harvester",
- "--workdir=${workspaceRoot}/build/package/",
+ "--workdir=${workspaceRoot}/build/package",
"--ldpaths=lib",
"--roothttp=htdocs",
"--token=",
diff --git a/src/plugins/supervisor-api.c b/src/plugins/supervisor-api.c
index 33e52c6..cb2b476 100644
--- a/src/plugins/supervisor-api.c
+++ b/src/plugins/supervisor-api.c
@@ -63,7 +63,7 @@ CTLP_CAPI(list, source, argsJ, eventJ)
result = json_object_new_array();
for (int i = 0; i < daemons->count; i++) {
- wrap_json_pack(&item, "{si ss sb sb so so so}",
+ int rc = wrap_json_pack(&item, "{si ss sb sb s?o s?o so}",
"pid", daemons->daemons[i]->pid,
"name", daemons->daemons[i]->name,
"isServer", daemons->daemons[i]->isServer,
@@ -72,6 +72,9 @@ CTLP_CAPI(list, source, argsJ, eventJ)
"ws_clients", daemons->daemons[i]->ws_clients,
"apis", daemons->daemons[i]->apis);
//, "config", daemons->daemons[i]->config);
+ if (rc) {
+ AFB_API_ERROR(source->api, "wrap_json_pack error %d: %s", rc, wrap_json_get_error_string(rc));
+ }
json_object_array_add(result, item);
}
diff --git a/src/plugins/supervisor.c b/src/plugins/supervisor.c
index 168e298..6d6980f 100644
--- a/src/plugins/supervisor.c
+++ b/src/plugins/supervisor.c
@@ -46,7 +46,7 @@ static void decode_daemons_cb(void* closure, json_object* obj, const char* fName
{
int rc;
struct afb_cred cred;
- json_object *j_response, *j_query, *j_config, *j_ws_servers, *j_ws_clients;
+ json_object *j_response, *j_query, *j_config, *j_ws_servers = NULL, *j_ws_clients = NULL;
json_object *j_name, *j_apis;
struct decode_daemon_str* clStr = (struct decode_daemon_str*)closure;
DAEMON_T* daemon = calloc(sizeof(DAEMON_T), 1);
@@ -81,10 +81,10 @@ static void decode_daemons_cb(void* closure, json_object* obj, const char* fName
// FIXME : implement free
daemon->config = j_config;
- rc = wrap_json_unpack(j_config, "{s:o s:o s:o}",
+ rc = wrap_json_unpack(j_config, "{s:o s:?o s:?o}",
"name", &j_name,
- "ws_servers", &j_ws_servers,
- "ws_clients", &j_ws_clients);
+ "ws-server", &j_ws_servers,
+ "ws-client", &j_ws_clients);
if (rc < 0) {
AFB_API_ERROR(clStr->api, "Error decoding config response %s", wrap_json_get_error_string(rc));
return;
@@ -98,10 +98,11 @@ static void decode_daemons_cb(void* closure, json_object* obj, const char* fName
return;
}
- daemon->ws_servers = j_ws_servers;
- daemon->isServer = (json_object_array_length(j_ws_servers) > 0);
- daemon->ws_clients = j_ws_clients;
- daemon->isClient = (json_object_array_length(j_ws_clients) > 0);
+ daemon->isServer = j_ws_servers && (json_object_array_length(j_ws_servers) > 0);
+ daemon->ws_servers = (daemon->isServer) ? j_ws_servers : json_object_new_array();
+
+ daemon->isClient = j_ws_clients && (json_object_array_length(j_ws_clients) > 0);
+ daemon->ws_clients = (daemon->isClient) ? j_ws_clients : json_object_new_array();
}
// Get apis