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 
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  bool isEquivalent(const NET_NetworkCookie &cookie) const
58  {
59  return myName == cookie.myName && myDomain == cookie.myDomain
60  && myPath == cookie.myPath;
61  }
62 
63  bool isValid() const;
64  bool hasExpired() const;
65 
66  void normalize(const UT_Url &url);
67 
68  bool parseCookie(const UT_StringRef& cookie);
69  static void parseCookies(const UT_StringArray &cookie_string,
70  NET_CookieList &cookies);
71 
72  const UT_StringHolder &name() const { return myName; }
73  const UT_StringHolder &domain() const { return myDomain; }
74  const NET_Time &creation() const { return myCreationDate; }
75  const NET_Time &expiration() const { return myExpirationDate; }
76  const UT_StringHolder &path() const { return myPath; }
77  const UT_StringHolder &value() const { return myValue; }
78  bool isHttpOnly() const { return myHttpOnly; }
79  bool isSecure() const { return myIsSecure; }
80  const NET_Time &lastAccess() const { return myLastAccessDate; }
81  bool isPersistent() const { return myIsPersistent; }
82 
83  void setName(const UT_StringHolder &name) { myName = name; }
84  void setDomain(const UT_StringHolder &domain) { myDomain = domain; }
85  void setCreation(const NET_Time &t) { myCreationDate = t; }
86  void setExpiration(const NET_Time &t)
87  {
88  myExpirationDate = t;
89  myHasExpires = !myExpirationDate.isNull();
90  setPersistent(myHasExpires);
91  }
92  bool setExpiration(const UT_StringRef& date)
93  {
94  bool result = NET_Time::fromUTCString(date, myExpirationDate);
95 
96  myHasExpires = result && !myExpirationDate.isNull();
97  setPersistent(myHasExpires);
98  return result;
99  }
100  void setPath(const UT_StringHolder &path) { myPath = path; }
101  void setValue(const UT_StringHolder &value) { myValue = value; }
102  void setHttpOnly(bool http_only) { myHttpOnly = http_only; }
103  void setSecure(bool is_secure) { myIsSecure = is_secure; }
104  void setLastAccess(const NET_Time &t) { myLastAccessDate = t; }
105  void setPersistent(bool is_persistent) { myIsPersistent = is_persistent; }
106 
107  // Debug print the entire contents of the cookie
108  void dump() const;
109 private:
111 
112  UT_StringHolder myName;
113  UT_StringHolder myDomain;
114  NET_Time myCreationDate;
115  NET_Time myExpirationDate;
116  UT_StringHolder myPath;
117  UT_StringHolder myValue;
118  bool myHttpOnly;
119  bool myIsSecure;
120  bool myIsPersistent;
121  NET_Time myLastAccessDate;
122  bool myHasExpires;
123  // These variables are not used. They are only used to interface properly
124  // with QtWebEngine
125  int myPriority;
126 };
127 
129  : myName(cookie.myName),
130  myDomain(cookie.myDomain),
131  myCreationDate(cookie.myCreationDate),
132  myExpirationDate(cookie.myExpirationDate),
133  myPath(cookie.myPath),
134  myValue(cookie.myValue),
135  myHttpOnly(cookie.myHttpOnly),
136  myIsSecure(cookie.myIsSecure),
137  myLastAccessDate(cookie.myLastAccessDate),
138  myIsPersistent(cookie.myIsPersistent),
139  myHasExpires(cookie.myHasExpires),
140  // Unused
141  myPriority(cookie.myPriority)
142 {
143 }
144 
145 inline NET_NetworkCookie &
147 {
148  myName = cookie.myName;
149  myDomain = cookie.myDomain;
150  myCreationDate = cookie.myCreationDate;
151  myExpirationDate = cookie.myExpirationDate;
152  myPath = cookie.myPath;
153  myValue = cookie.myValue;
154  myHttpOnly = cookie.myHttpOnly;
155  myIsSecure = cookie.myIsSecure;
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  myLastAccessDate(std::move(cookie.myLastAccessDate)),
175  myIsPersistent(std::move(cookie.myIsPersistent)),
176  myHasExpires(std::move(cookie.myHasExpires)),
177  // Unused
178  myPriority(std::move(cookie.myPriority))
179 {
180 }
181 
182 inline NET_NetworkCookie &
184 {
185  myName = std::move(cookie.myName);
186  myDomain = std::move(cookie.myDomain);
187  myCreationDate = std::move(cookie.myCreationDate);
188  myExpirationDate = std::move(cookie.myExpirationDate);
189  myPath = std::move(cookie.myPath);
190  myValue = std::move(cookie.myValue);
191  myHttpOnly = std::move(cookie.myHttpOnly);
192  myIsSecure = std::move(cookie.myIsSecure);
193  myLastAccessDate = std::move(cookie.myLastAccessDate);
194  myIsPersistent = std::move(cookie.myIsPersistent);
195  myHasExpires = std::move(cookie.myHasExpires);
196  // Unused
197  myPriority = std::move(cookie.myPriority);
198 
199  return *this;
200 }
201 
202 inline bool
204 {
205  return myName == cookie.myName && myDomain == cookie.myDomain &&
206  myExpirationDate == cookie.myExpirationDate &&
207  myPath == cookie.myPath && myValue == cookie.myValue &&
208  myHttpOnly == cookie.myHttpOnly && myIsSecure == cookie.myIsSecure &&
209  myIsPersistent == cookie.myIsPersistent &&
210  myHasExpires == cookie.myHasExpires;
211 }
212 
213 inline bool
215 {
216  return !(*this == cookie);
217 }
218 
219 // Serialize
220 template<>
222 {
223  if (!cookie.isValid())
224  return false;
225 
226  writer.jsonValue(cookie.toString());
227  return true;
228 }
229 
230 template <>
232 {
233  UT_StringHolder str_cookie;
234  if (!data.import(str_cookie))
235  return false;
236 
237  return cookie.parseCookie(str_cookie);
238 }
239 
240 #endif // __NET_NETWORKCOOKIE_H__
241 
GLboolean * data
Definition: glcorearb.h:131
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
**But if you need a result
Definition: thread.h:613
#define NET_API
Definition: NET_API.h:9
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
Definition: UT_Url.h:22
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
Definition: core.h:1131
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
static bool fromUTCString(const UT_StringRef &time_string, NET_Time &time)
Definition: format.h:895
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept