CertificateHandlerFactory.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef NetSSL_CertificateHandlerFactory_INCLUDED
  16. #define NetSSL_CertificateHandlerFactory_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. namespace Poco {
  19. namespace Net {
  20. class InvalidCertificateHandler;
  21. class NetSSL_API CertificateHandlerFactory
  22. /// A CertificateHandlerFactory is responsible for creating InvalidCertificateHandlers.
  23. ///
  24. /// You don't need to access this class directly. Use the macro
  25. /// POCO_REGISTER_CHFACTORY(namespace, InvalidCertificateHandlerName)
  26. /// instead (see the documentation of InvalidCertificateHandler for an example).
  27. {
  28. public:
  29. CertificateHandlerFactory();
  30. /// Creates the CertificateHandlerFactory.
  31. virtual ~CertificateHandlerFactory();
  32. /// Destroys the CertificateHandlerFactory.
  33. virtual InvalidCertificateHandler* create(bool server) const = 0;
  34. /// Creates a new InvalidCertificateHandler. Set server to true if the certificate handler is used on the server side.
  35. };
  36. class NetSSL_API CertificateHandlerFactoryRegistrar
  37. /// Registrar class which automatically registers CertificateHandlerFactory at the CertificateHandlerFactoryMgr.
  38. /// You don't need to access this class directly. Use the macro
  39. /// POCO_REGISTER_CHFACTORY(namespace, InvalidCertificateHandlerName)
  40. /// instead (see the documentation of InvalidCertificateHandler for an example).
  41. {
  42. public:
  43. CertificateHandlerFactoryRegistrar(const std::string& name, CertificateHandlerFactory* pFactory);
  44. /// Registers the CertificateHandlerFactory with the given name at the factory manager.
  45. virtual ~CertificateHandlerFactoryRegistrar();
  46. /// Destroys the CertificateHandlerFactoryRegistrar.
  47. };
  48. template <typename T>
  49. class CertificateHandlerFactoryImpl: public Poco::Net::CertificateHandlerFactory
  50. {
  51. public:
  52. CertificateHandlerFactoryImpl()
  53. {
  54. }
  55. ~CertificateHandlerFactoryImpl()
  56. {
  57. }
  58. InvalidCertificateHandler* create(bool server) const
  59. {
  60. return new T(server);
  61. }
  62. };
  63. } } // namespace Poco::Net
  64. // DEPRECATED: register the factory directly at the FactoryMgr:
  65. // Poco::Net::SSLManager::instance().certificateHandlerFactoryMgr().setFactory(name, new Poco::Net::CertificateHandlerFactoryImpl<MyConsoleHandler>());
  66. #define POCO_REGISTER_CHFACTORY(API, PKCLS) \
  67. static Poco::Net::CertificateHandlerFactoryRegistrar aRegistrar(std::string(#PKCLS), new Poco::Net::CertificateHandlerFactoryImpl<PKCLS>());
  68. #endif // NetSSL_CertificateHandlerFactory_INCLUDED