From 1205859f993585cd3172e894b7f904499472cc5e Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sun, 11 Nov 2018 00:01:56 +0000 Subject: [PATCH] Replace AclNameList with SBufList (#327) Removing a class we no longer need to simplify the deny_info code. --- src/acl/AclDenyInfoList.h | 5 ++--- src/acl/AclNameList.h | 35 ----------------------------------- src/acl/Gadgets.cc | 26 +++++--------------------- src/acl/Makefile.am | 1 - src/cache_cf.cc | 4 ++-- 5 files changed, 9 insertions(+), 62 deletions(-) delete mode 100644 src/acl/AclNameList.h diff --git a/src/acl/AclDenyInfoList.h b/src/acl/AclDenyInfoList.h index 95dfd10096..5599deaec4 100644 --- a/src/acl/AclDenyInfoList.h +++ b/src/acl/AclDenyInfoList.h @@ -9,7 +9,7 @@ #ifndef SQUID_ACLDENYINFOLIST_H_ #define SQUID_ACLDENYINFOLIST_H_ -#include "acl/AclNameList.h" +#include "acl/forward.h" #include "err_type.h" #include "errorpage.h" #include "mem/forward.h" @@ -26,7 +26,6 @@ public: } ~AclDenyInfoList() { xfree(err_page_name); - delete acl_list; while (next) { auto *a = next; next = a->next; @@ -36,7 +35,7 @@ public: } err_type err_page_id = ERR_NONE; char *err_page_name = nullptr; - AclNameList *acl_list = nullptr; + SBufList acl_list; ///< ACL names in configured order AclDenyInfoList *next = nullptr; }; diff --git a/src/acl/AclNameList.h b/src/acl/AclNameList.h deleted file mode 100644 index 0f7db6abee..0000000000 --- a/src/acl/AclNameList.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 1996-2018 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#ifndef SQUID_ACL_ACLNAMELIST_H_ -#define SQUID_ACL_ACLNAMELIST_H_ - -#include "acl/forward.h" -#include "mem/forward.h" - -/// list of name-based ACLs -class AclNameList -{ - MEMPROXY_CLASS(AclNameList); - -public: - AclNameList(const char *t) { - xstrncpy(name, t, ACL_NAME_SZ-1); - } - ~AclNameList() { - // recursion is okay, these lists are short - delete next; - } - - char name[ACL_NAME_SZ]; - AclNameList *next = nullptr; -}; -// TODO: convert to a std::list - -#endif /* SQUID_ACLNAMELIST_H_ */ - diff --git a/src/acl/Gadgets.cc b/src/acl/Gadgets.cc index 1b0531e75f..8c1933b632 100644 --- a/src/acl/Gadgets.cc +++ b/src/acl/Gadgets.cc @@ -49,19 +49,16 @@ aclGetDenyInfoPage(AclDenyInfoList ** head, const char *name, int redirect_allow debugs(28, 8, HERE << "got called for " << name); for (A = *head; A; A = A->next) { - AclNameList *L = NULL; - if (!redirect_allowed && strchr(A->err_page_name, ':') ) { debugs(28, 8, HERE << "Skip '" << A->err_page_name << "' 30x redirects not allowed as response here."); continue; } - for (L = A->acl_list; L; L = L->next) { - if (!strcmp(name, L->name)) { - debugs(28, 8, HERE << "match on " << name); + for (const auto &aclName: A->acl_list) { + if (aclName.cmp(name) == 0) { + debugs(28, 8, "match on " << name); return A->err_page_id; } - } } @@ -106,8 +103,6 @@ aclParseDenyInfoLine(AclDenyInfoList ** head) char *t = NULL; AclDenyInfoList *B; AclDenyInfoList **T; - AclNameList *L = NULL; - AclNameList **Tail = NULL; /* first expect a page name */ @@ -120,15 +115,11 @@ aclParseDenyInfoLine(AclDenyInfoList ** head) AclDenyInfoList *A = new AclDenyInfoList(t); /* next expect a list of ACL names */ - Tail = &A->acl_list; - while ((t = ConfigParser::NextToken())) { - L = new AclNameList(t); - *Tail = L; - Tail = &L->next; + A->acl_list.emplace_back(t); } - if (A->acl_list == NULL) { + if (A->acl_list.empty()) { debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line); debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping"); delete A; @@ -298,17 +289,10 @@ aclDestroyDenyInfoList(AclDenyInfoList ** list) { AclDenyInfoList *a = NULL; AclDenyInfoList *a_next = NULL; - AclNameList *l = NULL; - AclNameList *l_next = NULL; debugs(28, 8, "aclDestroyDenyInfoList: invoked"); for (a = *list; a; a = a_next) { - for (l = a->acl_list; l; l = l_next) { - l_next = l->next; - safe_free(l); - } - a_next = a->next; delete a; } diff --git a/src/acl/Makefile.am b/src/acl/Makefile.am index 4c3c480203..89936ec63e 100644 --- a/src/acl/Makefile.am +++ b/src/acl/Makefile.am @@ -147,7 +147,6 @@ libacls_la_SOURCES = \ UrlPort.h \ UserData.cc \ UserData.h \ - AclNameList.h \ AclDenyInfoList.h \ Gadgets.cc \ Gadgets.h \ diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 414be89c52..d1c26d4951 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -2443,8 +2443,8 @@ dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var) while (var != NULL) { storeAppendPrintf(entry, "%s %s", name, var->err_page_name); - for (auto *a = var->acl_list; a != NULL; a = a->next) - storeAppendPrintf(entry, " %s", a->name); + for (const auto &aclName: var->acl_list) + storeAppendPrintf(entry, " " SQUIDSBUFPH, SQUIDSBUFPRINT(aclName)); storeAppendPrintf(entry, "\n"); -- 2.47.3