aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-11 13:35:48 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:49 +0100
commit9a4ba373acf7b7feac6d980506bcdad20b96bdb6 (patch)
tree91374e82bd7f3088e68903402d1d73fab1287666
parentc4b36f01f3286a1c7f183323df00b36270c8498b (diff)
Check key exists before loading JSON file
Change-Id: I99d84fb56b01896caf6daa26ca50896f770ff509 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 55c11fe..a155062 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -168,30 +168,37 @@ void loadConf(afb_req request)
Composer& composer = Composer::instance();
json_object *sourcesJ = nullptr,
*signalsJ = nullptr;
- const char* filepath = afb_req_value(request, "filepath");
+ const char* filepath = afb_req_value(request, "file");
- json_object *fileJ = json_object_from_file(filepath);
+ if(filepath)
+ {
+ json_object *fileJ = json_object_from_file(filepath);
- json_object_object_get_ex(fileJ, "sources", &sourcesJ);
- json_object_object_get_ex(fileJ, "signals", &signalsJ);
+ json_object_object_get_ex(fileJ, "sources", &sourcesJ);
+ json_object_object_get_ex(fileJ, "signals", &signalsJ);
- if( sourcesJ && composer.loadSources(sourcesJ))
- {
- afb_req_fail_f(request, "Loading 'sources' configuration or subscription error", "Error code: -1");
- json_object_put(fileJ);
- return;
- }
- if(signalsJ && composer.loadSignals(signalsJ))
- {
- afb_req_fail_f(request, "Loading 'signals' configuration or subscription error", "Error code: -1");
+ if( sourcesJ && composer.loadSources(sourcesJ))
+ {
+ afb_req_fail_f(request, "Loading 'sources' configuration or subscription error", "Error code: -2");
+ json_object_put(fileJ);
+ return;
+ }
+ if(signalsJ)
+ {
+ if(!composer.loadSignals(signalsJ))
+ {composer.initSignals();}
+ else
+ {
+ afb_req_fail_f(request, "Loading 'signals' configuration or subscription error", "Error code: -2");
+ json_object_put(fileJ);
+ return;
+ }
+ }
json_object_put(fileJ);
- return;
+ afb_req_success(request, NULL, NULL);
}
else
- {composer.initSignals();}
-
- json_object_put(fileJ);
- afb_req_success(request, NULL, NULL);
+ {afb_req_fail_f(request, "No 'file' key found in request argument", "Error code: -1");}
}
/// @brief entry point to list available signals