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  bool isFirstParty() const { return myFirstParty; }
76  const NET_Time &lastAccess() const { return myLastAccessDate; }
77  bool isPersistent() const { return myIsPersistent; }
78 
79  void setName(const UT_StringHolder &name) { myName = name; }
80  void setDomain(const UT_StringHolder &domain) { myDomain = domain; }
81  void setCreation(const NET_Time &t) { myCreationDate = t; }
82  void setExpiration(const NET_Time &t)
83  {
84  myExpirationDate = t;
85  myHasExpires = !myExpirationDate.isNull();
86  setPersistent(myHasExpires);
87  }
88  bool setExpiration(const UT_StringRef& date)
89  {
90  bool result = NET_Time::fromUTCString(date, myExpirationDate);
91 
92  myHasExpires = result && !myExpirationDate.isNull();
93  setPersistent(myHasExpires);
94  return result;
95  }
96  void setPath(const UT_StringHolder &path) { myPath = path; }
97  void setValue(const UT_StringHolder &value) { myValue = value; }
98  void setHttpOnly(bool http_only) { myHttpOnly = http_only; }
99  void setSecure(bool is_secure) { myIsSecure = is_secure; }
100  void setFirstParty(bool is_first_party) { myFirstParty = is_first_party; }
101  void setLastAccess(const NET_Time &t) { myLastAccessDate = t; }
102  void setPersistent(bool is_persistent) { myIsPersistent = is_persistent; }
103 
104  // Debug print the entire contents of the cookie
105  void dump() const;
106 private:
108 
109  UT_StringHolder myName;
110  UT_StringHolder myDomain;
111  NET_Time myCreationDate;
112  NET_Time myExpirationDate;
113  UT_StringHolder myPath;
114  UT_StringHolder myValue;
115  bool myHttpOnly;
116  bool myIsSecure;
117  bool myFirstParty;
118  bool myIsPersistent;
119  NET_Time myLastAccessDate;
120  bool myHasExpires;
121  // These variables are not used. They are only used to interface properly
122  // with QtWebEngine
123  int myPriority;
124 };
125 
127  : myName(cookie.myName),
128  myDomain(cookie.myDomain),
129  myCreationDate(cookie.myCreationDate),
130  myExpirationDate(cookie.myExpirationDate),
131  myPath(cookie.myPath),
132  myValue(cookie.myValue),
133  myHttpOnly(cookie.myHttpOnly),
134  myIsSecure(cookie.myIsSecure),
135  myFirstParty(cookie.myFirstParty),
136  myLastAccessDate(cookie.myLastAccessDate),
137  myIsPersistent(cookie.myIsPersistent),
138  myHasExpires(cookie.myHasExpires),
139  // Unused
140  myPriority(cookie.myPriority)
141 {
142 }
143 
144 inline NET_NetworkCookie &
146 {
147  myName = cookie.myName;
148  myDomain = cookie.myDomain;
149  myCreationDate = cookie.myCreationDate;
150  myExpirationDate = cookie.myExpirationDate;
151  myPath = cookie.myPath;
152  myValue = cookie.myValue;
153  myHttpOnly = cookie.myHttpOnly;
154  myIsSecure = cookie.myIsSecure;
155  myFirstParty = cookie.myFirstParty;
156  myLastAccessDate = cookie.myLastAccessDate;
157  myIsPersistent = cookie.myIsPersistent;
158  myHasExpires = cookie.myHasExpires;
159  // Unused
160  myPriority = cookie.myPriority;
161 
162  return *this;
163 }
164 
166  : myName(std::move(cookie.myName)),
167  myDomain(std::move(cookie.myDomain)),
168  myCreationDate(std::move(cookie.myCreationDate)),
169  myExpirationDate(std::move(cookie.myExpirationDate)),
170  myPath(std::move(cookie.myPath)),
171  myValue(std::move(cookie.myValue)),
172  myHttpOnly(std::move(cookie.myHttpOnly)),
173  myIsSecure(std::move(cookie.myIsSecure)),
174  myFirstParty(std::move(cookie.myFirstParty)),
175  myLastAccessDate(std::move(cookie.myLastAccessDate)),
176  myIsPersistent(std::move(cookie.myIsPersistent)),
177  myHasExpires(std::move(cookie.myHasExpires)),
178  // Unused
179  myPriority(std::move(cookie.myPriority))
180 {
181 }
182 
183 inline NET_NetworkCookie &
185 {
186  myName = std::move(cookie.myName);
187  myDomain = std::move(cookie.myDomain);
188  myCreationDate = std::move(cookie.myCreationDate);
189  myExpirationDate = std::move(cookie.myExpirationDate);
190  myPath = std::move(cookie.myPath);
191  myValue = std::move(cookie.myValue);
192  myHttpOnly = std::move(cookie.myHttpOnly);
193  myIsSecure = std::move(cookie.myIsSecure);
194  myFirstParty = std::move(cookie.myFirstParty);
195  myLastAccessDate = std::move(cookie.myLastAccessDate);
196  myIsPersistent = std::move(cookie.myIsPersistent);
197  myHasExpires = std::move(cookie.myHasExpires);
198  // Unused
199  myPriority = std::move(cookie.myPriority);
200 
201  return *this;
202 }
203 
204 inline bool
206 {
207  return myName == cookie.myName && myDomain == cookie.myDomain &&
208  myExpirationDate == cookie.myExpirationDate &&
209  myPath == cookie.myPath && myValue == cookie.myValue &&
210  myHttpOnly == cookie.myHttpOnly && myIsSecure == cookie.myIsSecure &&
211  myFirstParty == cookie.myFirstParty &&
212  myIsPersistent == cookie.myIsPersistent &&
213  myHasExpires == cookie.myHasExpires;
214 }
215 
216 inline bool
218 {
219  return !(*this == cookie);
220 }
221 
222 // Serialize
223 template<>
225 {
226  if (!cookie.isValid())
227  return false;
228 
229  writer.jsonValue(cookie.toString());
230  return true;
231 }
232 
233 template <>
235 {
236  UT_StringHolder str_cookie;
237  if (!data.import(str_cookie))
238  return false;
239 
240  return cookie.parseCookie(str_cookie);
241 }
242 
243 #endif // __NET_NETWORKCOOKIE_H__
244 
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)