|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of the client interface of the cookie server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // System includes |
|
21 #include <e32std.h> |
|
22 // #include <thttphdrval.h> |
|
23 |
|
24 // User includes |
|
25 #include "cookie.h" |
|
26 #include "cookieIPC.h" |
|
27 #include "CookieCommonConstants.h" |
|
28 #include "cookielogger.h" |
|
29 #include "cookiemanagerclient.h" |
|
30 #include "CookieManagerServer.h" |
|
31 #include "CookieManagerStart.h" |
|
32 #include "CookieServerDef.h" |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 // TBD : do we have to set limits to the number of cookies at all? |
|
37 // Possible answer : as we store cookies in an RPointerArray that has a |
|
38 // restriction on the number of elements (max. 640 can be stored in an RArray |
|
39 // or RPointerArray), we have to bother with it. |
|
40 // TODO : |
|
41 // - change this value |
|
42 // - use always when appropriate |
|
43 // - share in a common header file |
|
44 // const TInt KMaxNumberOfCookies = 256; |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // RCookieManager::RCookieManager |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C RCookieManager::RCookieManager( RStringPool aStringPool ) |
|
51 : iStringPool( aStringPool ), iCookiePacker( iStringPool ) |
|
52 { |
|
53 CLOG(( EClient, 0, _L(" ") )); |
|
54 CLOG(( EClient, 0, _L("*****************") )); |
|
55 CLOG(( EClient, 0, _L("RCookieManager::RCookieManager") )); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // RCookieManager::ClearCookies |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C TInt RCookieManager::ClearCookies( TInt& aDeletedCookies ) |
|
63 { |
|
64 CLOG(( EClient, 0, _L("-> RCookieManager::ClearCookies") )); |
|
65 |
|
66 TPckg<TInt> pkgCount( aDeletedCookies ); |
|
67 TInt ret( SendReceive( EClearAllCookies, TIpcArgs( &pkgCount ) ) ); |
|
68 |
|
69 CLOG(( EClient, 0, |
|
70 _L("<- RCookieManager::ClearCookies cleared %d cookies, errcode%d"), |
|
71 aDeletedCookies, ret ) ); |
|
72 |
|
73 return ret; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // RCookieManager::Connect |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C TInt RCookieManager::Connect() |
|
81 { |
|
82 CLOG( ( EClientConnect, 0, _L( "-> RCookieManager::Connect" ) ) ); |
|
83 |
|
84 TInt error = KErrNone; |
|
85 RProcess server; |
|
86 error = server.Create( KCookieServerExe, TPtr( NULL, 0 ), |
|
87 TUidType( KNullUid, KNullUid, KCookieServerExeUid ) ); |
|
88 CLOG( ( EClientConnect, 0, |
|
89 _L( "RCookieManager::Connect after process creation, err %d" ), |
|
90 error ) ); |
|
91 |
|
92 if( !error ) |
|
93 { |
|
94 TRequestStatus status; |
|
95 server.Rendezvous( status ); |
|
96 if( status != KRequestPending ) |
|
97 { |
|
98 CLOG( (EClientConnect, 0, _L("RCookieManager::Connect pending status error.") ) ); |
|
99 server.Kill( 0 ); |
|
100 } |
|
101 else |
|
102 { |
|
103 CLOG( (EClientConnect, 0, _L("RCookieManager::Connect pending resume server.") ) ); |
|
104 server.Resume( ); |
|
105 } |
|
106 User::WaitForRequest( status ); |
|
107 error = ( server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int(); |
|
108 server.Close(); |
|
109 } |
|
110 CLOG( ( EClientConnect, 0, _L( "Creating server session" ) ) ); |
|
111 error = CreateSession( KCookieServerName, Version() ); |
|
112 CLOG( ( EClientConnect, 0, _L( "Server session created, errcode%d" ), error ) ); |
|
113 |
|
114 CLOG( ( EClientConnect, 0, _L( "<- RCookieManager::Connect" ) ) ); |
|
115 return error; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // RCookieManager::GetCookies |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 TInt RCookieManager::DoGetCookies( TDes8& aBuffer ) const |
|
123 { |
|
124 return SendReceive( EGetCookies, TIpcArgs( &aBuffer ) ); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // RCookieManager::GetCookieSize |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 TInt RCookieManager::DoGetCookieSize( const TDesC8& aRequestUri, |
|
132 TPckg<TInt>& aPkgSize ) const |
|
133 { |
|
134 return SendReceive( EGetCookieSize, TIpcArgs( aRequestUri.Length(), |
|
135 &aRequestUri, &aPkgSize ) ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // RCookieManager::DoStoreCookie |
|
140 // --------------------------------------------------------- |
|
141 // |
|
142 TInt RCookieManager::DoStoreCookie( const TDesC8& aPackedCookie, |
|
143 const TDesC8& aUri ) const |
|
144 { |
|
145 return SendReceive( EStoreCookie, TIpcArgs( aPackedCookie.Length(), |
|
146 &aPackedCookie, aUri.Length(), &aUri ) ); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------- |
|
150 // RCookieManager::GetCookiesL |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void RCookieManager::GetCookiesL( const TDesC8& aUri, |
|
154 RPointerArray<CCookie>& aCookies, |
|
155 TBool& aCookie2Reqd ) |
|
156 { |
|
157 CLOG( ( EClient, 0, _L( "-> RCookieManager::GetCookiesL" ) ) ); |
|
158 |
|
159 aCookie2Reqd = EFalse; |
|
160 |
|
161 TInt size = 0; |
|
162 TPckg<TInt> pkgSize( size ); |
|
163 User::LeaveIfError( DoGetCookieSize( aUri, pkgSize ) ); |
|
164 |
|
165 if ( size ) |
|
166 { |
|
167 HBufC8* buf = HBufC8::NewLC( size ); |
|
168 |
|
169 TPtr8 des( buf->Des() ); |
|
170 User::LeaveIfError( DoGetCookies( des ) ); |
|
171 |
|
172 // it seems this is the only place where we cannot avoid leaving |
|
173 // ==> we allocate memory for cookies when we fill up the cookie array. |
|
174 iCookiePacker.UnpackCookiesFromBufferL( *buf, aCookies ); |
|
175 |
|
176 TInt count = aCookies.Count(); |
|
177 TInt i = 0; |
|
178 TBool anyCookie2( EFalse ); |
|
179 TBool anyUnknownVersion( EFalse ); |
|
180 for ( ; i < count; i++ ) |
|
181 { |
|
182 if ( aCookies[i]->FromCookie2() ) |
|
183 { |
|
184 anyCookie2 = ETrue; |
|
185 anyUnknownVersion |= aCookies[i]->IsUnknownVersion(); |
|
186 } |
|
187 } |
|
188 |
|
189 // if there were no new-style cookies or a new version info is detected |
|
190 // then we have to send an extra cookie header indicating that we're |
|
191 // able to process new-style cookies |
|
192 if ( !anyCookie2 || anyUnknownVersion ) |
|
193 { |
|
194 aCookie2Reqd = ETrue; |
|
195 } |
|
196 |
|
197 CleanupStack::PopAndDestroy(); // buf |
|
198 } |
|
199 |
|
200 CLOG( ( EClient, 0, _L( "<- RCookieManager::GetCookiesL" ) ) ); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // RCookieManager::StoreCookie |
|
205 // --------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C TInt RCookieManager::StoreCookie( const CCookie& aCookie, |
|
208 const TUriC8& aUri ) |
|
209 { |
|
210 CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreCookie" ) ) ); |
|
211 |
|
212 TInt err; |
|
213 |
|
214 TInt cookieSize = aCookie.Size( EFalse ); |
|
215 HBufC8* buf = HBufC8::New( cookieSize ); |
|
216 if ( buf ) |
|
217 { |
|
218 CLOG( ( EClient, 0, |
|
219 _L( "RCookieManager::StoreCookie, cookie size:%d" ), |
|
220 cookieSize ) ); |
|
221 |
|
222 TPtr8 bufDes( buf->Des() ); |
|
223 err = iCookiePacker.CliPackCookie( bufDes, aCookie ); |
|
224 if ( !err ) |
|
225 { |
|
226 err = DoStoreCookie( *buf, aUri.UriDes() ); |
|
227 } |
|
228 |
|
229 delete buf; |
|
230 } |
|
231 else |
|
232 { |
|
233 err = KErrNoMemory; |
|
234 } |
|
235 |
|
236 CLOG( ( EClient, 0, |
|
237 _L( "<- RCookieManager::StoreCookie errcode%d" ), err ) ); |
|
238 |
|
239 return err; |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------- |
|
243 // RCookieManager::Version |
|
244 // --------------------------------------------------------- |
|
245 // |
|
246 TVersion RCookieManager::Version() const |
|
247 { |
|
248 CLOG(( EClient, 0, _L("<->RCookieManager::Version") )); |
|
249 |
|
250 return( TVersion( KCookieServerMajorVersionNumber, |
|
251 KCookieServerMinorVersionNumber, |
|
252 KCookieServerBuildVersionNumber )); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------- |
|
256 // RCookieManager::SetAppUidL |
|
257 // --------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C TInt RCookieManager::SetAppUidL( const TUint32& aAppUid ) |
|
260 { |
|
261 CLOG(( EClient, 0, _L("->RCookieManager::SetAppUid") )); |
|
262 HBufC* buf = HBufC::NewLC(128); |
|
263 TPtr ptr(buf->Des()); |
|
264 ptr.AppendNum(aAppUid,EHex); |
|
265 TInt error = SendReceive(ESetAppUid,TIpcArgs(ptr.Length(),&ptr)); |
|
266 CleanupStack::PopAndDestroy(); |
|
267 CLOG(( EClient, 0, _L("<-RCookieManager::SetAppUid") )); |
|
268 return error; |
|
269 } |
|
270 // End of file |