From: Francesco Chemolli Date: Tue, 30 Dec 2014 22:52:53 +0000 (+0100) Subject: Fixed Acl::UserData X-Git-Tag: merge-candidate-3-v1~384^2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52bc393be9389875a1469a78487e8e14e2a5c914;p=thirdparty%2Fsquid.git Fixed Acl::UserData --- diff --git a/src/acl/UserData.cc b/src/acl/UserData.cc index ce53f75f7f..638f05e72b 100644 --- a/src/acl/UserData.cc +++ b/src/acl/UserData.cc @@ -43,10 +43,7 @@ splaystrcmp (char * const &l, char * const &r) bool ACLUserData::match(char const *user) { - SplayNode *Top = names; - debugs(28, 7, "aclMatchUser: user is " << user << ", case_insensitive is " << flags.case_insensitive); - debugs(28, 8, "Top is " << Top << ", Top->data is " << ((char *) (Top != NULL ? (Top)->data : "Unavailable"))); if (user == NULL || strcmp(user, "-") == 0) return 0; @@ -56,26 +53,25 @@ ACLUserData::match(char const *user) return 1; } + char * const *result; + if (flags.case_insensitive) - Top = Top->splay((char *)user, splaystrcasecmp); + result = names->find(const_cast(user), splaystrcasecmp); else - Top = Top->splay((char *)user, splaystrcmp); + result = names->find(const_cast(user), splaystrcmp); /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */ - debugs(28, 7, "aclMatchUser: returning " << !splayLastResult << ",Top is " << - Top << ", Top->data is " << ((char *) (Top ? Top->data : "Unavailable"))); + debugs(28, 7, "aclMatchUser: returning " << (result != NULL)); - names = Top; - - return !splayLastResult; + return (result != NULL); } -static void -aclDumpUserListWalkee(char * const & node_data, void *outlist) -{ - /* outlist is really a SBufList* */ - static_cast(outlist)->push_back(SBuf(node_data)); -} +struct UserDataAclDumpVisitor { + SBufList contents; + void operator() (char * const & node_data) { + contents.push_back(SBuf(node_data)); + } +}; SBufList ACLUserData::dump() const @@ -89,10 +85,13 @@ ACLUserData::dump() const * a SBufList this way costs Sum(1,N) iterations. For instance * a 1000-elements list will be filled in 499500 iterations. */ - if (flags.required) + if (flags.required) { sl.push_back(SBuf("REQUIRED")); - else if (names) - names->walk(aclDumpUserListWalkee, &sl); + } else if (names) { + UserDataAclDumpVisitor visitor; + names->visit(visitor); + sl.splice(sl.end(),visitor.contents); + } return sl; } @@ -116,7 +115,7 @@ ACLUserData::parse() if (flags.case_insensitive) Tolower(t); - names = names->insert(xstrdup(t), splaystrcmp); + names->insert(xstrdup(t), splaystrcmp); } } @@ -131,7 +130,7 @@ ACLUserData::parse() if (flags.case_insensitive) Tolower(t); - names = names->insert(xstrdup(t), splaystrcmp); + names->insert(xstrdup(t), splaystrcmp); } } diff --git a/src/acl/UserData.h b/src/acl/UserData.h index e51ce40f5f..521d779c86 100644 --- a/src/acl/UserData.h +++ b/src/acl/UserData.h @@ -25,7 +25,7 @@ public: bool empty() const; virtual ACLData *clone() const; - SplayNode *names; + Splay *names; struct { bool case_insensitive;