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.
{
struct metadata_node *meta;
struct serial_number *cursor;
- array_index i;
struct serial_number duplicate;
char *string;
*
* 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'.)",
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_ */
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:
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
__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);
}
deltas_head_sort(struct deltas_head *deltas, unsigned long max_serial)
{
unsigned long min_serial;
- struct delta_head *cursor;
array_index i;
int error;
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)
{
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;
{
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;
{
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);
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);
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)
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;
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;
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;
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;
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; \
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);
}
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);
}
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);
}
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);
}