From: Alberto Leiva Popper Date: Thu, 5 Dec 2024 15:24:01 +0000 (-0300) Subject: General index.json review X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=509638a181298b8cc68cae6161439ffa994a894e;p=thirdparty%2FFORT-validator.git General index.json review Not much; just moving things around for peace of mind. --- diff --git a/src/cache.c b/src/cache.c index 2ea30398..2b89f740 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1069,10 +1069,9 @@ table_print(struct cache_table *tbl) { struct cache_node *node, *tmp; - if (HASH_COUNT(tbl->nodes) == 0) - return; - - printf(" %s (%s):\n", tbl->name, tbl->enabled ? "enabled" : "disabled"); + printf(" %s enabled:%d seq:%s/%lu\n", + tbl->name, tbl->enabled, + tbl->seq.prefix, tbl->seq.next_id); HASH_ITER(hh, tbl->nodes, node, tmp) cachent_print(node); } diff --git a/src/json_util.c b/src/json_util.c index 4d2173a5..696a8540 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -158,14 +158,16 @@ json_get_object(json_t *parent, char const *name, json_t **obj) { json_t *child; - *obj = NULL; - child = json_object_get(parent, name); - if (child == NULL) + if (child == NULL) { + *obj = NULL; return ENOENT; + } - if (!json_is_object(child)) + if (!json_is_object(child)) { + *obj = NULL; return pr_op_err("Tag '%s' is not a JSON object.", name); + } *obj = child; return 0; diff --git a/src/rrdp.c b/src/rrdp.c index 20e2b490..cd8aa7db 100644 --- a/src/rrdp.c +++ b/src/rrdp.c @@ -1395,6 +1395,44 @@ fail: json_decref(json); return NULL; } +static int +json2session(json_t *parent, char **session) +{ + char const *str; + int error; + + error = json_get_str(parent, TAGNAME_SESSION, &str); + *session = error ? NULL : pstrdup(str); + return error; +} + +static int +json2serial(json_t *parent, struct rrdp_serial *serial) +{ + char const *str; + int error; + + error = json_get_str(parent, TAGNAME_SERIAL, &str); + if (error < 0) + return error; + if (error > 0) { + serial->num = NULL; + serial->str = NULL; + return error; + } + + serial->num = BN_create(); + serial->str = pstrdup(str); + if (!BN_dec2bn(&serial->num, serial->str)) { + error = pr_op_err("Not a serial number: %s", serial->str); + BN_free(serial->num); + free(serial->str); + return error; + } + + return 0; +} + static int json2dh(json_t *json, struct rrdp_hash **dh) { @@ -1467,31 +1505,19 @@ int rrdp_json2state(json_t *json, struct rrdp_state **result) { struct rrdp_state *state; - char const *str; int error; state = pzalloc(sizeof(struct rrdp_state)); - error = json_get_str(json, TAGNAME_SESSION, &str); - if (error < 0) + error = json2session(json, &state->session.session_id); + if (error) goto revert_notif; - state->session.session_id = (error == 0) ? pstrdup(str) : NULL; - - error = json_get_str(json, TAGNAME_SERIAL, &str); - if (error < 0) + error = json2serial(json, &state->session.serial); + if (error) goto revert_session; - state->session.serial.str = (error == 0) ? pstrdup(str) : NULL; - - state->session.serial.num = BN_create(); - if (!BN_dec2bn(&state->session.serial.num, state->session.serial.str)) { - error = pr_op_err("Not a serial number: %s", state->session.serial.str); - goto revert_serial; - } - error = json_get_seq(json, "seq", &state->seq); if (error) goto revert_serial; - error = json2dhs(json, state); if (error) goto revert_seq;