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.
 
 
 
 
 
 

178 lines
3.8 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_HTTP_COOKIE_H
  9. #define CPPCMS_HTTP_COOKIE_H
  10. #include <cppcms/defs.h>
  11. #include <booster/copy_ptr.h>
  12. #include <string>
  13. #include <iostream>
  14. #include <cppcms/cstdint.h>
  15. namespace cppcms { namespace http {
  16. class cookie;
  17. std::ostream CPPCMS_API &operator<<(std::ostream &,cookie const &);
  18. ///
  19. /// \brief Class that represents single HTTP Cookie
  20. /// Generally used in context of http::request and http::response
  21. ///
  22. class CPPCMS_API cookie {
  23. public:
  24. ///
  25. /// Cookie's Name
  26. ///
  27. std::string name() const;
  28. ///
  29. /// Cookie's value
  30. ///
  31. std::string value() const;
  32. ///
  33. /// Cookie's path
  34. ///
  35. std::string path() const;
  36. ///
  37. /// Cookie's domain
  38. ///
  39. std::string domain() const;
  40. ///
  41. /// Cookie's comment
  42. ///
  43. std::string comment() const;
  44. ///
  45. /// Check if the cookie is transferred over secure connection only
  46. ///
  47. bool secure() const;
  48. ///
  49. /// Set cookie's name
  50. ///
  51. void name(std::string n);
  52. ///
  53. /// Set cookie's value
  54. ///
  55. void value(std::string v);
  56. ///
  57. /// Set cookie's path
  58. ///
  59. void path(std::string p);
  60. ///
  61. /// Set cookie's domain
  62. ///
  63. void domain(std::string);
  64. ///
  65. /// Set cookie's comment
  66. ///
  67. void comment(std::string);
  68. ///
  69. /// Set expiration date/time
  70. ///
  71. void expires(time_t when);
  72. ///
  73. /// Returns expires timestamp for the cookie, if not set returns 0
  74. ///
  75. /// \ver{v1_2}
  76. time_t expires() const;
  77. ///
  78. /// returns true if expires(time_t when) was called and expiration was set,
  79. /// if browser_age() is called it is reset to false
  80. ///
  81. /// \ver{v1_2}
  82. bool expires_defined() const;
  83. ///
  84. /// Set max cookie's age
  85. ///
  86. void max_age(unsigned age);
  87. ///
  88. /// Get max cookie's age, returns 0 if not set
  89. ///
  90. /// \ver{v1_2}
  91. unsigned max_age() const;
  92. ///
  93. /// returns true if max(unsigned age) was called and max_age was set,
  94. /// if browser_age() is called it is reset to false
  95. ///
  96. /// \ver{v1_2}
  97. bool max_age_defined() const;
  98. ///
  99. /// Set age according to browser's session (i.e. no Max-Age)
  100. ///
  101. void browser_age();
  102. ///
  103. /// Set secure property on the cookies
  104. ///
  105. void secure(bool v);
  106. ///
  107. /// Check if cookie is not assigned - empty
  108. ///
  109. bool empty() const;
  110. cookie();
  111. ~cookie();
  112. cookie(cookie const &);
  113. cookie const &operator=(cookie const &);
  114. ///
  115. /// Create cookie with name and value, age - browser, rest properties undefined.
  116. ///
  117. cookie(std::string name,std::string value);
  118. ///
  119. /// Create cookies with name, value and max-age, rest properties undefined.
  120. ///
  121. cookie(std::string name,std::string value,unsigned age);
  122. ///
  123. /// Create cookie with name, value, max-age, path, domain and command
  124. ///
  125. cookie(std::string name,std::string value,unsigned age,std::string path,std::string domain = std::string(),std::string comment=std::string());
  126. ///
  127. /// Create cookie with name, value, path, domain and comment, age - browser.
  128. cookie(std::string name,std::string value,std::string path,std::string domain=std::string(),std::string comment=std::string());
  129. private:
  130. friend std::ostream &operator<<(std::ostream &,cookie const &);
  131. void write(std::ostream &) const;
  132. // for future use
  133. struct _data;
  134. booster::copy_ptr<_data> d;
  135. // real members
  136. std::string name_;
  137. std::string value_;
  138. std::string path_;
  139. std::string domain_;
  140. std::string comment_;
  141. unsigned max_age_;
  142. uint32_t secure_ : 1;
  143. uint32_t has_age_ : 1;
  144. uint32_t has_expiration_: 1;
  145. CPPCMS_UNUSED_MEMBER uint32_t reserved_ : 29;
  146. };
  147. } } //::cppcms::http
  148. #endif