xref: /aoo42x/main/svl/inc/svl/httpcook.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SVTOOLS_HTTPCOOK_HXX
29 #define SVTOOLS_HTTPCOOK_HXX
30 
31 #include <tools/datetime.hxx>
32 #include <tools/stream.hxx>
33 #include <tools/string.hxx>
34 #include <svl/poolitem.hxx>
35 
36 /*=======================================================================
37  *
38  *=====================================================================*/
39 #define CNTHTTP_COOKIE_FLAG_SECURE            0x01
40 
41 #define CNTHTTP_COOKIE_POLICY_INTERACTIVE     0x00
42 #define CNTHTTP_COOKIE_POLICY_ACCEPTED        0x01
43 #define CNTHTTP_COOKIE_POLICY_BANNED          0x02
44 
45 #define CNTHTTP_COOKIE_DOMAIN_POLICY          0x10
46 
47 #define CNTHTTP_COOKIE_DOMAIN_ACCEPTED \
48     (CNTHTTP_COOKIE_DOMAIN_POLICY | CNTHTTP_COOKIE_POLICY_ACCEPTED)
49 #define CNTHTTP_COOKIE_DOMAIN_BANNED \
50     (CNTHTTP_COOKIE_DOMAIN_POLICY | CNTHTTP_COOKIE_POLICY_BANNED)
51 
52 /*=======================================================================
53  *
54  * CntHTTPCookie.
55  *
56  *=====================================================================*/
57 struct CntHTTPCookie
58 {
59 	String   m_aName;
60 	String   m_aValue;
61 	String   m_aDomain;
62 	String   m_aPath;
63 	DateTime m_aExpires;
64 	sal_uInt16   m_nFlags;
65 	sal_uInt16   m_nPolicy;
66 
67 	CntHTTPCookie (void)
68 		: m_aExpires (Date(0), Time(0)),
69 		  m_nFlags   (0),
70 		  m_nPolicy  (CNTHTTP_COOKIE_POLICY_INTERACTIVE)
71 	{}
72 
73 	sal_Bool replaces (const CntHTTPCookie& rOther) const
74 	{
75 		return ((m_aDomain == rOther.m_aDomain) &&
76 				(m_aPath   == rOther.m_aPath  ) &&
77 				(m_aName   == rOther.m_aName  )    );
78 	}
79 
80 	sal_Bool operator== (const CntHTTPCookie& rOther) const
81 	{
82 		return ((m_aName    == rOther.m_aName   ) &&
83 				(m_aValue   == rOther.m_aValue  ) &&
84 				(m_aDomain  == rOther.m_aDomain ) &&
85 				(m_aPath    == rOther.m_aPath   ) &&
86 				(m_aExpires == rOther.m_aExpires) &&
87 				(m_nFlags   == rOther.m_nFlags  ) &&
88 				(m_nPolicy  == rOther.m_nPolicy )    );
89 	}
90 
91 	void write (SvStream& rStrm) const
92 	{
93 		SfxPoolItem::writeUnicodeString(rStrm, m_aName);
94 		SfxPoolItem::writeUnicodeString(rStrm, m_aValue);
95 		SfxPoolItem::writeUnicodeString(rStrm, m_aDomain);
96 		SfxPoolItem::writeUnicodeString(rStrm, m_aPath);
97 
98 		rStrm << m_aExpires.GetDate();
99 		rStrm << m_aExpires.GetTime();
100 
101 		rStrm << m_nFlags;
102 		rStrm << m_nPolicy;
103 	}
104 
105 	void read (SvStream& rStrm, bool bUnicode)
106 	{
107 		SfxPoolItem::readUnicodeString(rStrm, m_aName, bUnicode);
108 		SfxPoolItem::readUnicodeString(rStrm, m_aValue, bUnicode);
109 		SfxPoolItem::readUnicodeString(rStrm, m_aDomain, bUnicode);
110 		SfxPoolItem::readUnicodeString(rStrm, m_aPath, bUnicode);
111 
112 		sal_uInt32 nValue = 0;
113 		rStrm >> nValue;
114 		m_aExpires.SetDate (nValue);
115 		rStrm >> nValue;
116 		m_aExpires.SetTime (nValue);
117 
118 		rStrm >> m_nFlags;
119 		rStrm >> m_nPolicy;
120 	}
121 };
122 
123 /*=======================================================================
124  *
125  * CntHTTPCookieRequest.
126  *
127  *=====================================================================*/
128 enum CntHTTPCookieRequestType
129 {
130 	CNTHTTP_COOKIE_REQUEST_RECV = 0,
131 	CNTHTTP_COOKIE_REQUEST_SEND
132 };
133 
134 struct CntHTTPCookieRequest
135 {
136 	const String& 			 m_rURL;
137 	List&         			 m_rCookieList;
138 	CntHTTPCookieRequestType m_eType;
139 	sal_uInt16					 m_nRet;
140 
141 	CntHTTPCookieRequest (
142 		const String& rURL,
143 		List& rCookieList,
144 		CntHTTPCookieRequestType eType)
145 		: m_rURL (rURL),
146 		  m_rCookieList (rCookieList),
147 		  m_eType(eType),
148 		  m_nRet (CNTHTTP_COOKIE_POLICY_BANNED) {}
149 };
150 
151 #endif // SVTOOLS_HTTPCOOK_HXX
152 
153