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.
 
 
 
 
 
 

108 lines
2.3 KiB

  1. #ifndef CPPCMS_SESSION_INTERFACE_H
  2. #define CPPCMS_SESSION_INTERFACE_H
  3. #include <boost/noncopyable.hpp>
  4. #include <boost/lexical_cast.hpp>
  5. #include <boost/shared_ptr.hpp>
  6. #include <string>
  7. #include <map>
  8. namespace cppcms {
  9. class session_api;
  10. class worker_thread;
  11. class serializable;
  12. class session_interface : private boost::noncopyable {
  13. struct entry {
  14. std::string value;
  15. bool exposed;
  16. entry(std::string v="",bool exp=false) : value(v) , exposed(exp) {}
  17. bool operator==(entry const &other) const
  18. {
  19. return value==other.value && exposed==other.exposed;
  20. }
  21. bool operator!=(entry const &other) const
  22. {
  23. return !(*this==other);
  24. }
  25. };
  26. typedef std::map<std::string,entry> data_t;
  27. data_t data,data_copy;
  28. worker_thread &worker;
  29. // Cached defaults
  30. int timeout_val_def;
  31. int how_def;
  32. // User Values
  33. int timeout_val;
  34. int how;
  35. // Information from session data
  36. time_t timeout_in;
  37. bool new_session;
  38. bool saved;
  39. int cookie_age();
  40. time_t session_age();
  41. void check();
  42. bool load();
  43. void update_exposed();
  44. std::string temp_cookie;
  45. boost::shared_ptr<session_api> storage;
  46. void set_session_cookie(int64_t age,std::string const &data,std::string const &key=std::string());
  47. void save_data(data_t const &data,std::string &s);
  48. void load_data(data_t &data,std::string const &s);
  49. public:
  50. session_interface(worker_thread &w);
  51. bool is_set(std::string const &key);
  52. void del(std::string const &key);
  53. std::string &operator[](std::string const &);
  54. template<typename T>
  55. T get(std::string const &key) {
  56. return boost::lexical_cast<T>((*this)[key]);
  57. }
  58. template<typename T>
  59. void set(std::string const &key,T const &val) {
  60. (*this)[key]=boost::lexical_cast<std::string>(val);
  61. }
  62. void get(std::string const &key,serializable &);
  63. void set(std::string const &key,serializable const &);
  64. bool is_exposed(std::string const &key);
  65. void expose(std::string const &key,bool val=true);
  66. void hide(std::string const &key);
  67. void clear();
  68. enum { fixed, renew, browser };
  69. void set_age(int t);
  70. void set_expiration(int h);
  71. void set_age();
  72. void set_expiration();
  73. void save();
  74. // Special interface
  75. void set_session_cookie(std::string const &data);
  76. void clear_session_cookie();
  77. std::string get_session_cookie();
  78. void set_api(boost::shared_ptr<session_api>);
  79. void on_start();
  80. void on_end();
  81. worker_thread &get_worker();
  82. };
  83. } // cppcms
  84. #endif