blob: 934600d86ddf4d33f9552c8dfed7eb1b3a2189a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
//
// HtCookie.h
//
// HtCookie: Class for cookies
//
// by Robert La Ferla. Started 12/5/2000.
// Reviewed by G.Bartolini - since 24 Feb 2001
// Cookies input file by G.Bartolini - since 27 Jan 2003
//
////////////////////////////////////////////////////////////
//
// The HtCookie class represents a single HTTP cookie.
//
// See "PERSISTENT CLIENT STATE HTTP COOKIES" Specification
// at http://www.netscape.com/newsref/std/cookie_spec.html
// Modified according to RFC2109 (max age and version attributes)
//
// This class also manages the creation of a cookie from a line
// of a cookie file format, which is a text file as proposed by Netscape;
// each line contains a name-value pair for a cookie.
// Fields within a single line are separated by the 'tab' character;
//
///////
//
// Part of the ht://Dig package <http://www.htdig.org/>
// Part of the ht://Check package <http://htcheck.sourceforge.net/>
// Copyright (c) 2001-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: HtCookie.h,v 1.10 2004/05/28 13:15:23 lha Exp $
//
#ifndef _HTCOOKIE_H
#define _HTCOOKIE_H
#ifdef HAVE_CONFIG_H
#include "htconfig.h"
#endif
#include "Object.h"
#include "htString.h"
#include "HtDateTime.h"
class HtCookie : public Object
{
public:
///////
// Construction/Destruction
///////
HtCookie(); // default constructor
HtCookie(const String &setCookieLine, const String& aURL);
HtCookie(const String &aName, const String &aValue, const String& aURL);
HtCookie(const String &line); // From a line of cookie file
HtCookie(const HtCookie& rhs); // default constructor
~HtCookie(); // Destructor
///////
// Public Interface
///////
void SetName(const String &aName) { name = aName; }
void SetValue(const String &aValue) { value = aValue; }
void SetPath(const String &aPath) { path = aPath; }
void SetDomain(const String &aDomain) { domain = aDomain; }
void SetExpires(const HtDateTime *aDateTime);
void SetIsSecure(const bool flag) { isSecure = flag; }
void SetIsDomainValid(const bool flag) { isDomainValid = flag; }
void SetSrcURL(const String &aURL) { srcURL = aURL; }
void SetMaxAge(const int ma) { max_age = ma; }
void SetVersion(const int vs) { rfc_version = vs; }
const String &GetName() const { return name; }
const String &GetValue()const { return value; }
const String &GetPath()const { return path; }
const String &GetDomain()const { return domain; }
const HtDateTime *GetExpires() const { return expires; }
const bool getIsSecure() const { return isSecure; }
const bool getIsDomainValid() const { return isDomainValid; }
const String &GetSrcURL()const { return srcURL; }
const int GetMaxAge()const { return max_age; }
const HtDateTime &GetIssueTime() const { return issue_time; }
const int GetVersion() const { return rfc_version; }
// Print debug info
#ifndef _MSC_VER /* _WIN32 */
virtual ostream &printDebug(ostream &out = std::cout);
#else
virtual ostream &printDebug(ostream &out = cout);
#endif
// Set the debug level
static void SetDebugLevel (int d) { debug=d;}
// Copy operator overload
const HtCookie &operator = (const HtCookie &rhs);
protected:
///////
// Date formats enumeration
///////
enum DateFormat
{
DateFormat_RFC1123,
DateFormat_RFC850,
DateFormat_AscTime,
DateFormat_NotRecognized
};
///////
// Protected methods
///////
char * stripAllWhitespace(const char * str);
int SetDate(const char * datestring, HtDateTime &dt);
DateFormat RecognizeDateFormat(const char * datestring);
String name;
String value;
String path;
String domain;
HtDateTime * expires;
bool isSecure;
bool isDomainValid;
String srcURL;
HtDateTime issue_time; // When the cookie has been created
int max_age; // rfc2109: lifetime of the cookie, in seconds
int rfc_version;
///////
// Debug level
///////
static int debug;
};
#endif
|