Panda3D
 All Classes Functions Variables Enumerations
httpCookie.I
1 // Filename: httpCookie.I
2 // Created by: drose (26Aug04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: HTTPCookie::Constructor
18 // Access: Published
19 // Description: Constructs an empty cookie.
20 ////////////////////////////////////////////////////////////////////
21 INLINE HTTPCookie::
22 HTTPCookie() :
23  _secure(false)
24 {
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: HTTPCookie::Constructor
29 // Access: Published
30 // Description: Constructs a cookie according to the indicated
31 // string, presumably the tag of a Set-Cookie header.
32 // There is no way to detect a formatting error in the
33 // string with this constructor.
34 ////////////////////////////////////////////////////////////////////
35 INLINE HTTPCookie::
36 HTTPCookie(const string &format, const URLSpec &url) {
37  parse_set_cookie(format, url);
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: HTTPCookie::Constructor
42 // Access: Published
43 // Description: Constructs a cookie with the indicated name, path,
44 // and domain values, but no other data. This is most
45 // useful for looking up an existing cookie in the
46 // HTTPClient.
47 ////////////////////////////////////////////////////////////////////
48 INLINE HTTPCookie::
49 HTTPCookie(const string &name, const string &path, const string &domain) :
50  _name(name),
51  _path(path),
52  _domain(domain),
53  _secure(false)
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: HTTPCookie::Destructor
59 // Access: Published
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 INLINE HTTPCookie::
63 ~HTTPCookie() {
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: HTTPCookie::set_name
68 // Access: Published
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 INLINE void HTTPCookie::
72 set_name(const string &name) {
73  _name = name;
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: HTTPCookie::get_name
78 // Access: Published
79 // Description: Returns the name of the cookie. This is the key
80 // value specified by the server.
81 ////////////////////////////////////////////////////////////////////
82 INLINE const string &HTTPCookie::
83 get_name() const {
84  return _name;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: HTTPCookie::set_value
89 // Access: Published
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 INLINE void HTTPCookie::
93 set_value(const string &value) {
94  _value = value;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: HTTPCookie::get_value
99 // Access: Published
100 // Description: Returns the value of the cookie. This is the
101 // arbitrary string associated with the cookie's name,
102 // as specified by the server.
103 ////////////////////////////////////////////////////////////////////
104 INLINE const string &HTTPCookie::
105 get_value() const {
106  return _value;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: HTTPCookie::set_domain
111 // Access: Published
112 // Description:
113 ////////////////////////////////////////////////////////////////////
114 INLINE void HTTPCookie::
115 set_domain(const string &domain) {
116  _domain = domain;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: HTTPCookie::get_domain
121 // Access: Published
122 // Description:
123 ////////////////////////////////////////////////////////////////////
124 INLINE const string &HTTPCookie::
125 get_domain() const {
126  return _domain;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: HTTPCookie::set_path
131 // Access: Published
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 INLINE void HTTPCookie::
135 set_path(const string &path) {
136  _path = path;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: HTTPCookie::get_path
141 // Access: Published
142 // Description: Returns the prefix of the URL paths on the server for
143 // which this cookie will be sent.
144 ////////////////////////////////////////////////////////////////////
145 INLINE const string &HTTPCookie::
146 get_path() const {
147  return _path;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: HTTPCookie::set_expires
152 // Access: Published
153 // Description:
154 ////////////////////////////////////////////////////////////////////
155 INLINE void HTTPCookie::
156 set_expires(const HTTPDate &expires) {
157  _expires = expires;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: HTTPCookie::clear_expires
162 // Access: Published
163 // Description: Removes the expiration date on the cookie.
164 ////////////////////////////////////////////////////////////////////
165 INLINE void HTTPCookie::
166 clear_expires() {
167  _expires = HTTPDate();
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: HTTPCookie::has_expires
172 // Access: Published
173 // Description: Returns true if the cookie has an expiration date,
174 // false otherwise.
175 ////////////////////////////////////////////////////////////////////
176 INLINE bool HTTPCookie::
177 has_expires() const {
178  return _expires.is_valid();
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: HTTPCookie::get_expires
183 // Access: Published
184 // Description: Returns the expiration date of the cookie if it is
185 // set, or an invalid date if it is not.
186 ////////////////////////////////////////////////////////////////////
187 INLINE HTTPDate HTTPCookie::
188 get_expires() const {
189  return _expires;
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: HTTPCookie::set_secure
194 // Access: Published
195 // Description:
196 ////////////////////////////////////////////////////////////////////
197 INLINE void HTTPCookie::
198 set_secure(bool secure) {
199  _secure = secure;
200 }
201 
202 ////////////////////////////////////////////////////////////////////
203 // Function: HTTPCookie::get_secure
204 // Access: Published
205 // Description: Returns true if the server has indicated this is a
206 // "secure" cookie which should only be sent over an
207 // HTTPS channel.
208 ////////////////////////////////////////////////////////////////////
209 INLINE bool HTTPCookie::
210 get_secure() const {
211  return _secure;
212 }
213 
214 ////////////////////////////////////////////////////////////////////
215 // Function: HTTPCookie::is_expired
216 // Access: Published
217 // Description: Returns true if the cookie's expiration date is
218 // before the indicated date, false otherwise.
219 ////////////////////////////////////////////////////////////////////
220 INLINE bool HTTPCookie::
221 is_expired(const HTTPDate &now) const {
222  return _expires.is_valid() && _expires < now;
223 }
224 
225 INLINE ostream &operator << (ostream &out, const HTTPCookie &cookie) {
226  cookie.output(out);
227  return out;
228 }
A container for a URL, e.g.
Definition: urlSpec.h:29
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:30