From: Francesco Chemolli Date: Wed, 2 Sep 2015 08:33:30 +0000 (+0200) Subject: Extend Auth::User exposing UserKey as SBuf X-Git-Tag: SQUID_4_0_1~21^2~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56e5a1c730d4752e8315e1e4ae7f84d1ca90f918;p=thirdparty%2Fsquid.git Extend Auth::User exposing UserKey as SBuf Implement UserNameCache::insert and sortedUsersList --- diff --git a/src/auth/User.h b/src/auth/User.h index e080e5ca0b..bebf7f9674 100644 --- a/src/auth/User.h +++ b/src/auth/User.h @@ -68,6 +68,8 @@ public: // NP: key is set at the same time as username_. Until then both are empty/NULL. const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : NULL;} + // user key as a SBuf + const SBuf SBUserKey() { return userKey_;} /** * How long these credentials are still valid for. diff --git a/src/auth/UserNameCache.cc b/src/auth/UserNameCache.cc index 892f33a9f4..2cd00804eb 100644 --- a/src/auth/UserNameCache.cc +++ b/src/auth/UserNameCache.cc @@ -58,4 +58,24 @@ UserNameCache::cleanup(void *me) } } +void +UserNameCache::insert(Auth::User::Pointer anAuth_user) +{ + store_[anAuth_user->SBUserKey()] = anAuth_user; +} + +std::vector UserNameCache::sortedUsersList () +{ + std::vector rv(size(), nullptr); + std::transform(store_.begin(), store_.end(), rv.begin(), + [](StoreType::value_type v) { return v.second; } + ); + sort(rv.begin(), rv.end(), + [](const Auth::User::Pointer &lhs, const Auth::User::Pointer &rhs) { + return strcmp(lhs->username(), rhs->username()) < 0; + } + ); + return rv; +} + } /* namespace Auth */ diff --git a/src/auth/UserNameCache.h b/src/auth/UserNameCache.h index d40dda9f9b..1aa38b488b 100644 --- a/src/auth/UserNameCache.h +++ b/src/auth/UserNameCache.h @@ -33,16 +33,23 @@ public: /// obtain pointer to user if present, or Pointer(nullptr) if not Auth::User::Pointer lookup(const SBuf &userKey); + /// add an user to the cache + void insert(Auth::User::Pointer anAuth_user); + void reset(); size_t size(); /** periodic cleanup function, removes timed-out entries * - * Must be static to support EVH interface. Argument is this + * Must be static to support EVH interface. Argument will be this */ static void cleanup(void *); + /** obtain sorted list of usernames + * + */ + std::vector sortedUsersList(); private: StoreType store_;