|
1 /* |
|
2 * Copyright (c) 2005 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: Attribute fetch processor. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngFetchProcessor.h" |
|
20 #include "CPEngAttributeTypeStack.h" |
|
21 #include "CPEngTransactionStatus.h" |
|
22 #include "PEngAddressUtils.h" |
|
23 #include "MPEngPresenceAttrManager.h" |
|
24 #include "MPEngPresenceAdvancedAttrModel2.h" |
|
25 |
|
26 #include "MPEngXMLSerializer.h" |
|
27 #include "MPEngXMLParser.h" |
|
28 #include "PEngWVPresenceAttributes2.h" |
|
29 #include "PEngAttrModelHelper.h" |
|
30 |
|
31 #include "PresenceDebugPrint.h" |
|
32 |
|
33 #include <PEngWVPresenceErrors2.h> |
|
34 #include <E32Std.h> |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 // CONSTANTS |
|
40 /** |
|
41 * Granularity for array of fetched presence ids. |
|
42 * Usually there is just few fetched presence id's |
|
43 * at time. |
|
44 */ |
|
45 const TInt KPEngFetchPresIdGranurality = 5; |
|
46 |
|
47 |
|
48 |
|
49 // ========================== EXPORTED FUNCTIONS =============================== |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CreateAttrFetchProcessorL() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C MPEngAttrFetchProcessor* CreateAttrFetchProcessorL( |
|
55 MPEngPresenceAttrManager& aAttrManager, |
|
56 const MDesCArray& aFetchedPresenceIds, |
|
57 const TArray< TUint32 > aFetchedAttributes, |
|
58 const TDesC& aDomain, |
|
59 TInt aTransactionOperation, |
|
60 TPEngWVCspVersion aCspVersion ) |
|
61 { |
|
62 return CPEngFetchProcessor::NewL( aAttrManager, |
|
63 aFetchedPresenceIds, |
|
64 aFetchedAttributes, |
|
65 aDomain, |
|
66 aTransactionOperation, |
|
67 aCspVersion ); |
|
68 } |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 // ============================ MEMBER FUNCTIONS =============================== |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CPEngFetchProcessor::NewL() |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CPEngFetchProcessor* CPEngFetchProcessor::NewL( MPEngPresenceAttrManager& aAttrManager, |
|
80 const MDesCArray& aFetchedPresenceIds, |
|
81 const TArray< TUint32 > aFetchedAttributes, |
|
82 const TDesC& aDomain, |
|
83 TInt aTransactionOperation, |
|
84 TPEngWVCspVersion aCspVersion ) |
|
85 { |
|
86 CPEngFetchProcessor* self = new ( ELeave ) CPEngFetchProcessor( |
|
87 aAttrManager, |
|
88 aTransactionOperation, |
|
89 aCspVersion ); |
|
90 |
|
91 CleanupStack::PushL( self ); |
|
92 self->ConstructL( aFetchedPresenceIds, aFetchedAttributes, aDomain ); |
|
93 CleanupStack::Pop( self ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 // Destructor |
|
99 CPEngFetchProcessor::~CPEngFetchProcessor() |
|
100 { |
|
101 iFetchedPresenceIds.Reset(); |
|
102 |
|
103 delete iFechedAttributeTypes; |
|
104 delete iDomain; |
|
105 delete iXmlParser; |
|
106 |
|
107 iPresenceBlocks.Reset(); |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CPEngFetchProcessor::CPEngFetchProcessor |
|
113 // C++ default constructor can NOT contain any code, that |
|
114 // might leave. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 CPEngFetchProcessor::CPEngFetchProcessor( MPEngPresenceAttrManager& aAttrManager, |
|
118 TInt aTransactionOperation, |
|
119 TPEngWVCspVersion aCspVersion ) |
|
120 : iAttributeManager( aAttrManager ), |
|
121 iTransactionOperation( aTransactionOperation ), |
|
122 iCspVersion( aCspVersion ), |
|
123 iFetchedPresenceIds( KPEngFetchPresIdGranurality ), |
|
124 iPresenceBlocks( KPEngFetchPresIdGranurality ) |
|
125 { |
|
126 } |
|
127 |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CPEngFetchProcessor::ConstructL() |
|
131 // Symbian 2nd phase constructor can leave. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CPEngFetchProcessor::ConstructL( const MDesCArray& aFetchedPresenceIds, |
|
135 const TArray< TUint32 > aFetchedAttributes, |
|
136 const TDesC& aDomain ) |
|
137 { |
|
138 __ASSERT_ALWAYS( aFetchedPresenceIds.MdcaCount() > 0, User::Leave( KErrArgument ) ); |
|
139 __ASSERT_ALWAYS( aFetchedAttributes.Count() > 0, User::Leave( KErrArgument ) ); |
|
140 |
|
141 iXmlParser = CreateXMLParserL(); |
|
142 iDomain = aDomain.AllocL(); |
|
143 |
|
144 const TInt presenceIdCount = aFetchedPresenceIds.MdcaCount(); |
|
145 for ( TInt ix = 0; ix < presenceIdCount; ix++ ) |
|
146 { |
|
147 //Allow one presence ID only once |
|
148 iFetchedPresenceIds.InsertIsqL( aFetchedPresenceIds.MdcaPoint( ix ), |
|
149 ECmpNormal ); |
|
150 } |
|
151 |
|
152 |
|
153 //Gather attribute names & name spaces |
|
154 //This will also validate that attributes are valid network attributes |
|
155 iFechedAttributeTypes = CPEngAttributeTypeStack::NewL(); |
|
156 iFechedAttributeTypes->PushAttributesL( aFetchedAttributes, |
|
157 iAttributeManager ); |
|
158 } |
|
159 |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CPEngFetchProcessor::GenerateRequestL() |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CPEngFetchProcessor::GenerateRequestL( TDes8& aSendBuffer ) |
|
166 { |
|
167 aSendBuffer.Zero(); |
|
168 MPEngXMLSerializer* serialize = CreateXmlSerializerLC( aSendBuffer ); |
|
169 GenerateRequestL( *serialize, |
|
170 iFetchedPresenceIds, |
|
171 *iFechedAttributeTypes, |
|
172 iCspVersion ); |
|
173 |
|
174 CleanupStack::PopAndDestroy(); //serialize |
|
175 } |
|
176 |
|
177 |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CPEngFetchProcessor::InitResponseProcessingL() |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CPEngFetchProcessor::InitResponseProcessingL( |
|
184 const TDesC8& aResponse, |
|
185 RPointerArray< MPEngPresenceAttrModel2 >& aResultModels, |
|
186 MPEngAdvTransactionStatus2& aResultStatus ) |
|
187 |
|
188 |
|
189 { |
|
190 iPresenceBlocks.Reset(); |
|
191 iFetchedModels = &aResultModels; |
|
192 iTransactionStatus = &aResultStatus; |
|
193 |
|
194 |
|
195 // If there isn't status primitive or the presence response, |
|
196 // indicate the corrupted response to client |
|
197 if ( !iXmlParser->DecodeL( aResponse, KStatusTag, ETrue, 3 ) && |
|
198 !iXmlParser->DecodeL( aResponse, KGetPresenceResponse, ETrue ) ) |
|
199 { |
|
200 User::Leave( KErrCorrupt ); |
|
201 } |
|
202 |
|
203 |
|
204 //Is there something to parse ? |
|
205 if ( CheckResultFromFromResponseL( aResponse, |
|
206 *iDomain, |
|
207 iTransactionOperation, |
|
208 *iXmlParser, |
|
209 *iTransactionStatus, |
|
210 iFetchedPresenceIds |
|
211 ) ) |
|
212 { |
|
213 //Split presence blocks from response to array |
|
214 LocatePresenceBlocksFromResponseL( aResponse, |
|
215 *iXmlParser, |
|
216 iPresenceBlocks ); |
|
217 } |
|
218 } |
|
219 |
|
220 |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CPEngFetchProcessor::ProcessStepL() |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TBool CPEngFetchProcessor::ProcessStepL() |
|
227 { |
|
228 if ( iPresenceBlocks.Count() > 0 ) |
|
229 { |
|
230 //Handle the first block |
|
231 ParseModelsFromBlockL( iPresenceBlocks[ 0 ], |
|
232 iAttributeManager, |
|
233 *iXmlParser, |
|
234 iFetchedPresenceIds, |
|
235 *iDomain, |
|
236 *iFechedAttributeTypes, |
|
237 *iFetchedModels, |
|
238 iTransactionOperation ); |
|
239 //Remove the first block |
|
240 iPresenceBlocks.Delete( 0 ); |
|
241 return ETrue; |
|
242 } |
|
243 |
|
244 return EFalse; |
|
245 } |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CPEngFetchProcessor::GenerateRequestL() |
|
252 // Parsing helper |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CPEngFetchProcessor::GenerateRequestL( |
|
256 MPEngXMLSerializer& aSerializer, |
|
257 const CDesC16ArraySeg& aFetchedPresenceIds, |
|
258 const CPEngAttributeTypeStack& aFechedAttributeTypes, |
|
259 TPEngWVCspVersion aCspVersion ) |
|
260 { |
|
261 TPtrC8 transactionContentNS( KTransactionContentNS ); |
|
262 TPtrC8 presenceSubListNS( KPresenceSubListAttributesNS ); |
|
263 |
|
264 if ( aCspVersion == EWVCspV12 ) |
|
265 { |
|
266 transactionContentNS.Set( KTransactionContentNS_CSP12 ); |
|
267 presenceSubListNS.Set( KPresenceSubListAttributesNS_CSP12 ); |
|
268 } |
|
269 |
|
270 const TInt presenceIdCount( aFetchedPresenceIds.Count() ); |
|
271 aSerializer.StartTagL( KTransactionContent ); |
|
272 aSerializer.AttributeL( KXmlXmlns, transactionContentNS ); |
|
273 |
|
274 aSerializer.StartTagL( KGetPresenceRequest ); |
|
275 |
|
276 //Generate first requested presence ID's |
|
277 TInt index = 0; |
|
278 for ( index = 0; index < presenceIdCount; index++ ) |
|
279 { |
|
280 aSerializer.StartTagL( KUser ); |
|
281 aSerializer.StartTagL( KUserIDXMLTag ); |
|
282 { |
|
283 aSerializer.WvAddressL( aFetchedPresenceIds[ index ] ); |
|
284 } |
|
285 aSerializer.EndTagL( KUserIDXMLTag ); |
|
286 aSerializer.EndTagL( KUser ); |
|
287 } |
|
288 |
|
289 |
|
290 //And then requested attribute ID's |
|
291 //When engine starts support extension attributes, |
|
292 //this must be changed to use properly the name spaces. |
|
293 aSerializer.StartTagL( KPresenceSubList ); |
|
294 aSerializer.AttributeL( KXmlXmlns, presenceSubListNS ); |
|
295 |
|
296 TInt attributeCount( aFechedAttributeTypes.TypeCount() ); |
|
297 for ( index = 0; index < attributeCount; index++ ) |
|
298 { |
|
299 aSerializer.StartTagL( aFechedAttributeTypes.Name( index ) ); |
|
300 aSerializer.EndTagL( aFechedAttributeTypes.Name( index ) ); |
|
301 } |
|
302 |
|
303 aSerializer.EndTagL( KPresenceSubList ); |
|
304 |
|
305 aSerializer.EndTagL( KGetPresenceRequest ); |
|
306 aSerializer.EndTagL( KTransactionContent ); |
|
307 } |
|
308 |
|
309 |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CPEngFetchProcessor::CheckResultFromFromResponseL() |
|
313 // Parsing helper |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 TBool CPEngFetchProcessor::CheckResultFromFromResponseL( |
|
317 const TDesC8& aResponse, |
|
318 const TDesC& aDomain, |
|
319 TInt aTransactionOperation, |
|
320 MPEngXMLParser& aParser, |
|
321 MPEngAdvTransactionStatus2& aTransactionStatus, |
|
322 CDesC16Array& aRequestedPresenceIds ) |
|
323 { |
|
324 //Get the result structure from response |
|
325 aParser.ParseResultL( aResponse, |
|
326 aTransactionOperation, |
|
327 aTransactionStatus ); |
|
328 |
|
329 //Filter presence id's according the network server response status |
|
330 //If all requested presence id's were unknown, no need to do further |
|
331 //processing. In this case add all requested presence id's |
|
332 //as detailed result. |
|
333 if ( aTransactionStatus.Status() == KPEngNwErrUnknownUser ) |
|
334 { |
|
335 TInt presIdCount = aRequestedPresenceIds.Count(); |
|
336 for ( TInt presIdIx( 0 ); presIdIx < presIdCount; presIdIx++ ) |
|
337 { |
|
338 TPtrC presenceId( aRequestedPresenceIds[ presIdIx ] ); |
|
339 aTransactionStatus.AddDetailedResultL( aTransactionOperation, |
|
340 KPEngNwErrUnknownUser, |
|
341 NULL, |
|
342 &presenceId, |
|
343 NULL, |
|
344 NULL ); |
|
345 } |
|
346 |
|
347 return EFalse; |
|
348 } |
|
349 |
|
350 //If partial failure, remove unknown presence id's |
|
351 if ( aTransactionStatus.Status() == KPEngNwErrPartiallySuccessful ) |
|
352 { |
|
353 const TInt detailedResults = aTransactionStatus.DetailedResultCount(); |
|
354 for ( TInt dResultIx( 0 ); dResultIx < detailedResults; dResultIx++ ) |
|
355 { |
|
356 const MPEngDetailedResultEntry2& dEntry = |
|
357 aTransactionStatus.DetailedResult( dResultIx ); |
|
358 TPtrC unknownPresenceId( NULL, 0 ); |
|
359 if ( dEntry.GetDetailedDesc( unknownPresenceId, |
|
360 EPEngDTPresenceID ) == KErrNone ) |
|
361 { |
|
362 //there was a presence id reported in detailed result |
|
363 //assume that it is failed and try remove it from fetched presences |
|
364 TInt index = |
|
365 PEngAddressUtils::FindWVAddressF( unknownPresenceId, |
|
366 aRequestedPresenceIds, |
|
367 aDomain, |
|
368 PEngAddressUtils::EMatchToUniqueId ); |
|
369 if ( index != KErrNotFound ) |
|
370 { |
|
371 aRequestedPresenceIds.Delete( index ); |
|
372 } |
|
373 |
|
374 //If there is some requested user ID reported in response as unknown, |
|
375 //but its locating & remove from requested ID's array fails |
|
376 //==> no problem, only those users models are anyway returned |
|
377 //to client, which are found from response. |
|
378 } |
|
379 } |
|
380 } |
|
381 |
|
382 return ETrue; |
|
383 } |
|
384 |
|
385 |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // CPEngFetchProcessor::LocatePresenceBlocksFromResponseL() |
|
389 // Parsing helper |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 void CPEngFetchProcessor::LocatePresenceBlocksFromResponseL( |
|
393 const TDesC8& aResponse, |
|
394 MPEngXMLParser& aParser, |
|
395 CDesC8Array& aPresenceBlocks ) |
|
396 { |
|
397 //locate the presence data blocks |
|
398 if ( aParser.DecodeL( aResponse, KPresenceXMLTag, ETrue ) ) |
|
399 { |
|
400 //place found presence data blocks to an array |
|
401 TInt foundPresencesCount = aParser.Count(); |
|
402 for ( TInt blockIndex = 0; blockIndex < foundPresencesCount; blockIndex++ ) |
|
403 { |
|
404 aPresenceBlocks.AppendL( aParser.ResultL( blockIndex ) ); |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CPEngFetchProcessor::ParseModelsFromBlockL() |
|
412 // Parsing helper |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 void CPEngFetchProcessor::ParseModelsFromBlockL( |
|
416 const TDesC8& aPresenceBlock, |
|
417 MPEngPresenceAttrManager& aAttrManager, |
|
418 MPEngXMLParser& aParser, |
|
419 CDesC16Array& aFetchedPresenceIds, |
|
420 const TDesC& aDomain, |
|
421 const CPEngAttributeTypeStack& aAttributeTypes, |
|
422 RPointerArray<MPEngPresenceAttrModel2>& aResultModels, |
|
423 TInt aOperation ) |
|
424 { |
|
425 if ( aParser.DecodeL( aPresenceBlock, KUserIDXMLTag, EFalse ) ) |
|
426 { |
|
427 //There is a presence id => unescape the id |
|
428 HBufC* presIdBuf = aParser.ResultAsWVAddressL(); |
|
429 CleanupStack::PushL( presIdBuf ); |
|
430 |
|
431 //Try get the presence id as it was really requested |
|
432 TInt presenceIdIndex = PEngAddressUtils::FindWVAddressF( *presIdBuf, |
|
433 aFetchedPresenceIds, |
|
434 aDomain, |
|
435 PEngAddressUtils::EMatchToUniqueId ); |
|
436 if ( presenceIdIndex != KErrNotFound ) |
|
437 { |
|
438 //There is client requested presence ID for this presence block |
|
439 //Use the client given ID as model ID. |
|
440 //If not able to match to client given id, actual id from presence block is used |
|
441 TPtrC clientPresenceId( aFetchedPresenceIds[ presenceIdIndex ] ); |
|
442 HBufC* clientPresenceIdBuf = clientPresenceId.AllocL(); |
|
443 |
|
444 CleanupStack::PopAndDestroy(); //presIdBuf |
|
445 CleanupStack::PushL( clientPresenceIdBuf ); |
|
446 presIdBuf = clientPresenceIdBuf; |
|
447 |
|
448 //Remove ID from aFetchedPresenceIds array, |
|
449 //so it won't be handled again |
|
450 aFetchedPresenceIds.Delete( presenceIdIndex ); |
|
451 } |
|
452 |
|
453 |
|
454 //go trough all requested attributes |
|
455 TBool onlineStatFetched( EFalse ); |
|
456 const TInt attrTypeCount = aAttributeTypes.TypeCount(); |
|
457 for ( TInt attrTypeIx = 0; attrTypeIx < attrTypeCount; attrTypeIx++ ) |
|
458 { |
|
459 const TUint32 attributeType = aAttributeTypes.TypeId( attrTypeIx ); |
|
460 if ( aParser.DecodeL( aPresenceBlock, |
|
461 aAttributeTypes.Name( attrTypeIx ), |
|
462 ETrue ) ) |
|
463 { |
|
464 if ( attributeType == KUidPrAttrOnlineStatus ) |
|
465 { |
|
466 onlineStatFetched = ETrue; |
|
467 } |
|
468 //attribute type was found from presence data block |
|
469 //Instantiate a model |
|
470 MPEngPresenceAttrModel2* model = NULL; |
|
471 aAttrManager.LoadAttributeLC( model, |
|
472 *presIdBuf, |
|
473 attributeType, |
|
474 EPEngStorableModel ); |
|
475 |
|
476 |
|
477 |
|
478 //And let it to do the real parsing |
|
479 TPtrC8 attributeData = aParser.ResultL(); |
|
480 model->Advanced()->DecodeFromXmlL( aParser, attributeData ); |
|
481 |
|
482 //add the model to results |
|
483 aResultModels.AppendL( model ); |
|
484 CleanupStack::Pop(); //model |
|
485 } |
|
486 |
|
487 else |
|
488 { |
|
489 |
|
490 |
|
491 if ( attributeType == KUidPrAttrStatusText ) |
|
492 { |
|
493 |
|
494 MPEngPresenceAttrModel2* model = NULL; |
|
495 aAttrManager.LoadAttributeLC( model, |
|
496 *presIdBuf, |
|
497 KUidPrAttrStatusText, |
|
498 EPEngStorableModel ); |
|
499 |
|
500 model->SetDataDesC16L( KNullDesC, EPEngStatusText ); |
|
501 |
|
502 PEngAttrModelHelper::AddOrReplaceModelL( aResultModels, *model ); |
|
503 // aResultModels.AppendL( model ); |
|
504 CleanupStack::Pop(); //model |
|
505 |
|
506 } |
|
507 } |
|
508 } |
|
509 if ( !onlineStatFetched && ( aOperation == EPEngTransOpAttributeFetchToCache ) ) |
|
510 { |
|
511 MPEngPresenceAttrModel2* model = NULL; |
|
512 aAttrManager.LoadAttributeLC( model, |
|
513 *presIdBuf, |
|
514 KUidPrAttrOnlineStatus, |
|
515 EPEngStorableModel ); |
|
516 //add the model to results |
|
517 aResultModels.AppendL( model ); |
|
518 CleanupStack::Pop(); //model |
|
519 } |
|
520 |
|
521 CleanupStack::PopAndDestroy( presIdBuf ); |
|
522 } |
|
523 } |
|
524 |
|
525 |
|
526 |
|
527 // End of File |
|
528 |
|
529 |