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