1 //
2 // HtCookieJar.h
3 //
4 // HtCookieJar: Abstract Class for storing/retrieving cookies
5 //
6 // by Robert La Ferla.  Started 12/9/2000.
7 // Reviewed by G.Bartolini - since 24 Feb 2001
8 //
9 ////////////////////////////////////////////////////////////
10 //
11 // The HtCookieJar class stores/retrieves cookies.
12 // It's an abstract class though, which has to be the interface
13 // for HtHTTP class.
14 //
15 // The class has only 2 access point from the outside:
16 // - a method for cookies insertion (AddCookie());
17 // - a method for getting the HTTP request for cookies
18 //    (SetHTTPRequest_CookiesString).
19 //
20 // See "PERSISTENT CLIENT STATE HTTP COOKIES" Specification
21 // at http://www.netscape.com/newsref/std/cookie_spec.html
22 // Modified according to RFC2109 (max age and version attributes)
23 //
24 ///////
25 //
26 // Part of the ht://Dig package   <http://www.htdig.org/>
27 // Part of the ht://Check package   <http://htcheck.sourceforge.net/>
28 // Copyright (c) 2001-2004 The ht://Dig Group
29 // For copyright details, see the file COPYING in your distribution
30 // or the GNU Library General Public License (LGPL) version 2 or later
31 // <http://www.gnu.org/copyleft/lgpl.html>
32 //
33 // $Id: HtCookieJar.h,v 1.6 2004/05/28 13:15:23 lha Exp $
34 //
35 
36 #ifndef _HTCOOKIE_JAR_H
37 #define _HTCOOKIE_JAR_H
38 
39 #ifdef HAVE_CONFIG_H
40 #include "htconfig.h"
41 #endif
42 
43 #include "Object.h"
44 #include "htString.h"
45 #include "HtCookie.h"
46 #include "URL.h"
47 
48 // for ShowSummary()
49 #ifdef HAVE_STD
50 #include <iostream>
51 #ifdef HAVE_NAMESPACES
52 using namespace std;
53 #endif
54 #else
55 #include <iostream.h>
56 #endif /* HAVE_STD */
57 
58 
59 class HtCookieJar : public Object
60 {
61 
62    public:
63 
64    ///////
65       //    Construction/Destruction
66    ///////
67 
HtCookieJar()68       HtCookieJar() {};    // empty
~HtCookieJar()69       virtual ~HtCookieJar() {};   // empty
70 
71    ///////
72       //    Interface methods
73    ///////
74 
75       // This method allow the insertion of a cookie
76       // into the jar.
77       virtual int AddCookie(const String &CookieString,
78       	 const URL &url) = 0;
79 
80       // Set the request string to be sent to an HTTP server
81       // for cookies. It manages all the process regarding
82       // domains and subdomains.
83       virtual int SetHTTPRequest_CookiesString(const URL &_url,
84       	 String &RequestString) = 0;
85 
86       // Get the next cookie
87       virtual const HtCookie* NextCookie() = 0;
88 
89       // Reset the iterator
90       virtual void ResetIterator() = 0;
91 
92       // Get the minimum number of periods from a specified domain
93       // returns 0 if not valid
94       virtual int GetDomainMinNumberOfPeriods(const String& domain) const;
95 
96       // Set its debug level and HtCookie class'
SetDebugLevel(int d)97       static void SetDebugLevel (int d)
98       {
99       	 debug=d;  // internal one
100       	 HtCookie::SetDebugLevel(d);  // HtCookie's debug level
101       }
102 
103       // Show summary (abstract)
104       virtual ostream &ShowSummary (ostream &out) = 0;
105 
106    protected:
107 
108    ///////
109       //    Protected attributes
110    ///////
111 
112       // Writes the HTTP request line given a cookie
113       virtual int WriteCookieHTTPRequest(const HtCookie &Cookie,
114       	 String &RequestString, const int &NumCookies);
115 
116       // Print debug info
117       virtual void printDebug() = 0;
118 
119       ///////
120          //    Debug level
121       ///////
122 
123       static int debug;
124 
125 };
126 
127 #endif
128 
129