15 #include "httpCookie.h"
20 #include "httpChannel.h"
30 operator < (
const HTTPCookie &other)
const {
31 if (_domain != other._domain) {
32 return _domain < other._domain;
35 if (_path != other._path) {
39 return _path > other._path;
42 if (_name != other._name) {
43 return _name < other._name;
61 update_from(
const HTTPCookie &other) {
62 nassertv(!(other < *
this) && !(*
this < other));
64 _value = other._value;
65 _expires = other._expires;
66 _secure = other._secure;
79 parse_set_cookie(
const string &format,
const URLSpec &url) {
88 bool first_param =
true;
91 while (start < format.length() && isspace(format[start])) {
94 size_t semicolon = format.find(
';', start);
96 while (semicolon != string::npos) {
97 if (!parse_cookie_param(format.substr(start, semicolon - start),
102 start = semicolon + 1;
103 while (start < format.length() && isspace(format[start])) {
106 semicolon = format.find(
';', start);
109 if (!parse_cookie_param(format.substr(start), first_param)) {
123 matches_url(
const URLSpec &url)
const {
124 if (_domain.empty()) {
128 if (server == _domain ||
129 (
string(
".") + server) == _domain ||
130 (server.length() > _domain.length() &&
131 server.substr(server.length() - _domain.length()) == _domain &&
132 (_domain[0] ==
'.' || server[server.length() - _domain.length() - 1] ==
'.'))) {
136 if (path.length() >= _path.length() &&
137 path.substr(0, _path.length()) == _path) {
140 if (_secure && !url.
is_ssl()) {
158 output(ostream &out)
const {
159 out << _name <<
"=" << _value
160 <<
"; path=" << _path <<
"; domain=" << _domain;
163 out <<
"; expires=" << _expires;
181 parse_cookie_param(
const string ¶m,
bool first_param) {
182 size_t equals = param.find(
'=');
185 if (equals == string::npos) {
188 key = param.substr(0, equals);
189 value = param.substr(equals + 1);
197 key = HTTPChannel::downcase(key);
198 if (key ==
"expires") {
200 if (!_expires.is_valid()) {
204 }
else if (key ==
"path") {
207 }
else if (key ==
"domain") {
208 _domain = HTTPChannel::downcase(value);
212 if (!_domain.empty() && _domain[0] !=
'.') {
213 _domain = string(
".") + _domain;
216 }
else if (key ==
"secure") {
227 #endif // HAVE_OPENSSL
A container for a URL, e.g.
bool is_ssl() const
Returns true if the URL's scheme specifies an SSL-secured protocol such as https, or false otherwise...
A container for an HTTP-legal time/date indication.
string get_server() const
Returns the server name specified by the URL, if any.
string get_path() const
Returns the path specified by the URL, or "/" if no path is specified.