]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/context_storage.cc
Cleanup: un-wrap C++ header includes
[thirdparty/squid.git] / src / ssl / context_storage.cc
1 #include "squid.h"
2 #include "mgr/Registration.h"
3 #include "ssl/context_storage.h"
4 #include "Store.h"
5 #include "StoreEntryStream.h"
6
7 #include <limits>
8 #if USE_SSL
9 #include <openssl/ssl.h>
10 #endif
11
12 Ssl::CertificateStorageAction::CertificateStorageAction(const Mgr::Command::Pointer &aCmd)
13 : Mgr::Action(aCmd)
14 {}
15
16 Ssl::CertificateStorageAction::Pointer
17 Ssl::CertificateStorageAction::Create(const Mgr::Command::Pointer &aCmd)
18 {
19 return new CertificateStorageAction(aCmd);
20 }
21
22 void Ssl::CertificateStorageAction::dump (StoreEntry *sentry)
23 {
24 StoreEntryStream stream(sentry);
25 const char delimiter = '\t';
26 const char endString = '\n';
27 // Page title.
28 stream << "Cached ssl certificates statistic.\n";
29 // Title of statistic table.
30 stream << "Port" << delimiter << "Max mem(KB)" << delimiter << "Cert number" << delimiter << "KB/cert" << delimiter << "Mem used(KB)" << delimiter << "Mem free(KB)" << endString;
31
32 // Add info for each port.
33 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = TheGlobalContextStorage.storage.begin(); i != TheGlobalContextStorage.storage.end(); ++i) {
34 stream << i->first << delimiter;
35 LocalContextStorage & ssl_store_policy(*(i->second));
36 stream << ssl_store_policy.memLimit() / 1024 << delimiter;
37 stream << ssl_store_policy.entries() << delimiter;
38 stream << SSL_CTX_SIZE / 1024 << delimiter;
39 stream << ssl_store_policy.size() / 1024 << delimiter;
40 stream << ssl_store_policy.freeMem() / 1024 << endString;
41 }
42 stream << endString;
43 stream.flush();
44 }
45
46 ///////////////////////////////////////////////////////
47
48 Ssl::GlobalContextStorage::GlobalContextStorage()
49 : reconfiguring(true)
50 {
51 RegisterAction("cached_ssl_cert", "Statistic of cached generated ssl certificates", &CertificateStorageAction::Create, 0, 1);
52 }
53
54 Ssl::GlobalContextStorage::~GlobalContextStorage()
55 {
56 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end(); ++i) {
57 delete i->second;
58 }
59 }
60
61 void Ssl::GlobalContextStorage::addLocalStorage(Ip::Address const & address, size_t size_of_store)
62 {
63 assert(reconfiguring);
64 configureStorage.insert(std::pair<Ip::Address, size_t>(address, size_of_store));
65 }
66
67 Ssl::LocalContextStorage *Ssl::GlobalContextStorage::getLocalStorage(Ip::Address const & address)
68 {
69 reconfigureFinish();
70 std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.find(address);
71
72 if (i == storage.end())
73 return NULL;
74 else
75 return i->second;
76 }
77
78 void Ssl::GlobalContextStorage::reconfigureStart()
79 {
80 configureStorage.clear();
81 reconfiguring = true;
82 }
83
84 void Ssl::GlobalContextStorage::reconfigureFinish()
85 {
86 if (reconfiguring) {
87 reconfiguring = false;
88
89 // remove or change old local storages.
90 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end(); ++i) {
91 std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.find(i->first);
92 if (conf_i == configureStorage.end() || conf_i->second <= 0) {
93 storage.erase(i);
94 } else {
95 i->second->setMemLimit(conf_i->second);
96 }
97 }
98
99 // add new local storages.
100 for (std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.begin(); conf_i != configureStorage.end(); ++conf_i ) {
101 if (storage.find(conf_i->first) == storage.end() && conf_i->second > 0) {
102 storage.insert(std::pair<Ip::Address, LocalContextStorage *>(conf_i->first, new LocalContextStorage(-1, conf_i->second)));
103 }
104 }
105 }
106 }
107
108 Ssl::GlobalContextStorage Ssl::TheGlobalContextStorage;