]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/CredentialsCache.h
Maintenance: No ptr copy in future CredentialsCache::insert()s (#1807)
[thirdparty/squid.git] / src / auth / CredentialsCache.h
CommitLineData
f21d7eaa 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
f21d7eaa
FC
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
638cfbc4
AJ
9#ifndef SQUID_SRC_AUTH_CREDENTIALSCACHE_H
10#define SQUID_SRC_AUTH_CREDENTIALSCACHE_H
f21d7eaa 11
0b5cd1d0 12#include "auth/User.h"
7512e3f9 13#include "cbdata.h"
5218815a 14#include "sbuf/Algorithms.h"
f21d7eaa
FC
15
16#include <unordered_map>
17
18namespace Auth {
19
4fca920f 20/// Cache of Auth::User credentials, keyed by Auth::User::userKey
51087401 21class CredentialsCache
f21d7eaa 22{
638cfbc4 23 CBDATA_CLASS(CredentialsCache);
f6d8c56e 24
f21d7eaa 25public:
455bb54d 26 explicit CredentialsCache(const char *name, const char * const eventName);
f21d7eaa 27
638cfbc4 28 ~CredentialsCache() = default;
4e7c52d9 29 CredentialsCache(const CredentialsCache&) = delete;
638cfbc4 30 CredentialsCache& operator=(const CredentialsCache&) = delete;
f21d7eaa 31
4fca920f 32 /// \returns a pointer to cached credentials, or nil if none found
26ba1d87 33 Auth::User::Pointer lookup(const SBuf &userKey) const;
f21d7eaa 34
97821413 35 /// add an user to the cache with the provided key
e5827d49 36 void insert(const SBuf &userKey, const Auth::User::Pointer &anAuth_user);
56e5a1c7 37
c531de88
FC
38 /// clear cache
39 void reset() { store_.clear(); }
f21d7eaa 40
fde785ee 41 /// \returns number of cached usernames
26ba1d87 42 size_t size() const { return store_.size(); }
f21d7eaa 43
0b5cd1d0
FC
44 /** periodic cleanup function, removes timed-out entries
45 *
56e5a1c7 46 * Must be static to support EVH interface. Argument will be this
0b5cd1d0 47 */
c531de88 48 static void Cleanup(void *);
f21d7eaa 49
2d9bd2a1
AJ
50 /// cache garbage collection, removes timed-out entries
51 void cleanup();
52
51087401 53 /**
61beade2 54 * Cleanup cache data after a reconfiguration has occurred.
51087401
AJ
55 * Similar to cleanup() but also flushes stale config dependent
56 * state from retained entries.
57 */
58 void doConfigChangeCleanup();
59
fde785ee 60 /// \returns alphanumerically sorted list of usernames
26ba1d87 61 std::vector<Auth::User::Pointer> sortedUsersList() const;
f6d8c56e 62
f21d7eaa 63private:
15094d79
AJ
64 void scheduleCleanup();
65
e7403d01 66 /// whether a cleanup (garbage collection) event has been scheduled
15094d79
AJ
67 bool gcScheduled_;
68
81da7e70
AR
69 /// key is User::userKey(), mapped value is User::Pointer
70 typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
f21d7eaa
FC
71 StoreType store_;
72
455bb54d
AJ
73 // c-string raw pointer used as event name
74 const char * const cacheCleanupEventName;
f21d7eaa
FC
75};
76
77} /* namespace Auth */
46b1e6bf 78
638cfbc4 79#endif /* SQUID_SRC_AUTH_CREDENTIALSCACHE_H */
7512e3f9 80