|
1 /* |
|
2 * Copyright (c) 2006 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 CNcdServerDetails |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 |
|
21 #include "ncdserverdetailsimpl.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncd_cp_cookieimpl.h" |
|
24 #include "ncddatabasestorage.h" |
|
25 #include "ncdstorageitem.h" |
|
26 #include "catalogsutils.h" |
|
27 #include "ncd_cp_cookie.h" |
|
28 #include "ncd_cp_cookieimpl.h" |
|
29 #include "catalogsconstants.h" |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CNcdServerDetails |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // NewL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CNcdServerDetails* |
|
41 CNcdServerDetails::NewLC( |
|
42 const TDesC& aServerUri, const TDesC& aNamespace ) |
|
43 { |
|
44 CNcdServerDetails* self = new( ELeave ) CNcdServerDetails(); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aServerUri, aNamespace ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // NewL |
|
52 // --------------------------------------------------------------------------- |
|
53 CNcdServerDetails* CNcdServerDetails::NewL( RReadStream& aStream ) |
|
54 { |
|
55 CNcdServerDetails* self = new( ELeave ) CNcdServerDetails(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aStream ); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Destructor |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CNcdServerDetails::~CNcdServerDetails() |
|
68 { |
|
69 delete iServerUri; |
|
70 delete iNamespace; |
|
71 delete iCapabilities; |
|
72 iCookies.ResetAndDestroy(); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Externalizes the object |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CNcdServerDetails::ExternalizeL( RWriteStream& aStream ) const |
|
80 { |
|
81 DLTRACEIN(( _L("ServerURI: %S, Namespace: %S"), iServerUri, |
|
82 iNamespace )); |
|
83 ExternalizeDesL( *iServerUri, aStream ); |
|
84 ExternalizeDesL( *iNamespace, aStream ); |
|
85 |
|
86 TInt count = iCapabilities->MdcaCount(); |
|
87 DLTRACE(("Externalizing %d capabilities", count )); |
|
88 aStream.WriteInt32L( count ); |
|
89 for ( TInt i = 0 ; i < count; i++ ) |
|
90 { |
|
91 DLTRACE(( _L("Cap: %S"), &iCapabilities->MdcaPoint( i ) )); |
|
92 ExternalizeDesL( iCapabilities->MdcaPoint( i ), aStream ); |
|
93 } |
|
94 |
|
95 count = iCookies.Count(); |
|
96 DLTRACE(("Externalizing %d cookies", count )); |
|
97 aStream.WriteInt32L( count ); |
|
98 for ( TInt i = 0; i < count; ++i ) |
|
99 { |
|
100 iCookies[i]->ExternalizeL( aStream ); |
|
101 } |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // Adds a new capability |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CNcdServerDetails::AddCapabilityL( |
|
109 const TDesC& aCapability ) |
|
110 { |
|
111 DLTRACEIN(( _L("Server cap: %S to server: %S"), &aCapability, |
|
112 iServerUri )); |
|
113 |
|
114 iCapabilities->AppendL( aCapability ); |
|
115 } |
|
116 |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Clears capabilities |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CNcdServerDetails::ClearCapabilitiesL() |
|
123 { |
|
124 DLTRACEIN(("")); |
|
125 delete iCapabilities; |
|
126 iCapabilities = NULL; |
|
127 iCapabilities = new( ELeave ) CDesCArrayFlat( KListGranularity ); |
|
128 DLTRACEOUT(("Capabilities cleared")); |
|
129 } |
|
130 |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // Check if the server supports the given capability |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 TBool CNcdServerDetails::IsCapabilitySupported( |
|
137 const TDesC& aCapability ) const |
|
138 { |
|
139 TInt pos = 0; |
|
140 return ( iCapabilities->Find( aCapability, pos, ECmpNormal ) == 0 ); |
|
141 } |
|
142 |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // Server URI getter |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 const TDesC& CNcdServerDetails::ServerUri() const |
|
149 { |
|
150 DASSERT( iServerUri ); |
|
151 return *iServerUri; |
|
152 } |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Namespace getter |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 const TDesC& CNcdServerDetails::Namespace() const |
|
160 { |
|
161 DASSERT( iNamespace ); |
|
162 return *iNamespace; |
|
163 } |
|
164 |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // AddCookieL |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CNcdServerDetails::AddCookieL( |
|
171 const MNcdConfigurationProtocolCookie& aCookie, |
|
172 const TDesC8& aSim ) |
|
173 { |
|
174 DLTRACEIN(( _L("Key: %S, type: %S"), &aCookie.Key(), &aCookie.Type() )); |
|
175 TInt index = FindCookie( aCookie ); |
|
176 |
|
177 if ( aCookie.Type() == NcdConfigurationProtocolCookieTypes::KRemove ) |
|
178 { |
|
179 DLINFO(("Removing cookie")); |
|
180 if ( index != KErrNotFound ) |
|
181 { |
|
182 delete iCookies[index]; |
|
183 iCookies.Remove( index ); |
|
184 } |
|
185 return; |
|
186 } |
|
187 |
|
188 CNcdConfigurationProtocolCookie* cookie = |
|
189 CNcdConfigurationProtocolCookie::NewLC( aCookie ); |
|
190 |
|
191 |
|
192 // Set SIM identification |
|
193 AssignDesL( cookie->iSim, aSim ); |
|
194 |
|
195 if ( index == KErrNotFound ) |
|
196 { |
|
197 DLINFO(("Adding a new cookie")); |
|
198 iCookies.AppendL( cookie ); |
|
199 } |
|
200 else |
|
201 { |
|
202 DLINFO(("Replacing an existing cookie")); |
|
203 delete iCookies[index]; |
|
204 iCookies[index] = cookie; |
|
205 } |
|
206 CleanupStack::Pop( cookie ); |
|
207 |
|
208 // Convert expiration delta to expiration time and put it to the cookie |
|
209 if ( cookie->ExpirationDelta() ) |
|
210 { |
|
211 DLINFO(("Expiration delta: %d", cookie->ExpirationDelta() )); |
|
212 TTimeIntervalMinutes delta( cookie->ExpirationDelta() ); |
|
213 TTime currentTime; |
|
214 currentTime.HomeTime(); |
|
215 currentTime += delta; |
|
216 cookie->iExpirationTime = currentTime; |
|
217 } |
|
218 } |
|
219 |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // CookiesL |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 RPointerArray<const MNcdConfigurationProtocolCookie> |
|
226 CNcdServerDetails::CookiesL( |
|
227 const TDesC8& aSim ) const |
|
228 { |
|
229 DLTRACEIN(("")); |
|
230 RPointerArray<const MNcdConfigurationProtocolCookie> array; |
|
231 CleanupClosePushL( array ); |
|
232 for ( TInt i = 0; i < iCookies.Count(); ++i ) |
|
233 { |
|
234 if ( iCookies[i]->Scope() != |
|
235 NcdConfigurationProtocolCookieScopes::KSim || |
|
236 iCookies[i]->Sim() == aSim ) |
|
237 { |
|
238 DLTRACE(("Found a suitable cookie")); |
|
239 array.AppendL( iCookies[i] ); |
|
240 } |
|
241 } |
|
242 CleanupStack::Pop( &array ); |
|
243 DLTRACEOUT(("Found %d suitable cookies", array.Count() )); |
|
244 return array; |
|
245 } |
|
246 |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Removes cookies that have expired |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CNcdServerDetails::RemoveExpiredCookies() |
|
253 { |
|
254 DLTRACEIN(("")); |
|
255 |
|
256 TInt removed = 0; |
|
257 TTime time; |
|
258 time.UniversalTime(); |
|
259 |
|
260 TInt i = 0; |
|
261 while ( i < iCookies.Count() ) |
|
262 { |
|
263 if ( iCookies[i]->ExpirationDelta() && |
|
264 iCookies[i]->ExpirationTime() < time ) |
|
265 { |
|
266 DLINFO(( _L("Cookie %S has expired"), &iCookies[i]->Key() )); |
|
267 delete iCookies[i]; |
|
268 iCookies.Remove( i ); |
|
269 removed++; |
|
270 } |
|
271 else |
|
272 { |
|
273 ++i; |
|
274 } |
|
275 } |
|
276 DLTRACEOUT(("Removed %d cookies", removed)); |
|
277 return removed; |
|
278 } |
|
279 |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // Constructor |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 CNcdServerDetails::CNcdServerDetails() |
|
286 { |
|
287 } |
|
288 |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // 2nd phase constructor |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void CNcdServerDetails::ConstructL( |
|
295 const TDesC& aServerUri, |
|
296 const TDesC& aNamespace ) |
|
297 { |
|
298 iServerUri = aServerUri.AllocL(); |
|
299 iNamespace = aNamespace.AllocL(); |
|
300 iCapabilities = new( ELeave ) CDesCArrayFlat( KListGranularity ); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // 2nd phase constructor |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void CNcdServerDetails::ConstructL( RReadStream& aStream ) |
|
308 { |
|
309 DLTRACEIN(("")); |
|
310 InternalizeDesL( iServerUri, aStream ); |
|
311 InternalizeDesL( iNamespace, aStream ); |
|
312 DLTRACE(( _L("ServerURI: %S, Namespace: %S"), iServerUri, iNamespace )); |
|
313 iCapabilities = new( ELeave ) CDesCArrayFlat( KListGranularity ); |
|
314 |
|
315 TInt32 capabilityCount = aStream.ReadInt32L(); |
|
316 DLTRACE(("Internalizing %d capabilities", capabilityCount )); |
|
317 |
|
318 HBufC* capability( NULL ); |
|
319 for ( TInt i = 0; i < capabilityCount; i++ ) |
|
320 { |
|
321 InternalizeDesL( capability, aStream ); |
|
322 CleanupStack::PushL( capability ); |
|
323 DLTRACE(( _L("Cap: %S"), capability )); |
|
324 iCapabilities->AppendL( *capability ); |
|
325 CleanupStack::PopAndDestroy( capability ); |
|
326 capability = NULL; |
|
327 } |
|
328 |
|
329 TInt32 cookieCount = aStream.ReadInt32L(); |
|
330 DLTRACE(("Internalizing %d cookies", cookieCount )); |
|
331 iCookies.ReserveL( cookieCount ); |
|
332 for ( TInt i = 0; i < cookieCount; ++i ) |
|
333 { |
|
334 CNcdConfigurationProtocolCookie* cookie = |
|
335 CNcdConfigurationProtocolCookie::NewLC(); |
|
336 cookie->InternalizeL( aStream ); |
|
337 iCookies.AppendL( cookie ); |
|
338 CleanupStack::Pop( cookie ); |
|
339 } |
|
340 DLTRACEOUT(("Internalization successful")); |
|
341 } |
|
342 |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // Find cookie |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 TInt CNcdServerDetails::FindCookie( const |
|
349 MNcdConfigurationProtocolCookie& aCookie ) const |
|
350 { |
|
351 for ( TInt i = 0; i < iCookies.Count(); ++i ) |
|
352 { |
|
353 if ( aCookie.Key() == iCookies[i]->Key() ) |
|
354 { |
|
355 return i; |
|
356 } |
|
357 } |
|
358 return KErrNotFound; |
|
359 } |
|
360 |