]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
General index.json review
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 5 Dec 2024 15:24:01 +0000 (12:24 -0300)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 5 Dec 2024 15:24:01 +0000 (12:24 -0300)
Not much; just moving things around for peace of mind.

src/cache.c
src/json_util.c
src/rrdp.c

index 2ea3039865804723eb56d2410ff0a007444924c7..2b89f7402bc2c805386e04b450a0e9c576524180 100644 (file)
@@ -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);
 }
index 4d2173a56834bf737c41daca78852d52a552c74b..696a85400afac504e5428dc7f24058f39b79ac6e 100644 (file)
@@ -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;
index 20e2b49048b1eff70d119769c48241c90936d39d..cd8aa7db8355eabe9918fd29d4f67f590445f419 100644 (file)
@@ -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;