From 331f1c030b8d336ad6037df498f795404a8347cf0523de29e966c8c113b87b9c Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 3 Aug 2025 21:09:47 -0400 Subject: [PATCH] An ersatz vector is now replaced. --- src/domain.cc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/domain.cc b/src/domain.cc index 8d030e4..d3ffd19 100644 --- a/src/domain.cc +++ b/src/domain.cc @@ -9,19 +9,19 @@ #include +#include + #include "../dlib/dlib.h" #include "msg.hh" #include "list.h" #include "domain.hh" -typedef struct { +struct Rule { char *origin; char *destination; -} Rule; +}; -static Rule *exceptions = NULL; -static int num_exceptions = 0; -static int num_exceptions_max = 1; +std::vector< Rule > exceptions; static bool_t default_deny = FALSE; @@ -64,10 +64,9 @@ void a_Domain_parse(FILE *fp) MSG("Domain: Default action \"%s\" not recognised.\n", tok2); } } else { - a_List_add(exceptions, num_exceptions, num_exceptions_max, Rule); - exceptions[num_exceptions].origin = dStrdup(tok1); - exceptions[num_exceptions].destination = dStrdup(tok2); - num_exceptions++; + exceptions.emplace_back(); + exceptions.back().origin = dStrdup(tok1); + exceptions.back().destination = dStrdup(tok2); _MSG("Domain: Exception from %s to %s.\n", tok1, tok2); } } @@ -80,11 +79,11 @@ void a_Domain_freeall(void) { int i = 0; - for (i = 0; i < num_exceptions; i++) { + for (i = 0; i < exceptions.size(); i++) { dFree(exceptions[i].origin); dFree(exceptions[i].destination); } - dFree(exceptions); + exceptions.clear(); } /** @@ -119,7 +118,7 @@ bool_t a_Domain_permit(const DilloUrl *source, const DilloUrl *dest) bool_t ret; const char *source_host, *dest_host; - if (default_deny == FALSE && num_exceptions == 0) + if (default_deny == FALSE && exceptions.size() == 0) return TRUE; source_host = URL_HOST(source); @@ -138,7 +137,7 @@ bool_t a_Domain_permit(const DilloUrl *source, const DilloUrl *dest) ret = default_deny ? FALSE : TRUE; - for (i = 0; i < num_exceptions; i++) { + for (i = 0; i < exceptions.size(); i++) { if (Domain_match(source_host, exceptions[i].origin) && Domain_match(dest_host, exceptions[i].destination)) { ret = default_deny;