]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Add ARRAYLIST_FOREACH_IDX
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 12 Sep 2023 21:54:27 +0000 (15:54 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 12 Sep 2023 21:55:50 +0000 (15:55 -0600)
The old ARRAYLIST_FOREACH provided both a cursor and a counter.
Most users weren't using the counter, so I separated them:

The new ARRAYLIST_FOREACH uses a cursor,
the new ARRAYLIST_FOREACH_IDX uses a counter.

src/cert_stack.c
src/data_structure/array_list.h
src/object/certificate.c
src/rpp.c
src/rrdp/rrdp_objects.c
src/rtr/db/delta.c
src/rtr/rtr.c
src/slurm/db_slurm.c

index 5ad5c1cd23169ccf15892bea8061c724225d3ec9..c411c4f69d95f84f576f65ba7ae9a9bc438deebc 100644 (file)
@@ -394,7 +394,6 @@ x509stack_store_serial(struct cert_stack *stack, BIGNUM *number)
 {
        struct metadata_node *meta;
        struct serial_number *cursor;
-       array_index i;
        struct serial_number duplicate;
        char *string;
 
@@ -427,7 +426,7 @@ x509stack_store_serial(struct cert_stack *stack, BIGNUM *number)
         *
         * TODO I haven't seen this warning in a while. Review.
         */
-       ARRAYLIST_FOREACH(&meta->serials, cursor, i) {
+       ARRAYLIST_FOREACH(&meta->serials, cursor) {
                if (BN_cmp(cursor->number, number) == 0) {
                        BN2string(number, &string);
                        pr_val_warn("Serial number '%s' is not unique. (Also found in '%s'.)",
index 6a6ea5ac5a670f5de48f62179115a7730799d75f..686165c949e501f99c6defbb56e82a77b558df19 100644 (file)
        DEFINE_ARRAY_LIST_STRUCT(name, elem_type);                      \
        DEFINE_ARRAY_LIST_FUNCTIONS(name, elem_type, static)
 
-#define ARRAYLIST_FOREACH(list, node, index) for (                     \
-       (index) = 0, (node) = (list)->array;                            \
+#define ARRAYLIST_FOREACH(list, node) for (                            \
+       (node) = (list)->array;                                         \
+       (node) < (list)->array + (list)->len;                           \
+       (node)++                                                        \
+)
+
+#define ARRAYLIST_FOREACH_IDX(list, index) for (                       \
+       (index) = 0;                                                    \
        (index) < (list)->len;                                          \
-       (index)++, (node)++                                             \
+       (index)++                                                       \
 )
 
 #endif /* SRC_DATA_STRUCTURE_ARRAY_LIST_H_ */
index 3c44c3b102595a6d69bb90b59bdc9f218a9ab0a1..d1e127846a3e61d397ca9eefc6fbe8006aa231d3 100644 (file)
@@ -1932,12 +1932,11 @@ static int
 download_rpp(struct sia_uris *uris)
 {
        struct rpki_uri **node, *uri;
-       array_index index;
 
        if (uris->rpp.len == 0)
                return pr_val_err("SIA lacks both caRepository and rpkiNotify.");
 
-       ARRAYLIST_FOREACH(&uris->rpp, node, index) {
+       ARRAYLIST_FOREACH(&uris->rpp, node) {
                uri = *node;
                switch (uri_get_type(uri)) {
                case UT_RSYNC:
index efa6333a5e6fbbff8dba22913777460fe815dda7..d9592cd7d4e1efcfa85eb81be4a37a7170756eec 100644 (file)
--- a/src/rpp.c
+++ b/src/rpp.c
@@ -241,7 +241,6 @@ void
 rpp_traverse(struct rpp *pp)
 {
        struct rpki_uri **uri;
-       array_index i;
 
        /*
         * A subtree should not invalidate the rest of the tree, so error codes
@@ -258,13 +257,13 @@ rpp_traverse(struct rpp *pp)
        __cert_traverse(pp);
 
        /* Validate ROAs, apply validation_handler on them. */
-       ARRAYLIST_FOREACH(&pp->roas, uri, i)
+       ARRAYLIST_FOREACH(&pp->roas, uri)
                roa_traverse(*uri, pp);
 
        /*
         * We don't do much with the ghostbusters right now.
         * Just validate them.
         */
-       ARRAYLIST_FOREACH(&pp->ghostbusters, uri, i)
+       ARRAYLIST_FOREACH(&pp->ghostbusters, uri)
                ghostbusters_traverse(*uri, pp);
 }
index b34f1a29839ea785f2d32608d48b20530c2bf839..7d44259d8f3c4cc458a43d8f62c9ae40b5a10e36 100644 (file)
@@ -95,7 +95,6 @@ int
 deltas_head_sort(struct deltas_head *deltas, unsigned long max_serial)
 {
        unsigned long min_serial;
-       struct delta_head *cursor;
        array_index i;
        int error;
 
@@ -105,7 +104,7 @@ deltas_head_sort(struct deltas_head *deltas, unsigned long max_serial)
 
        min_serial = max_serial + 1 - deltas->len;
 
-       ARRAYLIST_FOREACH(deltas, cursor, i) {
+       ARRAYLIST_FOREACH_IDX(deltas, i) {
                error = swap_until_sorted(deltas->array, i, min_serial,
                    max_serial);
                if (error)
index 84c734852d621f3cdb5d8484775e3d57beb7a7f8..551cbd09efdc7666a96a1d38ac0ba8e17e8ce635 100644 (file)
@@ -192,13 +192,12 @@ __foreach_v4(struct deltas_v4 *array, delta_vrp_foreach_cb cb, void *arg,
 {
        struct delta_vrp delta;
        struct delta_v4 *d;
-       array_index i;
        int error;
 
        delta.vrp.addr_fam = AF_INET;
        delta.flags = flags;
 
-       ARRAYLIST_FOREACH(array, d, i) {
+       ARRAYLIST_FOREACH(array, d) {
                delta.vrp.asn = d->as;
                delta.vrp.prefix.v4 = d->prefix.addr;
                delta.vrp.prefix_length = d->prefix.len;
@@ -217,13 +216,12 @@ __foreach_v6(struct deltas_v6 *array, delta_vrp_foreach_cb cb, void *arg,
 {
        struct delta_vrp delta;
        struct delta_v6 *d;
-       array_index i;
        int error;
 
        delta.vrp.addr_fam = AF_INET6;
        delta.flags = flags;
 
-       ARRAYLIST_FOREACH(array, d, i) {
+       ARRAYLIST_FOREACH(array, d) {
                delta.vrp.asn = d->as;
                delta.vrp.prefix.v6 = d->prefix.addr;
                delta.vrp.prefix_length = d->prefix.len;
@@ -242,12 +240,11 @@ __foreach_rk(struct deltas_rk *array,  delta_router_key_foreach_cb cb,
 {
        struct delta_router_key delta;
        struct delta_rk *d;
-       array_index i;
        int error;
 
        delta.flags = flags;
 
-       ARRAYLIST_FOREACH(array, d, i) {
+       ARRAYLIST_FOREACH(array, d) {
                delta.router_key.as = d->as;
                memcpy(delta.router_key.ski, d->ski, RK_SKI_LEN);
                memcpy(delta.router_key.spk, d->spk, RK_SPKI_LEN);
index d69c7f701d0006bd2d36b854add0e540f53d7201..12d357a889c12137017dbf436479f36457dc9d6d 100644 (file)
@@ -579,21 +579,17 @@ static enum poll_verdict
 fddb_poll(void)
 {
        struct pollfd *pollfds; /* array */
-
-       struct rtr_server *server;
-       struct rtr_client *client;
        struct pollfd *fd;
-
        unsigned int nclients;
        unsigned int i;
        int error;
 
        pollfds = pcalloc(servers.len + clients.len, sizeof(struct pollfd));
 
-       ARRAYLIST_FOREACH(&servers, server, i)
-               init_pollfd(&pollfds[i], server->fd);
-       ARRAYLIST_FOREACH(&clients, client, i)
-               init_pollfd(&pollfds[servers.len + i], client->fd);
+       ARRAYLIST_FOREACH_IDX(&servers, i)
+               init_pollfd(&pollfds[i], servers.array[i].fd);
+       ARRAYLIST_FOREACH_IDX(&clients, i)
+               init_pollfd(&pollfds[servers.len + i], clients.array[i].fd);
 
        error = poll(pollfds, servers.len + clients.len, 1000);
 
@@ -750,12 +746,11 @@ int
 rtr_foreach_client(rtr_foreach_client_cb cb, void *arg)
 {
        struct rtr_client *client;
-       unsigned int i;
        int error = 0;
 
        mutex_lock(&lock);
 
-       ARRAYLIST_FOREACH(&clients, client, i) {
+       ARRAYLIST_FOREACH(&clients, client) {
                if (client->fd != -1) {
                        error = cb(client, arg);
                        if (error)
index fb4869fcfc6dc2a87c5eb7b7cc8122c745297224..3b033524ec4a442358559c86d1977ccbac178e78 100644 (file)
@@ -182,9 +182,8 @@ static bool
 prefix_filtered(struct db_slurm *db, struct slurm_prefix *prefix)
 {
        struct slurm_prefix_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor)
                if (prefix_filtered_by(cursor, prefix))
                        return true;
 
@@ -238,9 +237,8 @@ static bool
 bgpsec_filtered(struct db_slurm *db, struct slurm_bgpsec *bgpsec)
 {
        struct slurm_bgpsec_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor)
                if (bgpsec_filtered_by(cursor, bgpsec))
                        return true;
 
@@ -272,14 +270,13 @@ static bool
 prefix_exists(struct db_slurm *db, struct slurm_prefix *elem)
 {
        struct slurm_prefix_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.filter_pfx_al, cursor)
                if (prefix_contained(&cursor->element, elem) ||
                    prefix_contained(elem, &cursor->element))
                        return true;
 
-       ARRAYLIST_FOREACH(&db->lists.assertion_pfx_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.assertion_pfx_al, cursor)
                if (prefix_contained(&cursor->element, elem) ||
                    prefix_contained(elem, &cursor->element))
                        return true;
@@ -336,14 +333,13 @@ static bool
 bgpsec_exists(struct db_slurm *db, struct slurm_bgpsec *elem)
 {
        struct slurm_bgpsec_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.filter_bgps_al, cursor)
                if (bgpsec_contained(&cursor->element, elem) ||
                    bgpsec_contained(elem, &cursor->element))
                        return true;
 
-       ARRAYLIST_FOREACH(&db->lists.assertion_bgps_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->lists.assertion_bgps_al, cursor)
                if (bgpsec_contained(&cursor->element, elem) ||
                    bgpsec_contained(elem, &cursor->element))
                        return true;
@@ -415,10 +411,9 @@ db_slurm_bgpsec_is_filtered(struct db_slurm *db, struct router_key const *key)
            object##_foreach_cb cb, void *arg)                          \
        {                                                               \
                struct slurm_##object##_wrap *cursor;                   \
-               array_index i;                                          \
                int error;                                              \
                                                                        \
-               ARRAYLIST_FOREACH(&lists->db_list, cursor, i) {         \
+               ARRAYLIST_FOREACH(&lists->db_list, cursor) {            \
                        error = cb(&cursor->element, arg);              \
                        if (error)                                      \
                                return error;                           \
@@ -544,9 +539,8 @@ static void
 persist_filter_prefix(struct db_slurm *db)
 {
        struct slurm_prefix_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor)
                al_filter_prefix_add(&db->lists.filter_pfx_al, cursor);
 }
 
@@ -554,9 +548,8 @@ static void
 persist_filter_bgpsec(struct db_slurm *db)
 {
        struct slurm_bgpsec_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->cache->filter_bgps_al, cursor, i) {
+       ARRAYLIST_FOREACH(&db->cache->filter_bgps_al, cursor) {
                al_filter_bgpsec_add(&db->lists.filter_bgps_al, cursor);
                slurm_bgpsec_wrap_refget(cursor);
        }
@@ -566,9 +559,8 @@ static void
 persist_assertion_prefix(struct db_slurm *db)
 {
        struct slurm_prefix_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor, i)
+       ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor)
                al_assertion_prefix_add(&db->lists.assertion_pfx_al, cursor);
 }
 
@@ -576,9 +568,8 @@ static void
 persist_assertion_bgpsec(struct db_slurm *db)
 {
        struct slurm_bgpsec_wrap *cursor;
-       array_index i;
 
-       ARRAYLIST_FOREACH(&db->cache->assertion_bgps_al, cursor, i) {
+       ARRAYLIST_FOREACH(&db->cache->assertion_bgps_al, cursor) {
                al_assertion_bgpsec_add(&db->lists.assertion_bgps_al, cursor);
                slurm_bgpsec_wrap_refget(cursor);
        }