| 1 | // |
| 2 | // CertificateHandlerFactory.h |
| 3 | // |
| 4 | // Library: NetSSL_OpenSSL |
| 5 | // Package: SSLCore |
| 6 | // Module: CertificateHandlerFactory |
| 7 | // |
| 8 | // Definition of the CertificateHandlerFactory class. |
| 9 | // |
| 10 | // Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef NetSSL_CertificateHandlerFactory_INCLUDED |
| 18 | #define NetSSL_CertificateHandlerFactory_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Net/NetSSL.h" |
| 22 | |
| 23 | |
| 24 | namespace Poco { |
| 25 | namespace Net { |
| 26 | |
| 27 | |
| 28 | class InvalidCertificateHandler; |
| 29 | |
| 30 | |
| 31 | class NetSSL_API CertificateHandlerFactory |
| 32 | /// A CertificateHandlerFactory is responsible for creating InvalidCertificateHandlers. |
| 33 | /// |
| 34 | /// You don't need to access this class directly. Use the macro |
| 35 | /// POCO_REGISTER_CHFACTORY(namespace, InvalidCertificateHandlerName) |
| 36 | /// instead (see the documentation of InvalidCertificateHandler for an example). |
| 37 | { |
| 38 | public: |
| 39 | CertificateHandlerFactory(); |
| 40 | /// Creates the CertificateHandlerFactory. |
| 41 | |
| 42 | virtual ~CertificateHandlerFactory(); |
| 43 | /// Destroys the CertificateHandlerFactory. |
| 44 | |
| 45 | virtual InvalidCertificateHandler* create(bool server) const = 0; |
| 46 | /// Creates a new InvalidCertificateHandler. Set server to true if the certificate handler is used on the server side. |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | class NetSSL_API CertificateHandlerFactoryRegistrar |
| 51 | /// Registrar class which automatically registers CertificateHandlerFactory at the CertificateHandlerFactoryMgr. |
| 52 | /// You don't need to access this class directly. Use the macro |
| 53 | /// POCO_REGISTER_CHFACTORY(namespace, InvalidCertificateHandlerName) |
| 54 | /// instead (see the documentation of InvalidCertificateHandler for an example). |
| 55 | { |
| 56 | public: |
| 57 | CertificateHandlerFactoryRegistrar(const std::string& name, CertificateHandlerFactory* pFactory); |
| 58 | /// Registers the CertificateHandlerFactory with the given name at the factory manager. |
| 59 | |
| 60 | virtual ~CertificateHandlerFactoryRegistrar(); |
| 61 | /// Destroys the CertificateHandlerFactoryRegistrar. |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | template <typename T> |
| 66 | class CertificateHandlerFactoryImpl: public Poco::Net::CertificateHandlerFactory |
| 67 | { |
| 68 | public: |
| 69 | CertificateHandlerFactoryImpl() |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | ~CertificateHandlerFactoryImpl() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | InvalidCertificateHandler* create(bool server) const |
| 78 | { |
| 79 | return new T(server); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | } } // namespace Poco::Net |
| 85 | |
| 86 | |
| 87 | // DEPRECATED: register the factory directly at the FactoryMgr: |
| 88 | // Poco::Net::SSLManager::instance().certificateHandlerFactoryMgr().setFactory(name, new Poco::Net::CertificateHandlerFactoryImpl<MyConsoleHandler>()); |
| 89 | #define POCO_REGISTER_CHFACTORY(API, PKCLS) \ |
| 90 | static Poco::Net::CertificateHandlerFactoryRegistrar aRegistrar(std::string(#PKCLS), new Poco::Net::CertificateHandlerFactoryImpl<PKCLS>()); |
| 91 | |
| 92 | |
| 93 | #endif // NetSSL_CertificateHandlerFactory_INCLUDED |
| 94 | |