ccservices/cmsservices/cmsengine/Server/src/cmsserverasynccontact.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 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: 
       
    15 *       
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <spsettings.h>
       
    22 #include <spproperty.h>
       
    23 #include <MVPbkFieldType.h>
       
    24 #include <MVPbkStoreContact.h>
       
    25 #include <CVPbkContactManager.h>
       
    26 #include <presencecachereader2.h>
       
    27 #include <CPbk2SortOrderManager.h>
       
    28 #include <MPbk2ContactNameFormatter.h>
       
    29 #include <Pbk2ContactNameFormatterFactory.h>
       
    30 #include <MVPbkContactFieldTextData.h>
       
    31 #include <MVPbkContactFieldUriData.h>
       
    32 #include <MVPbkContactFieldDateTimeData.h>
       
    33 #include <CVPbkContactFieldIterator.h>
       
    34 #include <MVPbkContactFieldBinaryData.h>
       
    35 #include <CVPbkDefaultAttribute.h>
       
    36 #include <MVPbkContactStore.h>
       
    37 #include <MVPbkContactStoreProperties.h>
       
    38 #include "bpas.h"
       
    39 #include "cmsserver.h"
       
    40 #include "cmsdefines.h"
       
    41 #include "cmsserverutils.h"
       
    42 #include "cmsservercontact.h"
       
    43 #include "cmsphonebookproxy.h"
       
    44 #include "cmsserverasynccontact.h"
       
    45 #include "cmsserverxspcontacthandler.h"
       
    46 #include "cmsserverdefines.h"
       
    47 #include "cmsdebug.h"
       
    48 
       
    49 // ----------------------------------------------------
       
    50 // CCmsServerAsyncContact::CCmsServerAsyncContact
       
    51 // 
       
    52 // ----------------------------------------------------
       
    53 //
       
    54 CCmsServerAsyncContact::CCmsServerAsyncContact( CCmsServerContact& aSyncContact,
       
    55                                                 CCmsServer& aCmsServer ) :
       
    56                                   CActive( EPriorityStandard ),
       
    57                                   iSyncContact( aSyncContact ),
       
    58                                   iCmsServer( aCmsServer )
       
    59     {
       
    60     CActiveScheduler::Add( this );
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------
       
    64 // CCmsServerAsyncContact::NewL
       
    65 // 
       
    66 // ----------------------------------------------------
       
    67 //
       
    68 CCmsServerAsyncContact* CCmsServerAsyncContact::NewL( CCmsServerContact& aSyncContact,
       
    69                                                       CCmsServer& aCmsServer )
       
    70     {
       
    71     CCmsServerAsyncContact* self = new( ELeave ) CCmsServerAsyncContact(
       
    72         aSyncContact, aCmsServer );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop();
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------
       
    80 // CCmsServerAsyncContact::~CCmsServerAsyncContact
       
    81 // 
       
    82 // ----------------------------------------------------
       
    83 //
       
    84 CCmsServerAsyncContact::~CCmsServerAsyncContact()
       
    85     {
       
    86     Cancel();
       
    87     delete iSortOrderManager;
       
    88     delete iNameFormatter;  
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------
       
    92 // CCmsServerAsyncContact::ConstructL
       
    93 // 
       
    94 // ----------------------------------------------------
       
    95 //
       
    96 void CCmsServerAsyncContact::ConstructL()
       
    97     {
       
    98     PRINT( _L("Start CCmsServerAsyncContact::ConstructL()" ) );
       
    99     
       
   100     iContactManager = iCmsServer.PhonebookProxyHandle().ContactManager();
       
   101     
       
   102     //for full name
       
   103 
       
   104     iSortOrderManager = CPbk2SortOrderManager::NewL( iContactManager->FieldTypes() );            
       
   105     iNameFormatter = Pbk2ContactNameFormatterFactory::CreateL
       
   106             ( iContactManager->FieldTypes(), *iSortOrderManager, &iCmsServer.FileSession() );
       
   107     
       
   108     PRINT( _L("End CCmsServerAsyncContact::ConstructL()" ) );
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------
       
   112 // CCmsServerAsyncContact::ContactDataTextLC
       
   113 // 
       
   114 // ----------------------------------------------------
       
   115 //        
       
   116 CDesCArrayFlat* CCmsServerAsyncContact::ContactDataTextLC( CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup )
       
   117     {
       
   118     PRINT( _L(" Start CCmsServerAsyncContact::ContactDataTextL( group )" ) );
       
   119     
       
   120     CDesCArrayFlat* fieldArray = NULL;
       
   121     switch( aFieldGroup )
       
   122         {
       
   123         case CCmsContactFieldItem::ECmsGroupVoIP:
       
   124             {
       
   125             const TInt count = sizeof( KCmsVoIPGroup ) / sizeof( KCmsVoIPGroup[0] );
       
   126             fieldArray = FieldsFromArrayLC( count, KCmsVoIPGroup );
       
   127             break;
       
   128             }
       
   129         case CCmsContactFieldItem::ECmsGroupVoice:
       
   130             {
       
   131             const TInt count = sizeof( KCmsVoiceCallGroup ) / sizeof( KCmsVoiceCallGroup[0] );
       
   132             fieldArray = FieldsFromArrayLC( count, KCmsVoiceCallGroup );
       
   133             break;
       
   134             }
       
   135         case CCmsContactFieldItem::ECmsGroupEmail:
       
   136             {
       
   137             const TInt count = sizeof( KCmsEmailAddressGroup ) / sizeof( KCmsEmailAddressGroup[0] );
       
   138             fieldArray = FieldsFromArrayLC( count, KCmsEmailAddressGroup );
       
   139             break;
       
   140             }
       
   141         default:
       
   142             {
       
   143             User::Leave( KErrArgument );
       
   144             break;
       
   145             }
       
   146         }
       
   147     PRINT( _L(" End CCmsServerAsyncContact::ContactDataTextL( group )" ) );
       
   148         
       
   149     return fieldArray;
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------
       
   153 // CCmsServerAsyncContact::ContactDataUriLC
       
   154 // 
       
   155 // ----------------------------------------------------
       
   156 //        
       
   157 CDesCArrayFlat* CCmsServerAsyncContact::ContactDataUriLC( TInt aResourceId )
       
   158     {
       
   159     PRINT( _L(" Start CCmsServerAsyncContact::ContactDataUriLC()" ) );
       
   160     
       
   161     MCmsContactInterface& syncContact = iSyncContact;
       
   162     CDesCArrayFlat* fieldArray = new ( ELeave ) CDesCArrayFlat( 5 );
       
   163     CleanupStack::PushL( fieldArray );
       
   164     const MVPbkFieldType* type = iContactManager->FieldTypes().Find( aResourceId );
       
   165     CVPbkBaseContactFieldTypeIterator* fieldIterator = CVPbkBaseContactFieldTypeIterator::NewLC( *type, syncContact.Contact().Fields() );
       
   166     while( fieldIterator->HasNext() )
       
   167         {
       
   168         const MVPbkBaseContactField* field = fieldIterator->Next();
       
   169         const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast( field->FieldData() );
       
   170         fieldArray->AppendL( uri.Uri() );
       
   171         }
       
   172     CleanupStack::PopAndDestroy();  //fieldIterator
       
   173     PRINT( _L(" End CCmsServerAsyncContact::ContactDataUriLC()" ) );
       
   174     return fieldArray;
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------
       
   178 // CCmsServerAsyncContact::FieldsFromArray
       
   179 // 
       
   180 // ----------------------------------------------------
       
   181 //        
       
   182 CDesCArrayFlat* CCmsServerAsyncContact::FieldsFromArrayLC( TInt aCount, const TInt aResourceArray[] )
       
   183     {
       
   184     PRINT( _L(" Start CCmsServerAsyncContact::FieldsFromArrayLC()" ) );
       
   185   
       
   186     CDesCArrayFlat* fieldArray = new ( ELeave ) CDesCArrayFlat( aCount );
       
   187     CleanupStack::PushL( fieldArray );
       
   188     for( TInt i = 0;i < aCount;i++ )
       
   189         {
       
   190         PhonebookDataL( aResourceArray[i], *fieldArray );
       
   191         }
       
   192     return fieldArray;
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------
       
   196 // CCmsServerAsyncContact::PhonebookDataL
       
   197 // 
       
   198 // ----------------------------------------------------
       
   199 //        
       
   200 void CCmsServerAsyncContact::PhonebookDataL( TInt aResourceId, CDesCArrayFlat& aFieldArray )
       
   201     {
       
   202     PRINT( _L(" Start CCmsServerAsyncContact::PhonebookDataL()" ) );
       
   203     
       
   204     MCmsContactInterface& syncContact = iSyncContact;
       
   205     CVPbkBaseContactFieldTypeIterator* fieldIterator = NULL;
       
   206     CCmsServerXSPContactHandler* xspHandler = iSyncContact.XSPHandler();
       
   207     const TInt xspCount( xspHandler ? xspHandler->ContactCount() : 0 );
       
   208     const MVPbkFieldType* type = iContactManager->FieldTypes().Find( aResourceId );
       
   209     fieldIterator = CVPbkBaseContactFieldTypeIterator::NewLC( *type, syncContact.Contact().Fields() );
       
   210     GetOneFieldL( aFieldArray, *fieldIterator );
       
   211     CleanupStack::PopAndDestroy();  //fieldIterator
       
   212     for( TInt i = 0; i < xspCount; i++ )
       
   213         {
       
   214         fieldIterator = CVPbkBaseContactFieldTypeIterator::NewLC( *type, xspHandler->Contact( i )->Fields() );
       
   215         GetOneFieldL( aFieldArray, *fieldIterator );
       
   216         CleanupStack::PopAndDestroy();  //fieldIterator
       
   217         }
       
   218     PRINT( _L("End CCmsServerAsyncContact::PhonebookDataL()" ) );
       
   219         
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------
       
   223 // CCmsServerAsyncContact::GetOneFieldL
       
   224 // 
       
   225 // ----------------------------------------------------
       
   226 //        
       
   227 void CCmsServerAsyncContact::GetOneFieldL( CDesCArrayFlat& aFieldArray, CVPbkBaseContactFieldTypeIterator& aFieldIterator )
       
   228     {
       
   229     PRINT( _L("Start CCmsServerAsyncContact::GetOneFieldL()" ) );
       
   230     
       
   231     while( aFieldIterator.HasNext() )
       
   232         {
       
   233         HBufC* data = ParseContactFieldL( *aFieldIterator.Next() );  
       
   234         if( data )
       
   235             {
       
   236             TInt index( 0 );
       
   237             CleanupStack::PushL( data );
       
   238             TPtrC descriptor( data->Des() );
       
   239             if( aFieldArray.Find( descriptor, index ) != 0 )
       
   240                 {
       
   241                 aFieldArray.AppendL( descriptor );
       
   242                 }
       
   243             CleanupStack::PopAndDestroy();  //data
       
   244             }
       
   245         }
       
   246     PRINT( _L("End CCmsServerAsyncContact::GetOneFieldL()" ) );   
       
   247     }
       
   248 
       
   249 // ----------------------------------------------------
       
   250 // CCmsServerAsyncContact::ContactDataBinaryL
       
   251 // 
       
   252 // ----------------------------------------------------
       
   253 //        
       
   254 HBufC8* CCmsServerAsyncContact::ContactDataBinaryL( TInt aResourceId )
       
   255     {
       
   256     PRINT( _L(" Start CCmsServerAsyncContact::ContactDataBinaryL()" ) );
       
   257     
       
   258     HBufC8* binData = NULL;
       
   259     MCmsContactInterface& syncContact = iSyncContact;
       
   260     const MVPbkStoreContact& contact = syncContact.Contact();
       
   261     const MVPbkFieldType* type = iContactManager->FieldTypes().Find( aResourceId );
       
   262     CVPbkBaseContactFieldTypeIterator* itr = CVPbkBaseContactFieldTypeIterator::NewLC( *type, contact.Fields() );
       
   263     if( itr->HasNext() )
       
   264         {
       
   265         PRINT( _L( "CCmsServerAsyncContact::ContactDataBinaryL():Phonebook thumbnail available" ) );
       
   266         const MVPbkBaseContactField* field = itr->Next();
       
   267         const MVPbkContactFieldBinaryData& data = MVPbkContactFieldBinaryData::Cast( field->FieldData() );
       
   268         binData = data.BinaryData().AllocL();
       
   269         }
       
   270     else
       
   271         {   
       
   272         PRINT( _L( "CCmsServerAsyncContact::ContactDataBinaryL(): Try to fetch avatar" ) );
       
   273         
       
   274         binData = FetchAvatarL();
       
   275         }
       
   276     CleanupStack::PopAndDestroy( itr );
       
   277     PRINT( _L(" End CCmsServerAsyncContact::ContactDataBinaryL()" ) );
       
   278     return binData;
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------
       
   282 // CCmsServerAsyncContact::FetchAvatarL
       
   283 // 
       
   284 // ----------------------------------------------------------
       
   285 //
       
   286 HBufC8* CCmsServerAsyncContact::FetchAvatarL()
       
   287     {
       
   288     PRINT( _L(" Start CCmsServerAsyncContact::FetchAvatarL()" ) );
       
   289     
       
   290     TBool found( EFalse );
       
   291     HBufC8* avatarBuf = NULL;
       
   292     MPresenceCacheReader2* reader = MPresenceCacheReader2::CreateReaderL();
       
   293     CleanupDeletePushL( reader );
       
   294     CDesCArrayFlat* uriArray( ContactDataUriLC( R_VPBK_FIELD_TYPE_IMPP ) );
       
   295     const TInt count( uriArray->MdcaCount() );
       
   296     for( TInt i = 0; !found && i < count; i++ )
       
   297         {
       
   298         MPresenceBuddyInfo2* info = reader->PresenceInfoLC( uriArray->MdcaPoint( i ) );
       
   299         if( info )
       
   300             {
       
   301             TPtrC8 avatarDesc( info->Avatar() );
       
   302             PRINT1( _L("CCmsServerAsyncContact::FetchAvatarL(): Avatar data length: %d" ), avatarDesc.Length() );
       
   303             avatarBuf = avatarDesc.AllocL();
       
   304             CleanupStack::PopAndDestroy();  //info
       
   305             found = ETrue;
       
   306             }
       
   307         }
       
   308     CleanupStack::PopAndDestroy( 2 );  //uriArray, reader
       
   309     PRINT( _L(" End  CCmsServerAsyncContact::FetchAvatarL()" ) );
       
   310     return avatarBuf;
       
   311     }
       
   312 
       
   313 // ----------------------------------------------------------
       
   314 // CCmsServerAsyncContact::FetchContactdata
       
   315 // 
       
   316 // ----------------------------------------------------------
       
   317 //
       
   318 void CCmsServerAsyncContact::FetchContactData( CCmsContactFieldItem::TCmsContactField aField )
       
   319     {
       
   320     PRINT( _L(" Start CCmsServerAsyncContact::FetchContactData()" ) );
       
   321     
       
   322     iStatus = KRequestPending;
       
   323     TRequestStatus* status = &iStatus;
       
   324     User::RequestComplete( status, ( TInt )aField );
       
   325     iAsyncOperation = SelectOperationType( aField ); 
       
   326     SetActive();
       
   327     PRINT( _L(" End CCmsServerAsyncContact::FetchContactData()" ) );
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------
       
   331 // CCmsServerAsyncContact::FetchEnabledFields
       
   332 // 
       
   333 // ----------------------------------------------------------
       
   334 //
       
   335 void CCmsServerAsyncContact::FetchEnabledFields()
       
   336     {
       
   337     PRINT( _L(" Start CCmsServerAsyncContact::FetchEnabledFields()" ) );
       
   338     
       
   339     iStatus = KRequestPending;
       
   340     TRequestStatus* status = &iStatus;
       
   341     User::RequestComplete( status, KErrNone );
       
   342     iAsyncOperation = EFetchEnabledFields;
       
   343     SetActive();
       
   344     PRINT( _L(" End CCmsServerAsyncContact::FetchEnabledFields()" ) );
       
   345     }
       
   346 
       
   347 // ----------------------------------------------------------
       
   348 // CCmsServerAsyncContact::SelectOperationType
       
   349 // 
       
   350 // ----------------------------------------------------------
       
   351 //
       
   352 CCmsServerAsyncContact::TCmsAsyncOperation CCmsServerAsyncContact::SelectOperationType( TInt aCmsField )
       
   353     {
       
   354     PRINT( _L(" Start CCmsServerAsyncContact::SelectOperationType()" ) );
       
   355     
       
   356     CCmsServerAsyncContact::TCmsAsyncOperation operation = CCmsServerAsyncContact::ENone;
       
   357     switch( aCmsField )
       
   358         {
       
   359         case CCmsContactFieldItem::ECmsPresenceData:
       
   360             {
       
   361             operation = CCmsServerAsyncContact::EFetchPresenceData;
       
   362             break;
       
   363             }
       
   364         case CCmsContactFieldItem::ECmsThumbnailPic:
       
   365             {
       
   366             operation = CCmsServerAsyncContact::EFetchPhonebookBinData;
       
   367             break;
       
   368             }
       
   369         case CCmsContactFieldItem::ECmsImpp:
       
   370             {
       
   371             operation = CCmsServerAsyncContact::EFetchPhonebookUriData;
       
   372         	break;
       
   373             }
       
   374         case CCmsContactFieldItem::ECmsAnniversary:
       
   375             {
       
   376             operation = CCmsServerAsyncContact::EFetchPhonebookDateTimeData;
       
   377         	break;
       
   378             }
       
   379         default:
       
   380             {
       
   381             operation = CCmsServerAsyncContact::EFetchPhonebookTextData;
       
   382             break;
       
   383             }
       
   384         }
       
   385     PRINT( _L(" End CCmsServerAsyncContact::SelectOperationType()" ) );    
       
   386     return operation;
       
   387     }
       
   388 
       
   389 // ----------------------------------------------------
       
   390 // CCmsServerAsyncContact::DoGetEnabledFieldsLC
       
   391 // 
       
   392 // ----------------------------------------------------
       
   393 //
       
   394 HBufC* CCmsServerAsyncContact::GetEnabledFieldsLC()
       
   395     {
       
   396     TInt bufferIndex = 0;
       
   397     CBufFlat* dataBuffer = CBufFlat::NewL( 50 );
       
   398     CleanupStack::PushL( dataBuffer );
       
   399     MCmsContactInterface& syncContact = iSyncContact;
       
   400     CCmsServerXSPContactHandler* xspHandler = iSyncContact.XSPHandler();
       
   401     const TInt xspCount( xspHandler ? xspHandler->ContactCount() : 0 );
       
   402     DoGetEnabledFieldsL( bufferIndex, dataBuffer, syncContact.Contact() );
       
   403     for( TInt i = 0; i < xspCount; i++ )
       
   404         {
       
   405         DoGetEnabledFieldsL( bufferIndex, dataBuffer, *xspHandler->Contact( i ) );
       
   406         }
       
   407     //Fullname is always available. Pbhk default name used atleast. 
       
   408     TBuf8<32> fullnameBuffer( _L8( "" ) );
       
   409     fullnameBuffer.AppendNum( CCmsContactFieldItem::ECmsFullName );
       
   410     fullnameBuffer.Append( KDelimiter );
       
   411     dataBuffer->InsertL( 0, fullnameBuffer );
       
   412 
       
   413     //Make thumbnail to be always "available". There may also be
       
   414     //an avatar available in the presence cache, so we need to 
       
   415     //make the client application ask this field explicitly
       
   416     TBuf8<32> thumbnailBuffer( _L8( "" ) );
       
   417     thumbnailBuffer.AppendNum( CCmsContactFieldItem::ECmsThumbnailPic );
       
   418     thumbnailBuffer.Append( KDelimiter );
       
   419     dataBuffer->InsertL( 0, thumbnailBuffer );
       
   420         
       
   421     TInt dataLength( dataBuffer->Size() );
       
   422     HBufC8* data8 = HBufC8::NewLC( dataLength );
       
   423     TPtr8 desc( data8->Des() );
       
   424     dataBuffer->Read( 0, desc, dataLength );
       
   425     dataBuffer->Reset();
       
   426     PRINT1( _L("CCmsServerAsyncContact::GetEnabledFieldsLC():Enabled fields: %S" ), &desc );
       
   427     
       
   428     HBufC* data16 = CmsServerUtils::ConvertDescLC( desc );
       
   429     CleanupStack::Pop();  //data16
       
   430     CleanupStack::PopAndDestroy( 2 );  //data8, dataBuffer
       
   431     CleanupStack::PushL( data16 );
       
   432     return data16;
       
   433     }
       
   434         
       
   435 // ----------------------------------------------------
       
   436 // CCmsServerAsyncContact::DoGetEnabledFieldsLC
       
   437 // 
       
   438 // ----------------------------------------------------
       
   439 //
       
   440 void CCmsServerAsyncContact::DoGetEnabledFieldsL( TInt& aBufferIndex, CBufFlat* aDataBuffer,
       
   441                                                   const MVPbkStoreContact& aContact )
       
   442     {
       
   443     PRINT( _L(" Start CCmsServerAsyncContact::DoGetEnabledFieldsLC()" ) );
       
   444     
       
   445     TBuf8<32> itemBuffer( _L8( "" ) );
       
   446     const MVPbkBaseContactFieldCollection& fieldCollection( aContact.Fields() );    
       
   447     TInt fieldCount = fieldCollection.FieldCount();
       
   448     for( TInt i = 0; i < fieldCount; i++ )
       
   449         {
       
   450         const MVPbkBaseContactField& fieldBase( fieldCollection.FieldAt( i ) );
       
   451         const MVPbkContactFieldData& field( fieldBase.FieldData() );
       
   452         const TInt KMatchPriority = 0;
       
   453         const MVPbkFieldType* type = fieldBase.MatchFieldType( KMatchPriority );
       
   454         if( type && !field.IsEmpty() )
       
   455             {
       
   456             itemBuffer.Zero();
       
   457             CCmsContactFieldItem::TCmsContactField cmsField( CmsServerUtils::MatchFieldType( type->FieldTypeResId() ) );
       
   458             itemBuffer.AppendNum( cmsField );
       
   459             if( !HasElement( aDataBuffer->Ptr( 0 ), itemBuffer ) )
       
   460                 {
       
   461                 itemBuffer.Append( KDelimiter );
       
   462                 aDataBuffer->InsertL( aBufferIndex, itemBuffer );
       
   463                 aBufferIndex = aBufferIndex + itemBuffer.Length();
       
   464                 }
       
   465             }
       
   466         }
       
   467     PRINT( _L(" End CCmsServerAsyncContact::DoGetEnabledFieldsLC()" ) );
       
   468     }
       
   469 
       
   470 // ----------------------------------------------------
       
   471 // CCmsServerAsyncContact::HasElement
       
   472 // 
       
   473 // ----------------------------------------------------
       
   474 // 
       
   475 TBool CCmsServerAsyncContact::HasElement( const TDesC8& aBuffer, const TDesC8& aItem )
       
   476     {
       
   477     TBool match = EFalse;
       
   478     TLex8 items( aBuffer );
       
   479     TPtrC8 token( _L8( " " ) );
       
   480     while( aBuffer.Length() > 0 && !match && 0 < token.Length() )
       
   481         {
       
   482         token.Set( items.NextToken() );
       
   483         if( token.Compare( aItem ) == 0 )
       
   484             {
       
   485             match = ETrue;
       
   486             }
       
   487         items.SkipSpace();
       
   488         }
       
   489     return match;
       
   490     }
       
   491 
       
   492 // ----------------------------------------------------
       
   493 // CCmsServerAsyncContact::DoGetDataLC
       
   494 // 
       
   495 // ----------------------------------------------------
       
   496 //
       
   497 HBufC* CCmsServerAsyncContact::DoGetDataLC( TInt aResourceId )
       
   498     {    
       
   499     //If full name is requested
       
   500     //Full name is created by using PbhkNameFormatter.
       
   501     HBufC* returnData = NULL;
       
   502     if( CCmsContactFieldItem::ECmsFullName == aResourceId )
       
   503         {  
       
   504         returnData = DoGetFullNameDataLC();         
       
   505         }
       
   506     else    
       
   507         {
       
   508         returnData = DoGetPhonebookDataLC( aResourceId );
       
   509         }
       
   510     return returnData;                           
       
   511     }
       
   512 
       
   513 // ----------------------------------------------------
       
   514 // CCmsServerAsyncContact::FindImAvailability
       
   515 // 
       
   516 // ----------------------------------------------------
       
   517 //
       
   518 TInt CCmsServerAsyncContact::FindImAvailabilityL()
       
   519     {
       
   520     TInt result( 0 );
       
   521     MCmsContactInterface& syncContact = iSyncContact;
       
   522     const MVPbkStoreContact& contact = syncContact.Contact();
       
   523     const MVPbkFieldType* type = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_IMPP );
       
   524     CVPbkBaseContactFieldTypeIterator* itr = CVPbkBaseContactFieldTypeIterator::NewLC( *type, contact.Fields() );
       
   525     while( itr->HasNext() && result == 0 )
       
   526         {
       
   527         const MVPbkBaseContactField* field = itr->Next();
       
   528         const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast( field->FieldData() );
       
   529         TPtrC scheme( uri.Scheme() ); 
       
   530         if( CmsServerUtils::IsFeatureSupportedL( ESubPropertyIMLaunchUid, scheme ) )//  IsImCapableL( scheme ) )
       
   531             {
       
   532             result = 1;
       
   533             }
       
   534         }
       
   535     CleanupStack::PopAndDestroy();  //itr
       
   536     return result; 
       
   537     }
       
   538 
       
   539 // ----------------------------------------------------
       
   540 // CCmsServerAsyncContact::DefaultAttributesL
       
   541 // 
       
   542 // ----------------------------------------------------
       
   543 //
       
   544 TInt CCmsServerAsyncContact::DefaultAttributesL( const MVPbkBaseContactField& aContactField )
       
   545     {
       
   546     const MVPbkStoreContactField& field = static_cast<const MVPbkStoreContactField&>(aContactField);
       
   547     TInt defaultAttributes = 0; 
       
   548     TInt type = EVPbkDefaultTypeUndefined;
       
   549 
       
   550     while( EVPbkLastDefaultType != type )
       
   551         {                                                 
       
   552         CVPbkDefaultAttribute* attr = CVPbkDefaultAttribute::NewL( (TVPbkDefaultType)type );
       
   553         CleanupStack::PushL( attr );
       
   554 
       
   555         if(iContactManager->ContactAttributeManagerL().HasFieldAttributeL( *attr, field ))
       
   556             {
       
   557             defaultAttributes |= MatchTypesToInternalEnum((TVPbkDefaultType)type);
       
   558             }
       
   559         
       
   560         CleanupStack::PopAndDestroy( attr );        
       
   561         type++;            
       
   562         }
       
   563 
       
   564     return defaultAttributes;
       
   565     }
       
   566 
       
   567 // ----------------------------------------------------------
       
   568 // CCmsServerAsyncContact::MatchTypesToInternalEnum
       
   569 //
       
   570 // ----------------------------------------------------------
       
   571 //
       
   572 CCmsContactFieldItem::TCmsDefaultAttributeTypes
       
   573     CCmsServerAsyncContact::MatchTypesToInternalEnum( TVPbkDefaultType aDefaultType )
       
   574     {
       
   575     CCmsContactFieldItem::TCmsDefaultAttributeTypes defaultAttributeType =
       
   576         CCmsContactFieldItem::ECmsDefaultTypeUndefined;
       
   577     switch( aDefaultType )
       
   578         {
       
   579         case EVPbkDefaultTypePhoneNumber:
       
   580             {
       
   581             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypePhoneNumber;
       
   582             break;
       
   583             }
       
   584         case EVPbkDefaultTypeVideoNumber:
       
   585             {
       
   586             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeVideoNumber;
       
   587             break;
       
   588             }
       
   589         case EVPbkDefaultTypeSms:
       
   590             {
       
   591             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeSms;
       
   592             break;
       
   593             }
       
   594         case EVPbkDefaultTypeMms:
       
   595             {
       
   596             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeMms;
       
   597             break;
       
   598             }
       
   599         case EVPbkDefaultTypeEmail:
       
   600             {
       
   601             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeEmail;
       
   602             break;
       
   603             }
       
   604         case EVPbkDefaultTypeEmailOverSms:
       
   605             {
       
   606             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeEmailOverSms;
       
   607             break; 
       
   608             }
       
   609         case EVPbkDefaultTypeVoIP:
       
   610             {
       
   611             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeVoIP;
       
   612             break;
       
   613             }
       
   614         case EVPbkDefaultTypePOC:
       
   615             {
       
   616             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypePOC;
       
   617             break;
       
   618             }
       
   619         case EVPbkDefaultTypeChat:
       
   620             {
       
   621             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeImpp;
       
   622             break;
       
   623             }
       
   624         case EVPbkDefaultTypeOpenLink:
       
   625             {
       
   626             defaultAttributeType = CCmsContactFieldItem::ECmsDefaultTypeUrl;
       
   627             break;
       
   628             }
       
   629         default:
       
   630             {
       
   631             break;
       
   632             }
       
   633         }
       
   634     return defaultAttributeType;
       
   635     }
       
   636 
       
   637 // ----------------------------------------------------
       
   638 // CCmsServerAsyncContact::IsVoIPCapableL
       
   639 // 
       
   640 // ----------------------------------------------------
       
   641 //
       
   642 TBool CCmsServerAsyncContact::IsVoipCapableL( const TDesC& aScheme )
       
   643     {
       
   644     PRINT( _L( "Start CCmsServerContact::IsVoipCapableL()" ) );
       
   645     PRINT1( _L( "CCmsServerAsyncContact::IsVoipCapableL():Service provider: %S" ), &aScheme );
       
   646     RIdArray ids;
       
   647     CleanupClosePushL( ids );
       
   648     TBool retValue = EFalse;
       
   649     CSPSettings* settings = CSPSettings::NewL();
       
   650     CleanupStack::PushL( settings );
       
   651     CDesCArrayFlat* nameArray = new ( ELeave ) CDesCArrayFlat( 2 );
       
   652     CleanupStack::PushL( nameArray );    
       
   653     TInt error = settings->FindServiceIdsL( ids );  
       
   654     User::LeaveIfError( error );     
       
   655     error = settings->FindServiceNamesL( ids, *nameArray );  
       
   656     User::LeaveIfError( error );
       
   657     TBool ready = EFalse;   
       
   658     const TInt count = nameArray->MdcaCount();
       
   659     for ( TInt i = 0; !ready && i < count; i++ )
       
   660         {
       
   661         TPtrC desc = nameArray->MdcaPoint( i );
       
   662         if ( !desc.CompareF( aScheme ) )
       
   663             {
       
   664             CSPProperty* property = CSPProperty::NewLC();
       
   665             error = settings->FindPropertyL( ids[i], EPropertyServiceAttributeMask, *property );
       
   666             if ( KErrNone == error )
       
   667                 {
       
   668                 TInt value = 0; 
       
   669                 property->GetValue( value );                    
       
   670                 if ( value & ESupportsInternetCall )
       
   671                     {
       
   672                     retValue = ETrue;                
       
   673                     }
       
   674                 }
       
   675             CleanupStack::PopAndDestroy();  //property
       
   676             break;
       
   677             }
       
   678         }
       
   679     CleanupStack::PopAndDestroy( 3 );  //nameArray, settings, ids
       
   680     PRINT( _L( "End CCmsServerContact::IsVoipCapableL()" ) );
       
   681     return retValue;
       
   682     }
       
   683 
       
   684 // ----------------------------------------------------
       
   685 // CCmsServerAsyncContact::DoGetPhonebookDataL
       
   686 // 
       
   687 // ----------------------------------------------------
       
   688 //
       
   689 HBufC* CCmsServerAsyncContact::DoGetPhonebookDataLC( TInt aResourceId )
       
   690     {
       
   691     PRINT( _L(" Start CCmsServerAsyncContact::DoGetPhonebookDataLC()" ) );
       
   692     
       
   693     RArray<TInt> defaultAttributeArray;
       
   694     CleanupClosePushL( defaultAttributeArray );
       
   695     CDesCArrayFlat* itemArray = new ( ELeave ) CDesCArrayFlat( 5 );
       
   696     CleanupStack::PushL( itemArray );    
       
   697     CDesCArrayFlat* infoArray = new ( ELeave ) CDesCArrayFlat( 5 );
       
   698     CleanupStack::PushL( infoArray );    
       
   699     MCmsContactInterface& syncContact = iSyncContact;
       
   700     CCmsServerXSPContactHandler* xspHandler = iSyncContact.XSPHandler();
       
   701     const TInt xspCount( xspHandler ? xspHandler->ContactCount() : 0 );
       
   702     HandleOneContactL( *itemArray, *infoArray, defaultAttributeArray, aResourceId, syncContact.Contact() );   
       
   703     for( TInt i = 0; i < xspCount; i++ )
       
   704         {
       
   705         HandleOneContactL( *itemArray, *infoArray, defaultAttributeArray, aResourceId, *xspHandler->Contact( i ) );   
       
   706         }
       
   707     HBufC* retBuffer = ConstructStreamBufferL( *itemArray, *infoArray, defaultAttributeArray );   
       
   708         CleanupStack::PopAndDestroy( 3 ); 
       
   709     CleanupStack::PushL( retBuffer );
       
   710     PRINT( _L(" End CCmsServerAsyncContact::DoGetPhonebookDataLC()" ) );
       
   711     return retBuffer;  
       
   712     }
       
   713 
       
   714 // ----------------------------------------------------
       
   715 // CCmsServerAsyncContact::HandleOneContactL
       
   716 // 
       
   717 // ----------------------------------------------------
       
   718 //
       
   719 void CCmsServerAsyncContact::HandleOneContactL( CDesCArray& aItemArray, CDesCArray& aInfoArray,  RArray<TInt>& aDefaults,
       
   720                                                 TInt aResourceId, const MVPbkStoreContact& aContact )
       
   721     {
       
   722     PRINT( _L(" Start CCmsServerAsyncContact::HandleOneContactL()" ) );
       
   723     
       
   724     const TDesC& storeName = aContact.ParentStore().StoreProperties().Name().UriDes();    
       
   725     
       
   726     TInt index( 0 );
       
   727     const MVPbkFieldType* type = iContactManager->FieldTypes().Find( aResourceId );
       
   728     CVPbkBaseContactFieldTypeIterator* itr = CVPbkBaseContactFieldTypeIterator::NewLC( *type, aContact.Fields() );
       
   729     while( itr->HasNext() )
       
   730         {
       
   731         const MVPbkBaseContactField* field = itr->Next();
       
   732         HBufC* item = ParseContactFieldL( *field );
       
   733         CleanupStack::PushL( item );
       
   734         TPtrC descriptor( item->Des() );
       
   735         if( aItemArray.Find( descriptor, index ) != 0 )
       
   736             {
       
   737             aItemArray.AppendL( descriptor );
       
   738             aInfoArray.AppendL( storeName );  
       
   739             //Reading default attributes.
       
   740             aDefaults.Append( DefaultAttributesL( *field ) );
       
   741             }
       
   742         CleanupStack::PopAndDestroy();   //item
       
   743         }
       
   744     CleanupStack::PopAndDestroy();  //itr
       
   745     PRINT( _L(" End CCmsServerAsyncContact::HandleOneContactL()" ) );
       
   746     }
       
   747 
       
   748 // ----------------------------------------------------
       
   749 // CCmsServerAsyncContact::HandleOneContactL
       
   750 // 
       
   751 // ----------------------------------------------------
       
   752 //
       
   753 HBufC* CCmsServerAsyncContact::ConstructStreamBufferL( CDesCArray& aItemArray, CDesCArray& aInfoArray, RArray<TInt>& aDefaults )
       
   754     {
       
   755     PRINT( _L(" Start CCmsServerAsyncContact::ConstructStreamBufferL()" ) );
       
   756     
       
   757     RBuf16 descBuffer;
       
   758         TBuf<15> lengthBuf;
       
   759     descBuffer.Create( 12 );
       
   760     descBuffer.CleanupClosePushL();
       
   761     const TInt count( aItemArray.MdcaCount() );
       
   762     for( TInt i = 0; i < count; i++ )
       
   763         {
       
   764         lengthBuf.Zero();
       
   765         TPtrC item( aItemArray.MdcaPoint( i ) );
       
   766         TPtrC info( aInfoArray.MdcaPoint( i ) );
       
   767         lengthBuf.AppendNum( item.Length() );
       
   768         lengthBuf.Append( KDelimiter );
       
   769         lengthBuf.AppendNum( info.Length() );
       
   770         lengthBuf.Append( KDelimiter );
       
   771         lengthBuf.AppendNum( aDefaults[i] );
       
   772         lengthBuf.Append( KDelimiter );
       
   773         PRINT3(_L( "Item [%d]: %S - Defaults: %W" ), i, &item, aDefaults[i] );
       
   774         User::LeaveIfError( descBuffer.ReAlloc( descBuffer.Length() + item.Length() + info.Length() + lengthBuf.Length() ) );
       
   775         descBuffer.Append( lengthBuf );
       
   776         descBuffer.Append( item );
       
   777         descBuffer.Append( info );
       
   778         }
       
   779     HBufC* retBuffer = descBuffer.AllocL();
       
   780     CleanupStack::PopAndDestroy();  //descBuffer
       
   781     PRINT( _L(" End CCmsServerAsyncContact::ConstructStreamBufferL()" ) );
       
   782     return retBuffer;
       
   783     }
       
   784 
       
   785 // ----------------------------------------------------
       
   786 // CCmsServerAsyncContact::ParseContactFieldL
       
   787 // 
       
   788 // ----------------------------------------------------
       
   789 //
       
   790 HBufC* CCmsServerAsyncContact::ParseContactFieldL( const MVPbkBaseContactField& aField )
       
   791     {
       
   792     HBufC* buffer = NULL;
       
   793     const TInt KMatchPriority = 0;
       
   794     const MVPbkFieldType* type = aField.MatchFieldType( KMatchPriority );
       
   795     if( EFetchPhonebookUriData == iAsyncOperation || R_VPBK_FIELD_TYPE_IMPP == type->FieldTypeResId() )
       
   796         {   
       
   797         const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast( aField.FieldData() );
       
   798         buffer = uri.Uri().AllocL(); 
       
   799         }
       
   800     else if( CCmsServerAsyncContact::EFetchPhonebookDateTimeData == iAsyncOperation )
       
   801         {
       
   802         TLocale locale;
       
   803         TBuf<256> dateBuffer;
       
   804         const MVPbkContactFieldDateTimeData& date = MVPbkContactFieldDateTimeData::Cast( aField.FieldData() );
       
   805         TTime time( date.DateTime() );
       
   806         time.FormatL( dateBuffer, KDateFormat, locale );
       
   807         buffer = HBufC::NewL( dateBuffer.Length() );
       
   808         buffer->Des().Copy( dateBuffer );
       
   809         }
       
   810     else
       
   811         {
       
   812         const MVPbkContactFieldTextData& text = MVPbkContactFieldTextData::Cast( aField.FieldData() );
       
   813         buffer = text.Text().AllocL();         
       
   814         }
       
   815     return buffer;
       
   816     }
       
   817 
       
   818 // ----------------------------------------------------
       
   819 // CCmsServerAsyncContact::DoGetFullNameDataLC
       
   820 // 
       
   821 // ----------------------------------------------------
       
   822 //
       
   823 HBufC* CCmsServerAsyncContact::DoGetFullNameDataLC()
       
   824     {
       
   825     RBuf16 descBuffer;
       
   826     TBuf<15> lengthBuf;
       
   827     _LIT( KDelimiter, " " );
       
   828     descBuffer.Create( 12 );
       
   829     descBuffer.CleanupClosePushL();
       
   830     MCmsContactInterface& syncContact = iSyncContact;    
       
   831     const MVPbkStoreContact& contact = syncContact.Contact();
       
   832     
       
   833     //Creating full name. 
       
   834     HBufC* fullname = iNameFormatter->GetContactTitleL
       
   835             ( contact.Fields(),
       
   836               MPbk2ContactNameFormatter::EPreserveLeadingSpaces |
       
   837               MPbk2ContactNameFormatter::EUseSeparator );
       
   838     CleanupStack::PushL( fullname );
       
   839 
       
   840     //Creating info string
       
   841     const TDesC& storeName = contact.ParentStore().StoreProperties().Name().UriDes();    
       
   842     
       
   843     //CREATING SENDING PROTOCOL
       
   844     //Create msg to client side
       
   845     lengthBuf.Zero();
       
   846     HBufC* item = fullname->Des().AllocL();
       
   847     CleanupStack::PopAndDestroy( fullname );   //fullname
       
   848     CleanupStack::PushL( item );    
       
   849     
       
   850     TPtr descriptor( item->Des() );
       
   851     lengthBuf.AppendNum( descriptor.Length() );
       
   852     lengthBuf.Append( KDelimiter );                     
       
   853 
       
   854     //Adding info length                            ?
       
   855     lengthBuf.AppendNum( storeName.Length() );
       
   856     lengthBuf.Append( KDelimiter );    
       
   857     
       
   858     //Adding attribute to protocol, No attributes for fullname
       
   859     lengthBuf.AppendNum( 0 );
       
   860     lengthBuf.Append( KDelimiter );
       
   861             
       
   862     User::LeaveIfError( descBuffer.ReAlloc( descBuffer.Length() + descriptor.Length() + storeName.Length()+ lengthBuf.Length() ) );
       
   863     descBuffer.Append( lengthBuf );
       
   864     descBuffer.Append( descriptor );
       
   865     descBuffer.Append( storeName );    
       
   866     CleanupStack::PopAndDestroy();   //item
       
   867 
       
   868     HBufC* retBuffer = descBuffer.AllocL();
       
   869 
       
   870     CleanupStack::PopAndDestroy( 1 );  //descBuffer
       
   871     CleanupStack::PushL( retBuffer );
       
   872         
       
   873     return retBuffer;
       
   874     }
       
   875 
       
   876 
       
   877 // ----------------------------------------------------
       
   878 // CCmsServerAsyncContact::AppendToBufferL
       
   879 // 
       
   880 // ----------------------------------------------------
       
   881 // 
       
   882 void CCmsServerAsyncContact::AppendToBufferL( RBuf16& aBuffer, const TDesC& aDescriptor,
       
   883                                               CCmsContactFieldItem::TCmsContactField aFieldType )
       
   884     {
       
   885     PRINT( _L(" Start CCmsServerAsyncContact::AppendToBufferL()" ) );
       
   886     
       
   887     RBuf tempBuffer;
       
   888     TBuf<32> typeBuf;
       
   889     TBuf<32> lengthBuf;
       
   890     _LIT( KDelimiter, " " );
       
   891     tempBuffer.Create( KDefaultBufferSize );
       
   892     tempBuffer.CleanupClosePushL();
       
   893     if( 0 < aDescriptor.Length() )
       
   894         {
       
   895         typeBuf.Zero();
       
   896         typeBuf.AppendNum( aFieldType );
       
   897         typeBuf.Append( KDelimiter );
       
   898         tempBuffer.ReAllocL( typeBuf.Length() + aDescriptor.Length() );
       
   899         tempBuffer.Append( typeBuf );
       
   900         tempBuffer.Append( aDescriptor );
       
   901         lengthBuf.Zero();
       
   902         lengthBuf.AppendNum( tempBuffer.Length() );
       
   903         lengthBuf.Append( KDelimiter );
       
   904         aBuffer.ReAllocL( aBuffer.Length() + tempBuffer.Length() + lengthBuf.Length() );
       
   905         aBuffer.Append( lengthBuf );
       
   906         aBuffer.Append( tempBuffer );
       
   907         }
       
   908     CleanupStack::PopAndDestroy();  //tempBuffer
       
   909     PRINT( _L("End CCmsServerAsyncContact::AppendToBufferL()" ) );
       
   910     }
       
   911 
       
   912 // ----------------------------------------------------
       
   913 // CCmsServerAsyncContact::ContactInfoArrayL
       
   914 // 
       
   915 // ----------------------------------------------------
       
   916 // 
       
   917 CDesCArrayFlat* CCmsServerAsyncContact::ContactInfoArrayLC()
       
   918     {
       
   919     PRINT( _L(" Start CCmsServerAsyncContact::ContactInfoArrayL()" ) );
       
   920     
       
   921     CDesCArrayFlat* idArray = new ( ELeave ) CDesCArrayFlat( 5 );
       
   922     CleanupStack::PushL( idArray );
       
   923     CDesCArrayFlat* email = ContactDataTextLC( CCmsContactFieldItem::ECmsGroupEmail );  
       
   924     AppendFieldsL( *email, *idArray );
       
   925     CleanupStack::PopAndDestroy();  //email
       
   926     CDesCArrayFlat* voip = ContactDataTextLC( CCmsContactFieldItem::ECmsGroupVoIP );
       
   927     AppendFieldsL( *voip, *idArray );
       
   928     CleanupStack::PopAndDestroy();  //voip
       
   929     PhonebookDataL( R_VPBK_FIELD_TYPE_IMPP, *idArray );
       
   930     PRINT( _L(" End CCmsServerAsyncContact::ContactInfoArrayL()" ) );
       
   931     return idArray;
       
   932     }
       
   933 
       
   934 // ----------------------------------------------------
       
   935 // CCmsServerAsyncContact::AppendFieldsL
       
   936 // 
       
   937 // ----------------------------------------------------
       
   938 //
       
   939 void CCmsServerAsyncContact::AppendFieldsL( const CDesCArrayFlat& aSource, CDesCArrayFlat& aTarget )
       
   940     {
       
   941     PRINT( _L(" Start CCmsServerAsyncContact::AppendFieldsL()" ) );
       
   942     
       
   943     const TInt count = aSource.MdcaCount();
       
   944     for( TInt i = 0; i < count; i++ )
       
   945         {
       
   946         aTarget.AppendL( aSource.MdcaPoint( i ) );
       
   947         }
       
   948     PRINT( _L(" Start CCmsServerAsyncContact::AppendFieldsL()" ) );    
       
   949     }
       
   950 
       
   951 // ----------------------------------------------------
       
   952 // CCmsServerAsyncContact::RunL
       
   953 // 
       
   954 // ----------------------------------------------------
       
   955 //
       
   956 void CCmsServerAsyncContact::RunL()
       
   957     {
       
   958     switch( iAsyncOperation )
       
   959         {
       
   960         case ENone:
       
   961             {
       
   962             break;
       
   963             }
       
   964         case EFetchEnabledFields:
       
   965             {
       
   966             MCmsContactInterface& syncContact = iSyncContact;
       
   967             HBufC* fields = GetEnabledFieldsLC();
       
   968             syncContact.HandleEnabledFields( fields ) ? 
       
   969    	            CleanupStack::PopAndDestroy() : CleanupStack::Pop();  //fields
       
   970             break;
       
   971             }
       
   972         case EFetchPhonebookTextData:
       
   973         case EFetchPhonebookUriData:
       
   974         case EFetchPhonebookDateTimeData:
       
   975             {
       
   976             MCmsContactInterface& syncContact = iSyncContact;
       
   977             CCmsContactFieldItem::TCmsContactField field =
       
   978                 ( CCmsContactFieldItem::TCmsContactField )iStatus.Int();
       
   979             HBufC* data = DoGetDataLC( CmsServerUtils::MatchFieldType( field ) );
       
   980             syncContact.HandleField( data ) ? 
       
   981                 CleanupStack::PopAndDestroy() : CleanupStack::Pop();  //data
       
   982             break;
       
   983             }
       
   984         case EFetchPhonebookBinData:
       
   985             {
       
   986             MCmsContactInterface& syncContact = iSyncContact;
       
   987             CCmsContactFieldItem::TCmsContactField field =
       
   988                 ( CCmsContactFieldItem::TCmsContactField )iStatus.Int();
       
   989             HBufC8* data = ContactDataBinaryL( CmsServerUtils::MatchFieldType( field ) );
       
   990             CleanupStack::PushL( data );
       
   991             syncContact.HandleField( data ) ? 
       
   992                 CleanupStack::PopAndDestroy() : CleanupStack::Pop();  //data
       
   993             break;
       
   994             }
       
   995         case EFetchPresenceData:
       
   996             {
       
   997             MBPASObserver* observer = &iSyncContact;
       
   998             CBPAS& presence( iSyncContact.BPASHandle() );
       
   999             presence.SetObserver( observer );
       
  1000             CDesCArrayFlat* infoArray = ContactInfoArrayLC();
       
  1001             presence.GiveInfosL( *infoArray );
       
  1002             infoArray->Delete( 0, infoArray->MdcaCount() );
       
  1003             CleanupStack::PopAndDestroy();  //infoArray
       
  1004             break;
       
  1005             }
       
  1006         default:
       
  1007             {
       
  1008             break;
       
  1009             }
       
  1010         }
       
  1011     }
       
  1012 
       
  1013 // ----------------------------------------------------
       
  1014 // CCmsServerAsyncContact::DoCancel
       
  1015 // 
       
  1016 // ----------------------------------------------------
       
  1017 //
       
  1018 void CCmsServerAsyncContact::DoCancel()
       
  1019     {
       
  1020     }
       
  1021 
       
  1022 // ----------------------------------------------------
       
  1023 // CCmsServerAsyncContact::RunError
       
  1024 // 
       
  1025 // ----------------------------------------------------
       
  1026 //
       
  1027 TInt CCmsServerAsyncContact::RunError( TInt aError )
       
  1028     {
       
  1029     //Handle error 
       
  1030     MCmsContactInterface& syncContact = iSyncContact;
       
  1031     syncContact.HandleError( aError );
       
  1032     return KErrNone;
       
  1033     }
       
  1034 
       
  1035 
       
  1036 
       
  1037 // End of File