From 5a5b349a307af809f122798655be621f3b950898 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sat, 20 Feb 2016 18:17:57 +1000 Subject: [PATCH] * src/ipaddr.* : fixes --- src/ipaddr.c | 33 ++++++++++++++++++++++++++++++++- src/ipaddr.h | 5 ++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/ipaddr.c b/src/ipaddr.c index 733f37e..a7cad04 100644 --- a/src/ipaddr.c +++ b/src/ipaddr.c @@ -30,6 +30,14 @@ f2b_ipaddr_create(const char *addr, size_t matches) { return NULL; } +void +f2b_ipaddr_destroy(f2b_ipaddr_t *ipaddr) { + assert(ipaddr != NULL); + + f2b_matches_destroy(&ipaddr->matches); + free(ipaddr); +} + f2b_ipaddr_t * f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr) { assert(ipaddr != NULL); @@ -40,15 +48,38 @@ f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr) { f2b_ipaddr_t * f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr) { + assert(addr != NULL); if (list == NULL) return NULL; - for (f2b_ipaddr_t *a = list; a->next != NULL; a = a->next) { + for (f2b_ipaddr_t *a = list; a != NULL; a = a->next) { if (strncmp(a->text, addr, sizeof(a->text)) == 0) return a; } return NULL; } + +f2b_ipaddr_t * +f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr) { + f2b_ipaddr_t *a = NULL; + + assert(addr != NULL); + + if (list == NULL) + return NULL; + + if (strncmp(list->text, addr, sizeof(list->text)) == 0) { + a = list->next; + f2b_ipaddr_destroy(list); + return a; + } + + for (a = list; a->next != NULL; a = a->next) { + assert(0); /* TODO */ + } + + return list; +} diff --git a/src/ipaddr.h b/src/ipaddr.h index a71c04d..4bf3a70 100644 --- a/src/ipaddr.h +++ b/src/ipaddr.h @@ -16,8 +16,11 @@ typedef struct f2b_ipaddr_t { f2b_matches_t matches; } f2b_ipaddr_t; -f2b_ipaddr_t * f2b_ipaddr_create(const char *addr, size_t max_matches); +f2b_ipaddr_t * f2b_ipaddr_create (const char *addr, size_t max_matches); +void f2b_ipaddr_destroy(f2b_ipaddr_t *ipaddr); + f2b_ipaddr_t * f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr); f2b_ipaddr_t * f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr); +f2b_ipaddr_t * f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr); #endif /* F2B_IPADDR_H_ */