1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

some refactoring in json parsing

This commit is contained in:
Steffen Vogel 2017-10-16 08:08:35 +02:00
parent 8806b8cc34
commit ce5f4e5a60
17 changed files with 200 additions and 200 deletions

View file

@ -59,9 +59,9 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
{
int ret;
json_t *cfg_ips;
json_t *cfg_slot = NULL;
json_t *cfg_id = NULL;
json_t *json_ips;
json_t *json_slot = NULL;
json_t *json_id = NULL;
json_error_t err;
c->name = strdup(name);
@ -69,17 +69,17 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
ret = json_unpack_ex(cfg, &err, 0, "{ s?: i, s?: b, s?: o, s?: o, s: o }"
"affinity", &c->affinity,
"do_reset", &c->do_reset,
"slot", &cfg_slot,
"id", &cfg_id,
"ips", &cfg_ips
"slot", &json_slot,
"id", &json_id,
"ips", &json_ips
);
if (ret)
jerror(&err, "Failed to parse FPGA vard configuration");
if (cfg_slot) {
if (json_slot) {
const char *err, *slot;
slot = json_string_value(cfg_slot);
slot = json_string_value(json_slot);
if (slot) {
ret = pci_device_parse_slot(&c->filter, slot, &err);
if (ret)
@ -89,10 +89,10 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
error("PCI slot must be a string");
}
if (cfg_id) {
if (json_id) {
const char *err, *id;
id = json_string_value(cfg_id);
id = json_string_value(json_id);
if (id) {
ret = pci_device_parse_id(&c->filter, (char*) id, &err);
if (ret)
@ -102,12 +102,12 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
error("PCI ID must be a string");
}
if (!json_is_object(cfg_ips))
if (!json_is_object(json_ips))
error("FPGA card IPs section must be an object");
const char *name_ip;
json_t *cfg_ip;
json_object_foreach(cfg_ips, name_ip, cfg_ip) {
json_t *json_ip;
json_object_foreach(json_ips, name_ip, json_ip) {
const char *vlnv;
struct fpga_ip_type *vt;
@ -115,7 +115,7 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
ip->card = c;
ret = json_unpack_ex(cfg_ip, &err, 0, "{ s: s }", "vlnv", &vlnv);
ret = json_unpack_ex(json_ip, &err, 0, "{ s: s }", "vlnv", &vlnv);
if (ret)
error("Failed to parse FPGA IP '%s' of card '%s'", name_ip, name);
@ -127,7 +127,7 @@ int fpga_card_parse(struct fpga_card *c, json_t *cfg, const char *name)
if (ret)
error("Failed to initalize FPGA IP core");
ret = fpga_ip_parse(ip, cfg_ip, name_ip);
ret = fpga_ip_parse(ip, json_ip, name_ip);
if (ret)
error("Failed to parse FPGA IP core");
@ -147,11 +147,11 @@ int fpga_card_parse_list(struct list *cards, json_t *cfg)
error("FPGA card configuration section must be a JSON object");
const char *name;
json_t *cfg_fpga;
json_object_foreach(cfg, name, cfg_fpga) {
json_t *json_fpga;
json_object_foreach(cfg, name, json_fpga) {
struct fpga_card *c = alloc(sizeof(struct fpga_card));
ret = fpga_card_parse(c, cfg_fpga, name);
ret = fpga_card_parse(c, json_fpga, name);
if (ret)
error("Failed to parse FPGA card configuration");

View file

@ -19,33 +19,33 @@ int dft_parse(struct fpga_ip *c, json_t *cfg)
int ret;
json_t *cfg_harms;
json_t *json_harms;
json_error_t err;
ret = json_unpack_ex(cfg, &err, 0, "{ s: i, s: i, s: o }",
"period", &dft->period,
"decimation", &dft->decimation,
"harmonics", &cfg_harms
"harmonics", &json_harms
);
if (ret)
jerror(&err, "Failed to parse configuration of FPGA IP '%s'", c->name);
if (!json_is_array(cfg_harms))
if (!json_is_array(json_harms))
error("DFT IP core requires 'harmonics' to be an array of integers!");
dft->num_harmonics = json_array_size(cfg_harms);
dft->num_harmonics = json_array_size(json_harms);
if (dft->num_harmonics <= 0)
error("DFT IP core requires 'harmonics' to contain at least 1 value!");
dft->fharmonics = alloc(sizeof(float) * dft->num_harmonics);
size_t index;
json_t *cfg_harm;
json_array_foreach(cfg_harms, index, cfg_harm) {
if (!json_is_real(cfg_harm))
json_t *json_harm;
json_array_foreach(json_harms, index, json_harm) {
if (!json_is_real(json_harm))
error("DFT IP core requires all 'harmonics' values to be of floating point type");
dft->fharmonics[index] = (float) json_number_value(cfg_harm) / dft->period;
dft->fharmonics[index] = (float) json_number_value(json_harm) / dft->period;
}
return 0;

View file

@ -139,7 +139,7 @@ int model_parse(struct fpga_ip *c, json_t *cfg)
int ret;
json_t *cfg_params;
json_t *json_params;
json_error_t err;
if (strcmp(c->vlnv.library, "hls") == 0)
@ -149,17 +149,17 @@ int model_parse(struct fpga_ip *c, json_t *cfg)
else
error("Unsupported model type: %s", c->vlnv.library);
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o }", "parameters", &cfg_params);
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o }", "parameters", &json_params);
if (ret)
jerror(&err, "Failed to parse configuration of FPGA IP '%s'", c->name);
if (cfg_params) {
if (!json_is_object(cfg_params))
if (json_params) {
if (!json_is_object(json_params))
error("Setting 'parameters' must be a JSON object");
const char *name;
json_t *value;
json_object_foreach(cfg_params, name, value) {
json_object_foreach(json_params, name, value) {
if (!json_is_real(value))
error("Parameters of FPGA IP '%s' must be of type floating point", c->name);

View file

@ -95,28 +95,28 @@ int switch_parse(struct fpga_ip *c, json_t *cfg)
int ret;
size_t index;
json_error_t err;
json_t *cfg_path, *cfg_paths = NULL;
json_t *json_path, *json_paths = NULL;
list_init(&sw->paths);
ret = json_unpack_ex(cfg, &err, 0, "{ s: i, s?: o }",
"num_ports", &sw->num_ports,
"paths", &cfg_paths
"paths", &json_paths
);
if (ret)
jerror(&err, "Failed to parse configuration of FPGA IP '%s'", c->name);
if (!cfg_paths)
if (!json_paths)
return 0; /* no switch config available */
if (!json_is_array(cfg_paths))
if (!json_is_array(json_paths))
error("Setting 'paths' of FPGA IP '%s' should be an array of JSON objects", c->name);
json_array_foreach(cfg_paths, index, cfg_path) {
json_array_foreach(json_paths, index, json_path) {
struct sw_path *p = alloc(sizeof(struct sw_path));
int reverse = 0;
ret = json_unpack_ex(cfg_path, &err, 0, "{ s?: b, s: s, s: s }",
ret = json_unpack_ex(json_path, &err, 0, "{ s?: b, s: s, s: s }",
"reverse", &reverse,
"in", &p->in,
"out", &p->out

View file

@ -246,14 +246,14 @@ int hook_parse_list(struct list *list, json_t *cfg, struct path *o, struct node
error("Hooks must be configured as a list of objects");
size_t index;
json_t *cfg_hook;
json_array_foreach(cfg, index, cfg_hook) {
json_t *json_hook;
json_array_foreach(cfg, index, json_hook) {
int ret;
const char *type;
struct plugin *p;
json_error_t err;
ret = json_unpack_ex(cfg_hook, &err, 0, "{ s: s }", "type", &type);
ret = json_unpack_ex(json_hook, &err, 0, "{ s: s }", "type", &type);
if (ret)
jerror(&err, "Failed to parse hook");
@ -267,7 +267,7 @@ int hook_parse_list(struct list *list, json_t *cfg, struct path *o, struct node
if (ret)
error("Failed to initialize hook: %s", p->name);
ret = hook_parse(h, cfg_hook);
ret = hook_parse(h, json_hook);
if (ret)
jerror(&err, "Failed to parse hook configuration");

View file

@ -59,15 +59,15 @@ static int map_parse(struct hook *h, json_t *cfg)
int ret;
struct map *m = h->_vd;
json_error_t err;
json_t *cfg_mapping;
json_t *json_mapping;
ret = json_unpack_ex(cfg, &err, 0, "{ s: o }",
"map", &cfg_mapping
"map", &json_mapping
);
if (ret)
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
ret = mapping_parse_list(&m->mapping, cfg_mapping, NULL);
ret = mapping_parse_list(&m->mapping, json_mapping, NULL);
if (ret)
return ret;

View file

@ -40,24 +40,24 @@ int tc_parse(struct rtnl_qdisc **netem, json_t *cfg)
const char *str;
int ret, val;
json_t *cfg_distribution = NULL;
json_t *cfg_limit = NULL;
json_t *cfg_delay = NULL;
json_t *cfg_jitter = NULL;
json_t *cfg_loss = NULL;
json_t *cfg_duplicate = NULL;
json_t *cfg_corruption = NULL;
json_t *json_distribution = NULL;
json_t *json_limit = NULL;
json_t *json_delay = NULL;
json_t *json_jitter = NULL;
json_t *json_loss = NULL;
json_t *json_duplicate = NULL;
json_t *json_corruption = NULL;
json_error_t err;
"distribution", &cfg_distribution,
"limit", &cfg_limit,
"delay", &cfg_delay,
"jitter", &cfg_jitter,
"loss", &cfg_loss,
"duplicate", &cfg_duplicate,
"corruption", &cfg_corruption
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o, s?: o, s?: o, s?: o, s?: o, s?: o, s?: o }",
"distribution", &json_distribution,
"limit", &json_limit,
"delay", &json_delay,
"jitter", &json_jitter,
"loss", &json_loss,
"duplicate", &json_duplicate,
"corruption", &json_corruption
);
if (ret)
jerror(&err, "Failed to parse setting network emulation settings");
@ -68,8 +68,8 @@ int tc_parse(struct rtnl_qdisc **netem, json_t *cfg)
rtnl_tc_set_kind(TC_CAST(ne), "netem");
if (cfg_distribution) {
str = json_string_value(cfg_distribution);
if (json_distribution) {
str = json_string_value(json_distribution);
if (!str)
error("Setting 'distribution' must be a JSON string");
@ -77,10 +77,10 @@ int tc_parse(struct rtnl_qdisc **netem, json_t *cfg)
error("Invalid delay distribution '%s' in netem config", str);
}
if (cfg_limit) {
val = json_integer_value(cfg_limit);
if (json_limit) {
val = json_integer_value(json_limit);
if (!json_is_integer(cfg_limit) || val <= 0)
if (!json_is_integer(json_limit) || val <= 0)
error("Setting 'limit' must be a positive integer");
rtnl_netem_set_limit(ne, val);
@ -88,46 +88,46 @@ int tc_parse(struct rtnl_qdisc **netem, json_t *cfg)
else
rtnl_netem_set_limit(ne, 0);
if (cfg_delay) {
val = json_integer_value(cfg_delay);
if (json_delay) {
val = json_integer_value(json_delay);
if (!json_is_integer(cfg_delay) || val <= 0)
if (!json_is_integer(json_delay) || val <= 0)
error("Setting 'delay' must be a positive integer");
rtnl_netem_set_delay(ne, val);
}
if (cfg_jitter) {
val = json_integer_value(cfg_jitter);
if (json_jitter) {
val = json_integer_value(json_jitter);
if (!json_is_integer(cfg_jitter) || val <= 0)
if (!json_is_integer(json_jitter) || val <= 0)
error("Setting 'jitter' must be a positive integer");
rtnl_netem_set_jitter(ne, val);
}
if (cfg_loss) {
val = json_integer_value(cfg_loss);
if (json_loss) {
val = json_integer_value(json_loss);
if (!json_is_integer(cfg_loss) || val < 0 || val > 100)
if (!json_is_integer(json_loss) || val < 0 || val > 100)
error("Setting 'loss' must be a positive integer within the range [ 0, 100 ]");
rtnl_netem_set_loss(ne, val);
}
if (cfg_duplicate) {
val = json_integer_value(cfg_duplicate);
if (json_duplicate) {
val = json_integer_value(json_duplicate);
if (!json_is_integer(cfg_duplicate) || val < 0 || val > 100)
if (!json_is_integer(json_duplicate) || val < 0 || val > 100)
error("Setting 'duplicate' must be a positive integer within the range [ 0, 100 ]");
rtnl_netem_set_duplicate(ne, val);
}
if (cfg_corruption) {
val = json_integer_value(cfg_corruption);
if (json_corruption) {
val = json_integer_value(json_corruption);
if (!json_is_integer(cfg_corruption) || val < 0 || val > 100)
if (!json_is_integer(json_corruption) || val < 0 || val > 100)
error("Setting 'corruption' must be a positive integer within the range [ 0, 100 ]");
rtnl_netem_set_corruption_probability(ne, val);

View file

@ -16,7 +16,7 @@
int cbuilder_parse(struct node *n, json_t *cfg)
{
struct cbuilder *cb = n->_vd;
json_t *cfg_param, *cfg_params = NULL;
json_t *json_param, *json_params = NULL;
const char *model;
@ -27,7 +27,7 @@ int cbuilder_parse(struct node *n, json_t *cfg)
ret = json_unpack_ex(cfg, &err, 0, "{ s: F, s: s, s: b }",
"timestep", &cb->timestep,
"model", &model,
"parameters", &cfg_params
"parameters", &json_params
);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
@ -36,18 +36,18 @@ int cbuilder_parse(struct node *n, json_t *cfg)
if (!cb->model)
error("Unknown model '%s' of node %s", model, node_name(n));
if (cfg_params) {
if (!json_is_array(cfg_params))
if (json_params) {
if (!json_is_array(json_params))
error("Setting 'parameters' of node %s must be an JSON array of numbers!", node_name(n));
cb->paramlen = json_array_size(cfg_params);
cb->paramlen = json_array_size(json_params);
cb->params = alloc(cb->paramlen * sizeof(double));
json_array_foreach(cfg_params, index, cfg_param) {
if (json_is_number(cfg_param))
json_array_foreach(json_params, index, json_param) {
if (json_is_number(json_param))
error("Setting 'parameters' of node %s must be an JSON array of numbers!", node_name(n));
cb->params[index] = json_number_value(cfg_params);
cb->params[index] = json_number_value(json_params);
}
}

View file

@ -44,15 +44,15 @@ int fpga_init(struct super_node *sn)
error("Failed to initiliaze VFIO sub-system");
#if 0
json_t *cfg, *cfg_fpgas;
json_t *cfg, *json_fpgas;
/* Parse FPGA configuration */
cfg = config_root_setting(&sn->cfg);
cfg_fpgas = config_setting_lookup(cfg, "fpgas");
if (!cfg_fpgas)
json_fpgas = config_setting_lookup(cfg, "fpgas");
if (!json_fpgas)
cerror(cfg, "Config file is missing 'fpgas' section");
ret = fpga_card_parse_list(&cards, cfg_fpgas);
ret = fpga_card_parse_list(&cards, json_fpgas);
if (ret)
cerror(cfg, "Failed to parse VILLASfpga config");
#endif

View file

@ -51,12 +51,12 @@ static int nanomsg_parse_endpoints(struct list *l, json_t *cfg)
const char *ep;
size_t index;
json_t *cfg_val;
json_t *json_val;
switch (json_typeof(cfg)) {
case JSON_ARRAY:
json_array_foreach(cfg, index, cfg_val) {
ep = json_string_value(cfg_val);
json_array_foreach(cfg, index, json_val) {
ep = json_string_value(json_val);
if (!ep)
return -1;
@ -86,28 +86,28 @@ int nanomsg_parse(struct node *n, json_t *cfg)
json_error_t err;
json_t *cfg_pub = NULL;
json_t *cfg_sub = NULL;
json_t *json_pub = NULL;
json_t *json_sub = NULL;
list_init(&m->publisher.endpoints);
list_init(&m->subscriber.endpoints);
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o, s?: o, s?: s }",
"publish", &cfg_pub,
"subscribe", &cfg_sub,
"publish", &json_pub,
"subscribe", &json_sub,
"format", &format
);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
if (cfg_pub) {
ret = nanomsg_parse_endpoints(&m->publisher.endpoints, cfg_pub);
if (json_pub) {
ret = nanomsg_parse_endpoints(&m->publisher.endpoints, json_pub);
if (ret < 0)
error("Invalid type for 'publish' setting of node %s", node_name(n));
}
if (cfg_sub) {
ret = nanomsg_parse_endpoints(&m->subscriber.endpoints, cfg_sub);
if (json_sub) {
ret = nanomsg_parse_endpoints(&m->subscriber.endpoints, json_sub);
if (ret < 0)
error("Invalid type for 'subscribe' setting of node %s", node_name(n));
}

View file

@ -205,12 +205,12 @@ static int ngsi_parse_mapping(struct list *mapping, json_t *cfg)
list_init(mapping);
size_t index;
json_t *cfg_token;
json_t *json_token;
json_array_foreach(cfg, index, cfg_token) {
json_array_foreach(cfg, index, json_token) {
const char *token;
token = json_string_value(cfg_token);
token = json_string_value(json_token);
if (!token)
return -2;
@ -410,7 +410,7 @@ int ngsi_parse(struct node *n, json_t *cfg)
int ret;
json_error_t err;
json_t *cfg_mapping;
json_t *json_mapping;
/* Default values */
i->access_token = NULL; /* disabled by default */
@ -426,12 +426,12 @@ int ngsi_parse(struct node *n, json_t *cfg)
"ssl_verify", &i->ssl_verify,
"timeout", &i->timeout,
"rate", &i->rate,
"mapping", &cfg_mapping
"mapping", &json_mapping
);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
ret = ngsi_parse_mapping(&i->mapping, cfg_mapping);
ret = ngsi_parse_mapping(&i->mapping, json_mapping);
if (ret)
error("Invalid setting 'mapping' of node %s", node_name(n));

View file

@ -42,7 +42,7 @@ int shmem_parse(struct node *n, json_t *cfg)
const char *val;
int ret;
json_t *cfg_exec = NULL;
json_t *json_exec = NULL;
json_error_t err;
/* Default values */
@ -56,21 +56,21 @@ int shmem_parse(struct node *n, json_t *cfg)
"in_name", &shm->in_name,
"queuelen", &shm->conf.queuelen,
"polling", &shm->conf.polling,
"exec", &cfg_exec
"exec", &json_exec
);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
if (cfg_exec) {
if (!json_is_array(cfg_exec))
if (json_exec) {
if (!json_is_array(json_exec))
error("Setting 'exec' of node %s must be a JSON array of strings", node_name(n));
shm->exec = alloc(sizeof(char *) * (json_array_size(cfg_exec) + 1));
shm->exec = alloc(sizeof(char *) * (json_array_size(json_exec) + 1));
size_t index;
json_t *cfg_val;
json_array_foreach(cfg_exec, index, cfg_val) {
val = json_string_value(cfg_exec);
json_t *json_val;
json_array_foreach(json_exec, index, json_val) {
val = json_string_value(json_exec);
if (!val)
error("Setting 'exec' of node %s must be a JSON array of strings", node_name(n));

View file

@ -389,7 +389,7 @@ int socket_parse(struct node *n, json_t *cfg)
int ret;
json_t *cfg_multicast = NULL;
json_t *json_multicast = NULL;
json_error_t err;
/* Default values */
@ -401,7 +401,7 @@ int socket_parse(struct node *n, json_t *cfg)
"remote", &remote,
"local", &local,
"verify_source", &s->verify_source,
"multicast", &cfg_multicast,
"multicast", &json_multicast,
"format", &format
);
if (ret)
@ -438,7 +438,7 @@ int socket_parse(struct node *n, json_t *cfg)
remote, node_name(n), gai_strerror(ret));
}
if (cfg_multicast) {
if (json_multicast) {
const char *group, *interface = NULL;
/* Default values */
@ -447,7 +447,7 @@ int socket_parse(struct node *n, json_t *cfg)
s->multicast.loop = 0;
s->multicast.ttl = 255;
ret = json_unpack_ex(cfg_multicast, &err, 0, "{ s?: b, s: s, s?: s, s?: b, s?: i }",
ret = json_unpack_ex(json_multicast, &err, 0, "{ s?: b, s: s, s?: s, s?: b, s?: i }",
"enabled", &s->multicast.enabled,
"group", &group,
"interface", &interface,
@ -473,18 +473,18 @@ int socket_parse(struct node *n, json_t *cfg)
}
#ifdef WITH_NETEM
json_t *cfg_netem;
json_t *json_netem;
cfg_netem = json_object_get(cfg, "netem");
if (cfg_netem) {
json_netem = json_object_get(cfg, "netem");
if (json_netem) {
int enabled = 1;
ret = json_unpack_ex(cfg_netem, &err, 0, "{ s?: b }", "enabled", &enabled);
ret = json_unpack_ex(json_netem, &err, 0, "{ s?: b }", "enabled", &enabled);
if (ret)
jerror(&err, "Failed to parse setting 'netem' of node %s", node_name(n));
if (enabled)
tc_parse(&s->tc_qdisc, cfg_netem);
tc_parse(&s->tc_qdisc, json_netem);
else
s->tc_qdisc = NULL;
}

View file

@ -82,8 +82,8 @@ int test_rtt_parse(struct node *n, json_t *cfg)
int numvalues = 0;
size_t index;
json_t *cfg_cases, *cfg_case, *cfg_val;
json_t *cfg_rates = NULL, *cfg_values = NULL;
json_t *json_cases, *json_case, *json_val;
json_t *json_rates = NULL, *json_values = NULL;
json_error_t err;
t->cooldown = 1.0;
@ -96,7 +96,7 @@ int test_rtt_parse(struct node *n, json_t *cfg)
"output", &output,
"format", &format,
"cooldown", &t->cooldown,
"cases", &cfg_cases
"cases", &json_cases
);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
@ -111,16 +111,16 @@ int test_rtt_parse(struct node *n, json_t *cfg)
/* Construct list of test cases */
if (!json_is_array(cfg_cases))
if (!json_is_array(json_cases))
error("The 'cases' setting of node %s must be an array.", node_name(n));
json_array_foreach(cfg_cases, index, cfg_case) {
json_array_foreach(json_cases, index, json_case) {
int limit = -1;
double duration = -1; /* in secs */
ret = json_unpack_ex(cfg_case, &err, 0, "{ s: o, s: o, s?: i, s?: F }",
"rates", &cfg_rates,
"values", &cfg_values,
ret = json_unpack_ex(json_case, &err, 0, "{ s: o, s: o, s?: i, s?: F }",
"rates", &json_rates,
"values", &json_values,
"limit", &limit,
"duration", &duration
);
@ -128,16 +128,16 @@ int test_rtt_parse(struct node *n, json_t *cfg)
if (limit > 0 && duration > 0)
error("The settings 'duration' and 'limit' of node %s must be used exclusively", node_name(n));
if (json_is_array(cfg_rates))
numrates = json_array_size(cfg_rates);
else if (json_is_number(cfg_rates))
if (json_is_array(json_rates))
numrates = json_array_size(json_rates);
else if (json_is_number(json_rates))
numrates = 1;
else
error("The 'rates' setting of node %s must be a real or an array of real numbers", node_name(n));
if (json_is_array(cfg_values))
numvalues = json_array_size(cfg_values);
else if (json_is_integer(cfg_values))
if (json_is_array(json_values))
numvalues = json_array_size(json_values);
else if (json_is_integer(json_values))
numvalues = 1;
else
error("The 'values' setting of node %s must be an integer or an array of integers", node_name(n));
@ -145,29 +145,29 @@ int test_rtt_parse(struct node *n, json_t *cfg)
rates = realloc(rates, sizeof(rates[0]) * numrates);
values = realloc(values, sizeof(values[0]) * numvalues);
if (json_is_array(cfg_rates)) {
json_array_foreach(cfg_rates, index, cfg_val) {
if (!json_is_number(cfg_val))
if (json_is_array(json_rates)) {
json_array_foreach(json_rates, index, json_val) {
if (!json_is_number(json_val))
error("The 'rates' setting of node %s must be an array of real numbers", node_name(n));
rates[index] = json_integer_value(cfg_val);
rates[index] = json_integer_value(json_val);
}
}
else
rates[0] = json_number_value(cfg_rates);
rates[0] = json_number_value(json_rates);
if (json_is_array(cfg_values)) {
json_array_foreach(cfg_values, index, cfg_val) {
if (!json_is_integer(cfg_val))
if (json_is_array(json_values)) {
json_array_foreach(json_values, index, json_val) {
if (!json_is_integer(json_val))
error("The 'values' setting of node %s must be an array of integers", node_name(n));
values[index] = json_integer_value(cfg_val);
values[index] = json_integer_value(json_val);
if (values[index] < 2)
error("Each 'values' entry must be at least 2 or larger");
}
}
else {
values[0] = json_integer_value(cfg_values);
values[0] = json_integer_value(json_values);
if (values[0] <= 2)
error("Each 'values' entry must be at least 2 or larger");
}

View file

@ -493,24 +493,24 @@ int websocket_parse(struct node *n, json_t *cfg)
int ret;
size_t index;
json_t *cfg_dests = NULL;
json_t *cfg_dest;
json_t *json_dests = NULL;
json_t *json_dest;
json_error_t err;
list_init(&w->destinations);
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o }", "destinations", &cfg_dests);
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o }", "destinations", &json_dests);
if (ret)
jerror(&err, "Failed to parse configuration of node %s", node_name(n));
if (cfg_dests) {
if (!json_is_array(cfg_dests))
if (json_dests) {
if (!json_is_array(json_dests))
error("The 'destinations' setting of node %s must be an array of URLs", node_name(n));
json_array_foreach(cfg_dests, index, cfg_dest) {
json_array_foreach(json_dests, index, json_dest) {
const char *uri, *prot, *ads, *path;
uri = json_string_value(cfg_dest);
uri = json_string_value(json_dest);
if (!uri)
error("The 'destinations' setting of node %s must be an array of URLs", node_name(n));

View file

@ -101,9 +101,9 @@ int zeromq_parse(struct node *n, json_t *cfg)
const char *format = "villas-human";
size_t index;
json_t *cfg_pub = NULL;
json_t *cfg_curve = NULL;
json_t *cfg_val;
json_t *json_pub = NULL;
json_t *json_curve = NULL;
json_t *json_val;
json_error_t err;
list_init(&z->publisher.endpoints);
@ -113,8 +113,8 @@ int zeromq_parse(struct node *n, json_t *cfg)
ret = json_unpack_ex(cfg, &err, 0, "{ s?: s, s?: o, s?: o, s?: s, s?: s, s?: b, s?: s }",
"subscribe", &ep,
"publish", &cfg_pub,
"curve", &cfg_curve,
"publish", &json_pub,
"curve", &json_curve,
"filter", &filter,
"pattern", &type,
"ipv6", &z->ipv6,
@ -130,11 +130,11 @@ int zeromq_parse(struct node *n, json_t *cfg)
if (!z->format)
error("Invalid format '%s' for node %s", format, node_name(n));
if (cfg_pub) {
switch (json_typeof(cfg_pub)) {
if (json_pub) {
switch (json_typeof(json_pub)) {
case JSON_ARRAY:
json_array_foreach(cfg_pub, index, cfg_val) {
ep = json_string_value(cfg_pub);
json_array_foreach(json_pub, index, json_val) {
ep = json_string_value(json_pub);
if (!ep)
error("All 'publish' settings must be strings");
@ -143,7 +143,7 @@ int zeromq_parse(struct node *n, json_t *cfg)
break;
case JSON_STRING:
ep = json_string_value(cfg_pub);
ep = json_string_value(json_pub);
list_push(&z->publisher.endpoints, strdup(ep));
@ -154,12 +154,12 @@ int zeromq_parse(struct node *n, json_t *cfg)
}
}
if (cfg_curve) {
if (json_curve) {
const char *public_key, *secret_key;
z->curve.enabled = true;
ret = json_unpack_ex(cfg_curve, &err, 0, "{ s: s, s: s, s?: b }",
ret = json_unpack_ex(json_curve, &err, 0, "{ s: s, s: s, s?: b }",
"public_key", &public_key,
"secret_key", &secret_key,
"enabled", &z->curve.enabled

View file

@ -106,7 +106,7 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
int ret;
config_t cfg;
config_setting_t *cfg_root = NULL;
config_setting_t *json_root = NULL;
warn("Failed to parse JSON configuration. Re-trying with old libconfig format.");
{ INDENT
@ -140,9 +140,9 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
error("Failed to parse configuration");
}
cfg_root = config_root_setting(&cfg);
json_root = config_root_setting(&cfg);
sn->cfg = config_to_json(cfg_root);
sn->cfg = config_to_json(json_root);
if (sn->cfg == NULL)
error("Failed to convert JSON to configuration file");
@ -177,20 +177,20 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
assert(sn->state != STATE_STARTED);
assert(sn->state != STATE_DESTROYED);
json_t *cfg_nodes = NULL;
json_t *cfg_paths = NULL;
json_t *cfg_plugins = NULL;
json_t *cfg_logging = NULL;
json_t *cfg_web = NULL;
json_t *json_nodes = NULL;
json_t *json_paths = NULL;
json_t *json_plugins = NULL;
json_t *json_logging = NULL;
json_t *json_web = NULL;
json_error_t err;
ret = json_unpack_ex(cfg, &err, 0, "{ s?: o, s?: o, s?: o, s?: o, s?: o, s?: i, s?: i, s?: i, s?: F, s?: s }",
"http", &cfg_web,
"logging", &cfg_logging,
"plugins", &cfg_plugins,
"nodes", &cfg_nodes,
"paths", &cfg_paths,
"http", &json_web,
"logging", &json_logging,
"plugins", &json_plugins,
"nodes", &json_nodes,
"paths", &json_paths,
"hugepages", &sn->hugepages,
"affinity", &sn->affinity,
"priority", &sn->priority,
@ -204,28 +204,28 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
strncpy(sn->name, name, 128);
#ifdef WITH_WEB
if (cfg_web)
web_parse(&sn->web, cfg_web);
if (json_web)
web_parse(&sn->web, json_web);
#endif /* WITH_WEB */
if (cfg_logging)
log_parse(&sn->log, cfg_logging);
if (json_logging)
log_parse(&sn->log, json_logging);
/* Parse plugins */
if (cfg_plugins) {
if (!json_is_array(cfg_plugins))
if (json_plugins) {
if (!json_is_array(json_plugins))
error("Setting 'plugins' must be a list of strings");
size_t index;
json_t *cfg_plugin;
json_array_foreach(cfg_plugins, index, cfg_plugin) {
json_t *json_plugin;
json_array_foreach(json_plugins, index, json_plugin) {
struct plugin *p = alloc(sizeof(struct plugin));
ret = plugin_init(p);
if (ret)
error("Failed to initialize plugin");
ret = plugin_parse(p, cfg_plugin);
ret = plugin_parse(p, json_plugin);
if (ret)
error("Failed to parse plugin");
@ -234,17 +234,17 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
}
/* Parse nodes */
if (cfg_nodes) {
if (!json_is_object(cfg_nodes))
if (json_nodes) {
if (!json_is_object(json_nodes))
error("Setting 'nodes' must be a group with node name => group mappings.");
const char *name;
json_t *cfg_node;
json_object_foreach(cfg_nodes, name, cfg_node) {
json_t *json_node;
json_object_foreach(json_nodes, name, json_node) {
struct plugin *p;
const char *type;
ret = json_unpack_ex(cfg_node, &err, 0, "{ s: s }", "type", &type);
ret = json_unpack_ex(json_node, &err, 0, "{ s: s }", "type", &type);
if (ret)
jerror(&err, "Failed to parse node");
@ -258,7 +258,7 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
if (ret)
error("Failed to initialize node");
ret = node_parse(n, cfg_node, name);
ret = node_parse(n, json_node, name);
if (ret)
error("Failed to parse node");
@ -267,20 +267,20 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
}
/* Parse paths */
if (cfg_paths) {
if (!json_is_array(cfg_paths))
if (json_paths) {
if (!json_is_array(json_paths))
warn("Setting 'paths' must be a list.");
size_t index;
json_t *cfg_path;
json_array_foreach(cfg_paths, index, cfg_path) {
json_t *json_path;
json_array_foreach(json_paths, index, json_path) {
struct path *p = alloc(sizeof(struct path));
ret = path_init(p);
if (ret)
error("Failed to initialize path");
ret = path_parse(p, cfg_path, &sn->nodes);
ret = path_parse(p, json_path, &sn->nodes);
if (ret)
error("Failed to parse path");