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.
 
 
 
 
 
 

141 lines
4.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef SESSION_FILE_STORAGE_H
  20. #define SESSION_FILE_STORAGE_H
  21. #include <string>
  22. #include <vector>
  23. #include "config.h"
  24. #ifdef CPPCMS_USE_EXTERNAL_BOOST
  25. # include <boost/noncopyable.hpp>
  26. # include <boost/shared_ptr.hpp>
  27. #else // Internal Boost
  28. # include <cppcms_boost/noncopyable.hpp>
  29. # include <cppcms_boost/shared_ptr.hpp>
  30. namespace boost = cppcms_boost;
  31. #endif
  32. #include <pthread.h>
  33. #include "session_storage.h"
  34. #include "session_backend_factory.h"
  35. #include "config.h"
  36. namespace cppcms {
  37. class cppcms_config;
  38. namespace storage {
  39. class io : private boost::noncopyable {
  40. protected:
  41. std::string dir;
  42. int lock_id(std::string const &sid) const;
  43. std::string mkname(std::string const &sid) const;
  44. virtual void close(int fid) const;
  45. public:
  46. std::string const &get_dir() const { return dir; }
  47. io(std::string d) : dir(d) {}
  48. virtual void wrlock(std::string const &sid) const = 0;
  49. virtual void rdlock(std::string const &sid) const = 0;
  50. virtual void unlock(std::string const &sid) const = 0;
  51. virtual void write(std::string const &sid,time_t timestamp,void const *buf,size_t len) const;
  52. virtual bool read(std::string const &sid,time_t &timestamp,std::vector<unsigned char> *out) const;
  53. virtual void unlink(std::string const &sid) const;
  54. virtual ~io(){};
  55. };
  56. #if !defined(CPPCMS_EMBEDDED)
  57. class local_io : public io {
  58. protected:
  59. pthread_rwlock_t *locks;
  60. public:
  61. local_io(std::string dir,pthread_rwlock_t *l);
  62. virtual void wrlock(std::string const &sid) const;
  63. virtual void rdlock(std::string const &sid) const;
  64. virtual void unlock(std::string const &sid) const;
  65. };
  66. class thread_io : public local_io
  67. {
  68. pthread_rwlock_t *create_locks();
  69. public:
  70. thread_io(std::string dir);
  71. ~thread_io();
  72. };
  73. class nfs_io : public thread_io {
  74. int fid;
  75. protected:
  76. virtual void close(int fid) const;
  77. public:
  78. nfs_io(std::string dir);
  79. virtual void wrlock(std::string const &sid) const;
  80. virtual void rdlock(std::string const &sid) const;
  81. virtual void unlock(std::string const &sid) const;
  82. ~nfs_io();
  83. };
  84. #ifdef HAVE_PTHREADS_PSHARED
  85. class shmem_io : public local_io
  86. {
  87. int creator_pid;
  88. pthread_rwlock_t *create_locks();
  89. public:
  90. shmem_io(std::string dir);
  91. ~shmem_io();
  92. };
  93. #endif
  94. #else // !CPPCMS_EMBEDDED
  95. class embed_io : public io {
  96. int fid;
  97. public:
  98. embed_io(std::string dir);
  99. virtual void wrlock(std::string const &sid) const;
  100. virtual void rdlock(std::string const &sid) const;
  101. virtual void unlock(std::string const &sid) const;
  102. ~embed_io();
  103. };
  104. #endif // CPPCMS_EMBEDDED
  105. } // storage
  106. class session_file_storage : public session_server_storage {
  107. boost::shared_ptr<storage::io> io;
  108. public:
  109. static void gc(boost::shared_ptr<storage::io>);
  110. static session_backend_factory factory(cppcms_config const &);
  111. session_file_storage(boost::shared_ptr<storage::io> io_) : io(io_) {}
  112. virtual void save(std::string const &sid,time_t timeout,std::string const &in);
  113. virtual bool load(std::string const &sid,time_t *timeout,std::string &out);
  114. virtual void remove(std::string const &sid) ;
  115. virtual ~session_file_storage(){};
  116. };
  117. } // cppcms
  118. #endif