~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/ssl/context_storage.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2011-07-09 17:58:46 UTC
  • mfrom: (21.2.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110709175846-eu1ygzgbo8d7ujnj
Tags: 3.1.14-1
* New upstream release
  - Fixes FTBFS with GCC 4.6 (Closes: #625405)
  - Fixes issue with IPv4/IPv6 DNS resolution (Closes: #604566)
  - Fixes issue with IPv6 resolution in access.log (Closes: #604832)

* debian/control
  - Bumped Standard-Version to 3.9.2, no change needed

* debian/squid.rc
  - Fixed init script preventing alterate cache dir from being created
    (Closes: #623935)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id$
 
3
 */
 
4
 
 
5
#ifndef SQUID_SSL_CONTEXT_STORAGE_H
 
6
#define SQUID_SSL_CONTEXT_STORAGE_H
 
7
 
 
8
#if USE_SSL
 
9
 
 
10
#include "SquidTime.h"
 
11
#include "CacheManager.h"
 
12
#if HAVE_MAP
 
13
#include <map>
 
14
#endif
 
15
#if HAVE_LIST
 
16
#include <list>
 
17
#endif
 
18
 
 
19
/// TODO: Replace on real size.
 
20
#define SSL_CTX_SIZE 1024
 
21
 
 
22
namespace  Ssl
 
23
{
 
24
 
 
25
/** Reports cached SSL certificate stats to Cache Manager.
 
26
 * TODO: Use "Report" functions instead friend class.
 
27
 */
 
28
class CertificateStorageAction : public CacheManagerAction
 
29
{
 
30
public:
 
31
    CertificateStorageAction();
 
32
    virtual void run (StoreEntry *sentry);
 
33
};
 
34
 
 
35
/**
 
36
 * Memory cache for store generated SSL context. Enforces total size limits
 
37
 * using an LRU algorithm.
 
38
 */
 
39
class LocalContextStorage
 
40
{
 
41
    friend class CertificateStorageAction;
 
42
public:
 
43
    /// Cache item is an (SSL_CTX, host name) tuple.
 
44
    class Item
 
45
    {
 
46
    public:
 
47
        Item(SSL_CTX * aSsl_ctx, std::string const & aName);
 
48
        ~Item();
 
49
    public:
 
50
        SSL_CTX * ssl_ctx; ///< The SSL context.
 
51
        std::string host_name; ///< The host name of the SSL context.
 
52
    };
 
53
 
 
54
    typedef std::list<Item *> Queue;
 
55
    typedef Queue::iterator QueueIterator;
 
56
 
 
57
    /// host_name:queue_item mapping for fast lookups by host name
 
58
    typedef std::map<std::string, QueueIterator> Map;
 
59
    typedef Map::iterator MapIterator;
 
60
    typedef std::pair<std::string, QueueIterator> MapPair;
 
61
 
 
62
    LocalContextStorage(size_t aMax_memory);
 
63
    ~LocalContextStorage();
 
64
    /// Set maximum memory size for this storage.
 
65
    void SetSize(size_t aMax_memory);
 
66
    /// Return a pointer to the  added ssl_ctx or NULL if fails (eg. max cache size equal 0).
 
67
    SSL_CTX * add(char const * host_name, SSL_CTX * ssl_ctx);
 
68
    /// Find SSL_CTX in storage by host name. Lru queue will be updated.
 
69
    SSL_CTX * find(char const * host_name);
 
70
    void remove(char const * host_name); ///< Delete the SSL context by hostname
 
71
 
 
72
private:
 
73
    void purgeOne(); ///< Delete oldest object.
 
74
    /// Delete object by iterator. It is used in deletePurge() and remove(...) methods.
 
75
    void deleteAt(MapIterator i);
 
76
 
 
77
    size_t max_memory; ///< Max cache size.
 
78
    size_t memory_used; ///< Used cache size.
 
79
    Map storage; ///< The hostnames/SSL_CTX * pairs
 
80
    Queue lru_queue; ///< LRU cache index
 
81
};
 
82
 
 
83
 
 
84
/// Class for storing/manipulating LocalContextStorage per local listening address/port.
 
85
class GlobalContextStorage
 
86
{
 
87
 
 
88
    friend class CertificateStorageAction;
 
89
public:
 
90
    GlobalContextStorage();
 
91
    ~GlobalContextStorage();
 
92
    /// Create new SSL context storage for the local listening address/port.
 
93
    void addLocalStorage(IpAddress const & address, size_t size_of_store);
 
94
    /// Return the local storage for the given listening address/port.
 
95
    LocalContextStorage & getLocalStorage(IpAddress const & address);
 
96
    /// When reconfigring should be called this method.
 
97
    void reconfigureStart();
 
98
private:
 
99
    /// Called by getLocalStorage method
 
100
    void reconfigureFinish();
 
101
    bool reconfiguring; ///< True if system reconfiguring now.
 
102
    /// Storage used on configure or reconfigure.
 
103
    std::map<IpAddress, size_t> configureStorage;
 
104
    /// Map for storing all local ip address and their local storages.
 
105
    std::map<IpAddress, LocalContextStorage *> storage;
 
106
};
 
107
 
 
108
/// Global cache for store all SSL server certificates.
 
109
extern GlobalContextStorage TheGlobalContextStorage;
 
110
} //namespace Ssl
 
111
#endif // USE_SSL
 
112
 
 
113
#endif // SQUID_SSL_CONTEXT_STORAGE_H