mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
allow loading of json configs
This commit is contained in:
parent
a43e430b1a
commit
8890767068
1 changed files with 11 additions and 9 deletions
|
@ -134,6 +134,14 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
|
|||
config_set_destructor(&sn->cfg, config_dtor);
|
||||
config_set_auto_convert(&sn->cfg, 1);
|
||||
|
||||
cfg_root = config_root_setting(&sn->cfg);
|
||||
|
||||
/* Little hack to properly report configuration filename in error messages
|
||||
* We add the uri as a "hook" object to the root setting.
|
||||
* See cerror() on how this info is used.
|
||||
*/
|
||||
config_setting_set_hook(cfg_root, strdup(uri));
|
||||
|
||||
/* Parse config */
|
||||
ret = config_read(&sn->cfg, f);
|
||||
if (ret != CONFIG_TRUE) {
|
||||
|
@ -143,6 +151,7 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
|
|||
json_error_t err;
|
||||
json_t *json;
|
||||
|
||||
rewind(f);
|
||||
json = json_loadf(f, 0, &err);
|
||||
if (json) {
|
||||
ret = json_to_config(json, cfg_root);
|
||||
|
@ -150,27 +159,20 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
|
|||
error("Failed t convert JSON to configuration file");
|
||||
}
|
||||
else {
|
||||
error("Failed to parse configuration");
|
||||
{ INDENT
|
||||
warn("conf: %s in %s:%d", config_error_text(&sn->cfg), uri, config_error_line(&sn->cfg));
|
||||
warn("json: %s in %s:%d:%d", err.text, err.source, err.line, err.column);
|
||||
}
|
||||
error("Failed to parse configuration");
|
||||
}
|
||||
#else
|
||||
error("Failed to parse configuration");
|
||||
{ INDENT
|
||||
warn("%s in %s:%d", config_error_text(&sn->cfg), uri, config_error_line(&sn->cfg));
|
||||
}
|
||||
error("Failed to parse configuration");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Little hack to properly report configuration filename in error messages
|
||||
* We add the uri as a "hook" object to the root setting.
|
||||
* See cerror() on how this info is used.
|
||||
*/
|
||||
cfg_root = config_root_setting(&sn->cfg);
|
||||
config_setting_set_hook(cfg_root, strdup(uri));
|
||||
|
||||
/* Close configuration file */
|
||||
if (af)
|
||||
afclose(af);
|
||||
|
|
Loading…
Add table
Reference in a new issue