Cookie.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2010 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_COOKIE_H
  36. #define D_COOKIE_H
  37. #include "common.h"
  38. #include <string>
  39. #include "a2time.h"
  40. namespace aria2 {
  41. class Cookie {
  42. private:
  43. std::string name_;
  44. std::string value_;
  45. time_t expiryTime_;
  46. // If persistent_ is false, this is a session scope cookie and it is
  47. // never expired during session. So isExpired() always returns
  48. // false.
  49. bool persistent_;
  50. std::string domain_;
  51. bool hostOnly_;
  52. std::string path_;
  53. bool secure_;
  54. bool httpOnly_;
  55. time_t creationTime_;
  56. time_t lastAccessTime_;
  57. public:
  58. Cookie();
  59. Cookie
  60. (const std::string& name,
  61. const std::string& value,
  62. time_t expiryTime,
  63. bool persistent,
  64. const std::string& domain,
  65. bool hostOnly,
  66. const std::string& path,
  67. bool secure,
  68. bool httpOnly,
  69. time_t creationTime);
  70. Cookie(const Cookie& c);
  71. ~Cookie();
  72. Cookie& operator=(const Cookie& c);
  73. std::string toString() const;
  74. bool match
  75. (const std::string& requestHost, const std::string& requestPath,
  76. time_t date, bool secure) const;
  77. bool operator==(const Cookie& cookie) const;
  78. bool isExpired(time_t base) const;
  79. const std::string& getName() const
  80. {
  81. return name_;
  82. }
  83. void setName(const std::string& name);
  84. const std::string& getValue() const
  85. {
  86. return value_;
  87. }
  88. void setValue(const std::string& value);
  89. time_t getExpiryTime() const
  90. {
  91. return expiryTime_;
  92. }
  93. void setExpiryTime(time_t expiryTime)
  94. {
  95. expiryTime_ = expiryTime;
  96. }
  97. bool getPersistent() const
  98. {
  99. return persistent_;
  100. }
  101. void setPersistent(bool persistent)
  102. {
  103. persistent_ = persistent;
  104. }
  105. const std::string& getDomain() const
  106. {
  107. return domain_;
  108. }
  109. void setDomain(const std::string& domain);
  110. bool getHostOnly() const
  111. {
  112. return hostOnly_;
  113. }
  114. void setHostOnly(bool hostOnly)
  115. {
  116. hostOnly_ = hostOnly;
  117. }
  118. const std::string& getPath() const
  119. {
  120. return path_;
  121. }
  122. void setPath(const std::string& path);
  123. bool getSecure() const
  124. {
  125. return secure_;
  126. }
  127. void setSecure(bool secure)
  128. {
  129. secure_ = secure;
  130. }
  131. bool getHttpOnly() const
  132. {
  133. return httpOnly_;
  134. }
  135. void setHttpOnly(bool httpOnly)
  136. {
  137. httpOnly_ = httpOnly;
  138. }
  139. time_t getCreationTime() const
  140. {
  141. return creationTime_;
  142. }
  143. void setCreationTime(time_t creationTime)
  144. {
  145. creationTime_ = creationTime;
  146. }
  147. time_t getLastAccessTime() const
  148. {
  149. return lastAccessTime_;
  150. }
  151. void setLastAccessTime(time_t lastAccessTime)
  152. {
  153. lastAccessTime_ = lastAccessTime;
  154. }
  155. std::string toNsCookieFormat() const;
  156. };
  157. } // namespace aria2
  158. #endif // D_COOKIE_H