<commit_before>/*
 * SSL/TLS certificate database and cache.
 *
 * author: <NAME> <<EMAIL>>
 */

#ifndef BENG_PROXY_SSL_CERT_CACHE_HXX
#define BENG_PROXY_SSL_CERT_CACHE_HXX

#include "NameCache.hxx"
#include "Unique.hxx"
#include "certdb/Config.hxx"
#include "certdb/CertDatabase.hxx"
#include "stock/ThreadedStock.hxx"

#include <unordered_map>
#include <string>
#include <mutex>

struct CertDatabase;

/**
 * A frontend for #CertDatabase which caches results as SSL_CTX
 * instance.  It is thread-safe, designed to be called synchronously
 * by worker threads (via #SslFilter).
 */
class CertCache final : CertNameCacheHandler {
    const CertDatabaseConfig config;

    CertNameCache name_cache;

    /**
     * Database connections used by worker threads.
     */
    ThreadedStock<CertDatabase> dbs;

    std::mutex mutex;

    /**
     * Map host names to SSL_CTX instances.  The key may be a
     * wildcard.
     */
    std::unordered_map<std::string, std::shared_ptr<SSL_CTX>> map;

public:
    explicit CertCache(const CertDatabaseConfig &_config)
        :config(_config), name_cache(_config, *this) {}

    void Disconnect() {
        name_cache.Disconnect();
    }

    /**
     * Look up a certificate by host name.  Returns the SSL_CTX
     * pointer on success, nullptr if no matching certificate was
     * found, and throws an exception on error.
     */
    std::shared_ptr<SSL_CTX> Get(const char *host);

private:
    std::shared_ptr<SSL_CTX> Add(UniqueX509 &&cert, UniqueEVP_PKEY &&key);
    std::shared_ptr<SSL_CTX> Query(const char *host);

    /* virtual methods from class CertNameCacheHandler */
    void OnCertModified(const std::string &name, bool deleted) override;
};

#endif
<commit_msg>ssl/Cache: fix CertDatabase forward declaration<commit_after>/*
 * SSL/TLS certificate database and cache.
 *
 * author: <NAME> <<EMAIL>>
 */

#ifndef BENG_PROXY_SSL_CERT_CACHE_HXX
#define BENG_PROXY_SSL_CERT_CACHE_HXX

#include "NameCache.hxx"
#include "Unique.hxx"
#include "certdb/Config.hxx"
#include "certdb/CertDatabase.hxx"
#include "stock/ThreadedStock.hxx"

#include <unordered_map>
#include <string>
#include <mutex>

class CertDatabase;

/**
 * A frontend for #CertDatabase which caches results as SSL_CTX
 * instance.  It is thread-safe, designed to be called synchronously
 * by worker threads (via #SslFilter).
 */
class CertCache final : CertNameCacheHandler {
    const CertDatabaseConfig config;

    CertNameCache name_cache;

    /**
     * Database connections used by worker threads.
     */
    ThreadedStock<CertDatabase> dbs;

    std::mutex mutex;

    /**
     * Map host names to SSL_CTX instances.  The key may be a
     * wildcard.
     */
    std::unordered_map<std::string, std::shared_ptr<SSL_CTX>> map;

public:
    explicit CertCache(const CertDatabaseConfig &_config)
        :config(_config), name_cache(_config, *this) {}

    void Disconnect() {
        name_cache.Disconnect();
    }

    /**
     * Look up a certificate by host name.  Returns the SSL_CTX
     * pointer on success, nullptr if no matching certificate was
     * found, and throws an exception on error.
     */
    std::shared_ptr<SSL_CTX> Get(const char *host);

private:
    std::shared_ptr<SSL_CTX> Add(UniqueX509 &&cert, UniqueEVP_PKEY &&key);
    std::shared_ptr<SSL_CTX> Query(const char *host);

    /* virtual methods from class CertNameCacheHandler */
    void OnCertModified(const std::string &name, bool deleted) override;
};

#endif

{'fraction_non_alphanumeric': 0.10717372515125324, 'fraction_numerical': 0.001728608470181504, 'mean_word_length': 3.7431693989071038, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5065924', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1090, 'n_words': 308}