ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
3.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_SESSION_COOKIES_H
  9. #define CPPCMS_SESSION_COOKIES_H
  10. #include <cppcms/session_api.h>
  11. #include <booster/hold_ptr.h>
  12. #include <booster/noncopyable.h>
  13. #include <booster/auto_ptr_inc.h>
  14. #include <string>
  15. namespace cppcms {
  16. class session_interface;
  17. ///
  18. /// \brief this namespace keeps various session storage backends
  19. ///
  20. namespace sessions {
  21. ///
  22. /// \brief This is an interface to generic session cookies encryption or signing API.
  23. ///
  24. /// Note for users implementing their own ecryptor classes:
  25. ///
  26. /// - Be super paranoid and extremely careful in what you are doing.
  27. /// - Take in mind that this object are created and destroyed much frequently then they are actually
  28. /// accessed, so lazy initialization is your best friend.
  29. ///
  30. /// Note this class does not have to be thread safe to use from multiple threads.
  31. ///
  32. class encryptor : public booster::noncopyable {
  33. public:
  34. ///
  35. /// Encrypt or sign the plain text \a plain together with \a timeout and return the encrypted value for a cookie.
  36. /// Don't forget to use base64 encoding in order to create a string that is valid for cookie
  37. ///
  38. virtual std::string encrypt(std::string const &plain) = 0;
  39. ///
  40. /// Decrypt the \a cipher text or check the signature and return the \a plain text and the session expiration value: \a timeout.
  41. ///
  42. /// If signature checks or decryption failed return false.
  43. ///
  44. virtual bool decrypt(std::string const &cipher,std::string &plain) = 0;
  45. ///
  46. /// Destructor
  47. ///
  48. virtual ~encryptor() {}
  49. };
  50. ///
  51. /// \brief This is an interface for an object that creates new encryptors
  52. ///
  53. /// This class must be thread safe.
  54. ///
  55. class encryptor_factory {
  56. public:
  57. ///
  58. /// Return a pointer to a newly created encryptor.
  59. ///
  60. virtual std::auto_ptr<encryptor> get() = 0;
  61. ///
  62. /// Destructor - cleanup everything
  63. ///
  64. virtual ~encryptor_factory() {}
  65. };
  66. ///
  67. /// \brief The implementation of session_api using encrypted or signed cookies
  68. ///
  69. class CPPCMS_API session_cookies : public session_api {
  70. public:
  71. ///
  72. /// Create a new object passing it a pointer ecryptor as parameter
  73. ///
  74. session_cookies(std::auto_ptr<encryptor> encryptor);
  75. ///
  76. /// Destroy it and destroy an encryptor it was created with
  77. ///
  78. ~session_cookies();
  79. ///
  80. /// Save session to cookies, see session_api::save
  81. ///
  82. virtual void save(session_interface &,std::string const &data,time_t timeout,bool newone ,bool on_server);
  83. ///
  84. /// Load session from cookies, see session_api::load
  85. ///
  86. virtual bool load(session_interface &,std::string &data,time_t &timeout);
  87. ///
  88. /// See session_api::is_blocking
  89. ///
  90. virtual bool is_blocking();
  91. ///
  92. /// Delete session, see session_api::clear
  93. ///
  94. virtual void clear(session_interface &);
  95. private:
  96. struct _data;
  97. booster::hold_ptr<_data> d;
  98. std::auto_ptr<encryptor> encryptor_;
  99. };
  100. } // sessions
  101. } // cppcms
  102. #endif