HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_NetworkCookie.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_NetworkCookie.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __NET_NETWORKCOOKIE_H__
13 #define __NET_NETWORKCOOKIE_H__
14 
15 #include "NET_API.h"
16 
17 #include "NET_ConvertToType.h"
18 #include "NET_Time.h"
19 
20 #include <UT/UT_Array.h>
21 #include <UT/UT_StringHolder.h>
22 #include <UT/UT_Url.h>
23 
24 #include <ctime>
25 
26 class NET_NetworkCookie;
28 
29 class NET_API NET_NetworkCookie
30 {
31 public:
33  {
35  Full
36  };
37 
40 
41  NET_NetworkCookie(const NET_NetworkCookie &cookie);
42  NET_NetworkCookie &operator=(const NET_NetworkCookie &cookie);
43 
45  NET_NetworkCookie &operator=(NET_NetworkCookie &&cookie);
46 
47  bool operator==(const NET_NetworkCookie &cookie) const;
48  bool operator!=(const NET_NetworkCookie &cookie) const;
49 
50  bool hasSameIdentifier(const NET_NetworkCookie &cookie) const;
51  UT_StringHolder toString(StringForm form = Full) const;
52  bool hasMatchingDomain(const NET_NetworkCookie &cookie) const;
53  bool hasMatchingDomain(const UT_Url &url) const;
54  bool hasMatchingPath(const UT_StringRef &path) const;
55  bool hasMatchingPath(const UT_Url &url) const;
56  bool hasMatchingPath(const NET_NetworkCookie &cookie) const;
57 
58  bool isValid() const;
59  bool hasExpired() const;
60 
61  void normalize(const UT_Url &url);
62 
63  bool parseCookie(const UT_StringRef& cookie);
64  static void parseCookies(const UT_StringArray &cookie_string,
65  NET_CookieList &cookies);
66 
67  const UT_StringHolder &name() const { return myName; }
68  const UT_StringHolder &domain() const { return myDomain; }
69  const NET_Time &creation() const { return myCreationDate; }
70  const NET_Time &expiration() const { return myExpirationDate; }
71  const UT_StringHolder &path() const { return myPath; }
72  const UT_StringHolder &value() const { return myValue; }
73  bool isHttpOnly() const { return myHttpOnly; }
74  bool isSecure() const { return myIsSecure; }
75  const NET_Time &lastAccess() const { return myLastAccessDate; }
76  bool isPersistent() const { return myIsPersistent; }
77 
78  void setName(const UT_StringHolder &name) { myName = name; }
79  void setDomain(const UT_StringHolder &domain) { myDomain = domain; }
80  void setCreation(const NET_Time &t) { myCreationDate = t; }
81  void setExpiration(const NET_Time &t)
82  {
83  myExpirationDate = t;
84  myHasExpires = !myExpirationDate.isNull();
85  setPersistent(myHasExpires);
86  }
87  bool setExpiration(const UT_StringRef& date)
88  {
89  bool result = NET_Time::fromUTCString(date, myExpirationDate);
90 
91  myHasExpires = result && !myExpirationDate.isNull();
92  setPersistent(myHasExpires);
93  return result;
94  }
95  void setPath(const UT_StringHolder &path) { myPath = path; }
96  void setValue(const UT_StringHolder &value) { myValue = value; }
97  void setHttpOnly(bool http_only) { myHttpOnly = http_only; }
98  void setSecure(bool is_secure) { myIsSecure = is_secure; }
99  void setLastAccess(const NET_Time &t) { myLastAccessDate = t; }
100  void setPersistent(bool is_persistent) { myIsPersistent = is_persistent; }
101 
102  // Debug print the entire contents of the cookie
103  void dump() const;
104 private:
106 
107  UT_StringHolder myName;
108  UT_StringHolder myDomain;
109  NET_Time myCreationDate;
110  NET_Time myExpirationDate;
111  UT_StringHolder myPath;
112  UT_StringHolder myValue;
113  bool myHttpOnly;
114  bool myIsSecure;
115  bool myIsPersistent;
116  NET_Time myLastAccessDate;
117  bool myHasExpires;
118  // These variables are not used. They are only used to interface properly
119  // with QtWebEngine
120  int myPriority;
121 };
122 
124  : myName(cookie.myName),
125  myDomain(cookie.myDomain),
126  myCreationDate(cookie.myCreationDate),
127  myExpirationDate(cookie.myExpirationDate),
128  myPath(cookie.myPath),
129  myValue(cookie.myValue),
130  myHttpOnly(cookie.myHttpOnly),
131  myIsSecure(cookie.myIsSecure),
132  myLastAccessDate(cookie.myLastAccessDate),
133  myIsPersistent(cookie.myIsPersistent),
134  myHasExpires(cookie.myHasExpires),
135  // Unused
136  myPriority(cookie.myPriority)
137 {
138 }
139 
140 inline NET_NetworkCookie &
142 {
143  myName = cookie.myName;
144  myDomain = cookie.myDomain;
145  myCreationDate = cookie.myCreationDate;
146  myExpirationDate = cookie.myExpirationDate;
147  myPath = cookie.myPath;
148  myValue = cookie.myValue;
149  myHttpOnly = cookie.myHttpOnly;
150  myIsSecure = cookie.myIsSecure;
151  myLastAccessDate = cookie.myLastAccessDate;
152  myIsPersistent = cookie.myIsPersistent;
153  myHasExpires = cookie.myHasExpires;
154  // Unused
155  myPriority = cookie.myPriority;
156 
157  return *this;
158 }
159 
161  : myName(std::move(cookie.myName)),
162  myDomain(std::move(cookie.myDomain)),
163  myCreationDate(std::move(cookie.myCreationDate)),
164  myExpirationDate(std::move(cookie.myExpirationDate)),
165  myPath(std::move(cookie.myPath)),
166  myValue(std::move(cookie.myValue)),
167  myHttpOnly(std::move(cookie.myHttpOnly)),
168  myIsSecure(std::move(cookie.myIsSecure)),
169  myLastAccessDate(std::move(cookie.myLastAccessDate)),
170  myIsPersistent(std::move(cookie.myIsPersistent)),
171  myHasExpires(std::move(cookie.myHasExpires)),
172  // Unused
173  myPriority(std::move(cookie.myPriority))
174 {
175 }
176 
177 inline NET_NetworkCookie &
179 {
180  myName = std::move(cookie.myName);
181  myDomain = std::move(cookie.myDomain);
182  myCreationDate = std::move(cookie.myCreationDate);
183  myExpirationDate = std::move(cookie.myExpirationDate);
184  myPath = std::move(cookie.myPath);
185  myValue = std::move(cookie.myValue);
186  myHttpOnly = std::move(cookie.myHttpOnly);
187  myIsSecure = std::move(cookie.myIsSecure);
188  myLastAccessDate = std::move(cookie.myLastAccessDate);
189  myIsPersistent = std::move(cookie.myIsPersistent);
190  myHasExpires = std::move(cookie.myHasExpires);
191  // Unused
192  myPriority = std::move(cookie.myPriority);
193 
194  return *this;
195 }
196 
197 inline bool
199 {
200  return myName == cookie.myName && myDomain == cookie.myDomain &&
201  myExpirationDate == cookie.myExpirationDate &&
202  myPath == cookie.myPath && myValue == cookie.myValue &&
203  myHttpOnly == cookie.myHttpOnly && myIsSecure == cookie.myIsSecure &&
204  myIsPersistent == cookie.myIsPersistent &&
205  myHasExpires == cookie.myHasExpires;
206 }
207 
208 inline bool
210 {
211  return !(*this == cookie);
212 }
213 
214 // Serialize
215 template<>
217 {
218  if (!cookie.isValid())
219  return false;
220 
221  writer.jsonValue(cookie.toString());
222  return true;
223 }
224 
225 template <>
227 {
228  UT_StringHolder str_cookie;
229  if (!data.import(str_cookie))
230  return false;
231 
232  return cookie.parseCookie(str_cookie);
233 }
234 
235 #endif // __NET_NETWORKCOOKIE_H__
236 
GLuint const GLchar * name
Definition: glew.h:1814
basic_writer< back_insert_range< internal::buffer > > writer
Definition: format.h:361
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
Definition: UT_Url.h:22
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
GLsizei const GLchar *const * path
Definition: glew.h:6461
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:77
GLuint64EXT * result
Definition: glew.h:14007
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
GLsizei const GLfloat * value
Definition: glew.h:1849
GLdouble GLdouble t
Definition: glew.h:1398
static bool fromUTCString(const UT_StringRef &time_string, NET_Time &time)