]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/auth/CredentialsCache.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / auth / CredentialsCache.h
index 793c202c755f66dacd63479e59bba79834cc28ef..3c44849c14182e4ba842be06c8e9011277fc35c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
 #define SQUID_SRC_AUTH_CREDENTIALSCACHE_H
 
 #include "auth/User.h"
-#include "base/RunnersRegistry.h"
 #include "cbdata.h"
-#include "SBufAlgos.h"
+#include "sbuf/Algorithms.h"
 
 #include <unordered_map>
 
 namespace Auth {
 
 /// Cache of Auth::User credentials, keyed by Auth::User::userKey
-class CredentialsCache : public RegisteredRunner
+class CredentialsCache
 {
-private:
     CBDATA_CLASS(CredentialsCache);
 
-    /// key is User::userKey(), mapped value is User::Pointer
-    typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
-
 public:
-    CredentialsCache() = delete;
-    explicit CredentialsCache(const char *name);
+    explicit CredentialsCache(const char *name, const char * const eventName);
 
     ~CredentialsCache() = default;
-    CredentialsCache(const CredentialsCache& ) = delete;
+    CredentialsCache(const CredentialsCache&) = delete;
     CredentialsCache& operator=(const CredentialsCache&) = delete;
 
-    /// obtain pointer to user if present, or Pointer(nullptr) if not
     /// \returns a pointer to cached credentials, or nil if none found
     Auth::User::Pointer lookup(const SBuf &userKey) const;
 
-    /// add an user to the cache
-    void insert(Auth::User::Pointer anAuth_user);
+    /// add an user to the cache with the provided key
+    void insert(const SBuf &userKey, Auth::User::Pointer anAuth_user);
 
     /// clear cache
     void reset() { store_.clear(); }
 
-    /// extract number of cached usernames
+    /// \returns number of cached usernames
     size_t size() const { return store_.size(); }
 
     /** periodic cleanup function, removes timed-out entries
@@ -57,30 +50,28 @@ public:
     /// cache garbage collection, removes timed-out entries
     void cleanup();
 
-    /** obtain sorted list of usernames
-     *
+    /**
+     * Cleanup cache data after a reconfiguration has occurred.
+     * Similar to cleanup() but also flushes stale config dependent
+     * state from retained entries.
      */
-    std::vector<Auth::User::Pointer> sortedUsersList() const;
+    void doConfigChangeCleanup();
 
-    /* RegisteredRunner API */
-    virtual void endingShutdown() override;
-    virtual void syncConfig() override;
+    /// \returns alphanumerically sorted list of usernames
+    std::vector<Auth::User::Pointer> sortedUsersList() const;
 
 private:
     void scheduleCleanup();
 
-    /// whether a GC event has been scheduled
+    /// whether a cleanup (garbage collection) event has been scheduled
     bool gcScheduled_;
 
+    /// key is User::userKey(), mapped value is User::Pointer
+    typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
     StoreType store_;
 
-    // for logs, events etc.
-    const char *cachename;
-
-    // c_str() raw pointer is used in event. std::string must not reallocate
-    // after ctor and until shutdown
-    // must be unique
-    std::string cacheCleanupEventName;
+    // c-string raw pointer used as event name
+    const char * const cacheCleanupEventName;
 };
 
 } /* namespace Auth */