xref: /aoo42x/main/svl/inc/svl/httpcook.hxx (revision 39a19a47)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SVTOOLS_HTTPCOOK_HXX
25 #define SVTOOLS_HTTPCOOK_HXX
26 
27 #include <tools/datetime.hxx>
28 #include <tools/stream.hxx>
29 #include <tools/string.hxx>
30 #include <svl/poolitem.hxx>
31 
32 /*=======================================================================
33  *
34  *=====================================================================*/
35 #define CNTHTTP_COOKIE_FLAG_SECURE            0x01
36 
37 #define CNTHTTP_COOKIE_POLICY_INTERACTIVE     0x00
38 #define CNTHTTP_COOKIE_POLICY_ACCEPTED        0x01
39 #define CNTHTTP_COOKIE_POLICY_BANNED          0x02
40 
41 #define CNTHTTP_COOKIE_DOMAIN_POLICY          0x10
42 
43 #define CNTHTTP_COOKIE_DOMAIN_ACCEPTED \
44     (CNTHTTP_COOKIE_DOMAIN_POLICY | CNTHTTP_COOKIE_POLICY_ACCEPTED)
45 #define CNTHTTP_COOKIE_DOMAIN_BANNED \
46     (CNTHTTP_COOKIE_DOMAIN_POLICY | CNTHTTP_COOKIE_POLICY_BANNED)
47 
48 /*=======================================================================
49  *
50  * CntHTTPCookie.
51  *
52  *=====================================================================*/
53 struct CntHTTPCookie
54 {
55 	String   m_aName;
56 	String   m_aValue;
57 	String   m_aDomain;
58 	String   m_aPath;
59 	DateTime m_aExpires;
60 	sal_uInt16   m_nFlags;
61 	sal_uInt16   m_nPolicy;
62 
CntHTTPCookieCntHTTPCookie63 	CntHTTPCookie (void)
64 		: m_aExpires (Date(0), Time(0)),
65 		  m_nFlags   (0),
66 		  m_nPolicy  (CNTHTTP_COOKIE_POLICY_INTERACTIVE)
67 	{}
68 
replacesCntHTTPCookie69 	sal_Bool replaces (const CntHTTPCookie& rOther) const
70 	{
71 		return ((m_aDomain == rOther.m_aDomain) &&
72 				(m_aPath   == rOther.m_aPath  ) &&
73 				(m_aName   == rOther.m_aName  )    );
74 	}
75 
operator ==CntHTTPCookie76 	sal_Bool operator== (const CntHTTPCookie& rOther) const
77 	{
78 		return ((m_aName    == rOther.m_aName   ) &&
79 				(m_aValue   == rOther.m_aValue  ) &&
80 				(m_aDomain  == rOther.m_aDomain ) &&
81 				(m_aPath    == rOther.m_aPath   ) &&
82 				(m_aExpires == rOther.m_aExpires) &&
83 				(m_nFlags   == rOther.m_nFlags  ) &&
84 				(m_nPolicy  == rOther.m_nPolicy )    );
85 	}
86 
writeCntHTTPCookie87 	void write (SvStream& rStrm) const
88 	{
89 		SfxPoolItem::writeUnicodeString(rStrm, m_aName);
90 		SfxPoolItem::writeUnicodeString(rStrm, m_aValue);
91 		SfxPoolItem::writeUnicodeString(rStrm, m_aDomain);
92 		SfxPoolItem::writeUnicodeString(rStrm, m_aPath);
93 
94 		rStrm << m_aExpires.GetDate();
95 		rStrm << m_aExpires.GetTime();
96 
97 		rStrm << m_nFlags;
98 		rStrm << m_nPolicy;
99 	}
100 
readCntHTTPCookie101 	void read (SvStream& rStrm, bool bUnicode)
102 	{
103 		SfxPoolItem::readUnicodeString(rStrm, m_aName, bUnicode);
104 		SfxPoolItem::readUnicodeString(rStrm, m_aValue, bUnicode);
105 		SfxPoolItem::readUnicodeString(rStrm, m_aDomain, bUnicode);
106 		SfxPoolItem::readUnicodeString(rStrm, m_aPath, bUnicode);
107 
108 		sal_uInt32 nValue = 0;
109 		rStrm >> nValue;
110 		m_aExpires.SetDate (nValue);
111 		rStrm >> nValue;
112 		m_aExpires.SetTime (nValue);
113 
114 		rStrm >> m_nFlags;
115 		rStrm >> m_nPolicy;
116 	}
117 };
118 
119 /*=======================================================================
120  *
121  * CntHTTPCookieRequest.
122  *
123  *=====================================================================*/
124 enum CntHTTPCookieRequestType
125 {
126 	CNTHTTP_COOKIE_REQUEST_RECV = 0,
127 	CNTHTTP_COOKIE_REQUEST_SEND
128 };
129 
130 struct CntHTTPCookieRequest
131 {
132 	const String& 			 m_rURL;
133 	List&         			 m_rCookieList;
134 	CntHTTPCookieRequestType m_eType;
135 	sal_uInt16					 m_nRet;
136 
CntHTTPCookieRequestCntHTTPCookieRequest137 	CntHTTPCookieRequest (
138 		const String& rURL,
139 		List& rCookieList,
140 		CntHTTPCookieRequestType eType)
141 		: m_rURL (rURL),
142 		  m_rCookieList (rCookieList),
143 		  m_eType(eType),
144 		  m_nRet (CNTHTTP_COOKIE_POLICY_BANNED) {}
145 };
146 
147 #endif // SVTOOLS_HTTPCOOK_HXX
148 
149