From 31ddadccbd4313d28750ebf32a936492f84faa50 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 25 Jan 2021 14:46:47 +1000 Subject: [PATCH] * rename function: f2b_matches_append() -> f2b_matches_prepend() --- src/jail.c | 6 +++--- src/matches.c | 2 +- src/matches.h | 10 ++++------ t/t_matches.c | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/jail.c b/src/jail.c index 2efcc8d..2e2ee6f 100644 --- a/src/jail.c +++ b/src/jail.c @@ -302,7 +302,7 @@ f2b_jail_process(f2b_jail_t *jail) { f2b_log_msg(log_debug, "jail '%s': found new ip %s", jail->name, matchbuf); } addr->lastseen = now; - f2b_matches_append(&addr->matches, match); + f2b_matches_prepend(&addr->matches, match); match = NULL; /* will create new object on next run */ if (addr->banned) { if (addr->banned_at != now) @@ -318,7 +318,7 @@ f2b_jail_process(f2b_jail_t *jail) { findtime = now - jail->findtime; } f2b_matches_expire(&addr->matches, findtime); - f2b_matches_append(&addr->matches, match); + f2b_matches_prepend(&addr->matches, match); if (addr->matches.count < jail->maxretry) { f2b_log_msg(log_info, "jail '%s': new match for ip %s (%zu/%zu)", jail->name, matchbuf, addr->matches.count, jail->maxretry); @@ -605,7 +605,7 @@ f2b_jail_cmd_ip_xxx(char *res, size_t ressize, f2b_jail_t *jail, int op, const c } addr->lastseen = now; match = f2b_match_create(now); - f2b_matches_append(&addr->matches, match); + f2b_matches_prepend(&addr->matches, match); f2b_matches_flush(&addr->matches); jail->ipaddrs = f2b_addrlist_append(jail->ipaddrs, addr); jail->stats.hosts++; diff --git a/src/matches.c b/src/matches.c index 251c94b..d30a9c1 100644 --- a/src/matches.c +++ b/src/matches.c @@ -32,7 +32,7 @@ f2b_matches_flush(f2b_matches_t *ms) { } void -f2b_matches_append(f2b_matches_t *ms, f2b_match_t *m) { +f2b_matches_prepend(f2b_matches_t *ms, f2b_match_t *m) { assert(ms != NULL); assert(m != NULL); diff --git a/src/matches.h b/src/matches.h index 8e332ee..717e5ab 100644 --- a/src/matches.h +++ b/src/matches.h @@ -41,13 +41,11 @@ f2b_match_t * f2b_match_create(time_t t); void f2b_matches_flush(f2b_matches_t *ms); /** - * @brief Push new match time to struct - * @param m Pointer to struct - * @param time Match time - * @param score Match score - * @returns true on success, false if capacity exceeded + * @brief Insert new match to head of matches list + * @param ms Matches list struct + * @param match Match entry */ -void f2b_matches_append (f2b_matches_t *ms, f2b_match_t *m); +void f2b_matches_prepend (f2b_matches_t *ms, f2b_match_t *m); /** * @brief Remove matches before given time diff --git a/t/t_matches.c b/t/t_matches.c index 1a049ad..12300fc 100644 --- a/t/t_matches.c +++ b/t/t_matches.c @@ -16,7 +16,7 @@ int main() { assert(match != NULL); assert(match->next == NULL); - f2b_matches_append(&matches, match); + f2b_matches_prepend(&matches, match); assert(matches.count == 1); assert(matches.last == now); assert(matches.list == match); @@ -28,7 +28,7 @@ int main() { for (size_t i = 1; i < size; i++) { match = f2b_match_create(now - 60 * (size - i)); - f2b_matches_append(&matches, match); + f2b_matches_prepend(&matches, match); assert(matches.count == i); assert(matches.last == now - (time_t) (60 * (size - i))); }