From: Amos Jeffries Date: Tue, 1 Nov 2016 01:41:39 +0000 (+1300) Subject: Cleanup: replace cachemgr_passwd with SBufList X-Git-Tag: SQUID_4_0_17~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a5f27c62b2b25ba7e492f0148e199d91984a8861;p=thirdparty%2Fsquid.git Cleanup: replace cachemgr_passwd with SBufList Remove one more use of wordlist in favour of SBufList Also, updates the debug warning during config parse to use the quieter PARSE_NOTE macro. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index efe10f9865..2e277e5ac4 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -2291,17 +2291,14 @@ free_peer(CachePeer ** P) static void dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list) { - wordlist *w; - - while (list != NULL) { + while (list) { if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) storeAppendPrintf(entry, "%s XXXXXXXXXX", name); else storeAppendPrintf(entry, "%s %s", name, list->passwd); - for (w = list->actions; w != NULL; w = w->next) { - storeAppendPrintf(entry, " %s", w->key); - } + for (auto w : list->actions) + entry->appendf(" " SQUIDSBUFPH, SQUIDSBUFPRINT(w)); storeAppendPrintf(entry, "\n"); list = list->next; @@ -2311,16 +2308,16 @@ dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordLis static void parse_cachemgrpasswd(Mgr::ActionPasswordList ** head) { - char *passwd = NULL; - wordlist *actions = NULL; - Mgr::ActionPasswordList *p; - Mgr::ActionPasswordList **P; + char *passwd = nullptr; parse_string(&passwd); - parse_wordlist(&actions); - p = new Mgr::ActionPasswordList; + + Mgr::ActionPasswordList *p = new Mgr::ActionPasswordList; p->passwd = passwd; - p->actions = actions; + while (char *token = ConfigParser::NextQuotedToken()) + p->actions.push_back(SBuf(token)); + + Mgr::ActionPasswordList **P; for (P = head; *P; P = &(*P)->next) { /* * See if any of the actions from this line already have a @@ -2330,15 +2327,12 @@ parse_cachemgrpasswd(Mgr::ActionPasswordList ** head) * requested action. Thus, we should warn users who might * think they can have two passwords for the same action. */ - wordlist *w; - wordlist *u; - - for (w = (*P)->actions; w; w = w->next) { - for (u = actions; u; u = u->next) { - if (strcmp(w->key, u->key)) + for (const auto &w : (*P)->actions) { + for (const auto &u : p->actions) { + if (w != u) continue; - debugs(0, DBG_CRITICAL, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); + debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u << "' (line " << config_lineno << ") already has a password"); } } } @@ -2349,14 +2343,8 @@ parse_cachemgrpasswd(Mgr::ActionPasswordList ** head) static void free_cachemgrpasswd(Mgr::ActionPasswordList ** head) { - Mgr::ActionPasswordList *p; - - while ((p = *head) != NULL) { - *head = p->next; - xfree(p->passwd); - wordlistDestroy(&p->actions); - xfree(p); - } + delete *head; + *head = nullptr; } static void diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 0565787d23..d84490c4b8 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -445,14 +445,13 @@ CacheManager::ActionProtection(const Mgr::ActionProfile::Pointer &profile) char * CacheManager::PasswdGet(Mgr::ActionPasswordList * a, const char *action) { - wordlist *w; - - while (a != NULL) { - for (w = a->actions; w != NULL; w = w->next) { - if (0 == strcmp(w->key, action)) + while (a) { + for (auto &w : a->actions) { + if (w.cmp(action) == 0) return a->passwd; - if (0 == strcmp(w->key, "all")) + static const SBuf allAction("all"); + if (w == allAction) return a->passwd; } diff --git a/src/mgr/ActionPasswordList.cc b/src/mgr/ActionPasswordList.cc index b27ac73cb5..38139c9c19 100644 --- a/src/mgr/ActionPasswordList.cc +++ b/src/mgr/ActionPasswordList.cc @@ -8,12 +8,11 @@ #include "squid.h" #include "mgr/ActionPasswordList.h" -#include "wordlist.h" +#include "sbuf/List.h" Mgr::ActionPasswordList::~ActionPasswordList() { - safe_free(passwd); - wordlistDestroy(&actions); - delete next; + xfree(passwd); + delete next; // recurse, these lists are usually not long } diff --git a/src/mgr/ActionPasswordList.h b/src/mgr/ActionPasswordList.h index 158e56503e..a1a69343f6 100644 --- a/src/mgr/ActionPasswordList.h +++ b/src/mgr/ActionPasswordList.h @@ -9,7 +9,7 @@ #ifndef SQUID_MGR_CACHEMGRPASSWD_H_ #define SQUID_MGR_CACHEMGRPASSWD_H_ -class wordlist; +#include "sbuf/forward.h" namespace Mgr { @@ -18,12 +18,11 @@ namespace Mgr class ActionPasswordList { public: - ActionPasswordList() : passwd(NULL), actions(NULL), next(NULL) {} ~ActionPasswordList(); - char *passwd; - wordlist *actions; - ActionPasswordList *next; + char *passwd = nullptr; + SBufList actions; + ActionPasswordList *next = nullptr; }; } //namespace Mgr