simpledatamodeladapter/src/presencepluginxdmutils.cpp
changeset 0 c8caa15ef882
child 6 aca99fb8a3dd
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006-2010 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:  IETF SIMPLE Protocol implementation for XIMP Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <utf.h>
       
    21 #include <e32test.h>
       
    22 #include <ximpobjectfactory.h>
       
    23 #include <presenceobjectfactory.h>
       
    24 #include <ximpidentity.h>
       
    25 #include <ximpobjectcollection.h>
       
    26 #include <presentitygroupinfo.h>
       
    27 #include <presentitygroupmemberinfo.h>
       
    28 #include <xdmengine.h>
       
    29 #include <xdmdocument.h>
       
    30 #include <xdmprotocolinfo.h>
       
    31 #include <xdmdocumentnode.h>
       
    32 #include <xdmnodeattribute.h>
       
    33 #include <xdmerrors.h>
       
    34 #include <pressettingsapi.h> //for TPresSettingsSet
       
    35 #include <XdmSettingsApi.h>
       
    36 #include <XdmProtocolUidList.h>
       
    37 #include <avabilitytext.h>
       
    38 
       
    39 #include "presencepluginxdmpresrules.h"
       
    40 #include "mpresencepluginconnectionobs.h"
       
    41 #include "presenceplugincommon.h"
       
    42 #include "presencepluginxdmutils.h"
       
    43 #include "presencepluginvirtualgroup.h"
       
    44 #include "presencepluginauthorization.h"
       
    45 #include "presenceplugindata.h"
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CPresencePluginXdmUtils::CPresencePluginXdmUtils()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CPresencePluginXdmUtils::CPresencePluginXdmUtils(  
       
    54 	MPresencePluginConnectionObs& aObs , TInt aXmdId, TBool aLocalmode )
       
    55     : CActive( CActive::EPriorityStandard ),
       
    56     iConnObs(aObs), iSettingsId(aXmdId),
       
    57     iXdmState(EStateIdle), iOperation( ENoOperation ),
       
    58 	iPresXdmOk( EFalse ), iXdmOk( EFalse ),
       
    59 	iRulesUpdateState(EStateNoOperation), iLocalMode( aLocalmode )
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CPresencePluginXdmUtils::ConstructL()
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CPresencePluginXdmUtils::ConstructL( )
       
    69     {
       
    70     
       
    71     //If we are in normalmode we need presence rules too
       
    72     if ( !iLocalMode )
       
    73         {
       
    74         DP_SDA("CPresencePluginXdmUtils::ConstructL NormalMode");
       
    75         iXdmPresRules = CPresencePluginXdmPresRules::NewL( 
       
    76             iSettingsId, EFalse );
       
    77         }
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CPresencePluginXdmUtils::NewL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CPresencePluginXdmUtils* CPresencePluginXdmUtils::NewL(
       
    85     MPresencePluginConnectionObs& aObs, TInt aXmdId, TBool aLocalmode )
       
    86     {
       
    87     CPresencePluginXdmUtils* self =
       
    88     	new( ELeave ) CPresencePluginXdmUtils( aObs, aXmdId, aLocalmode );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL(   );
       
    91     CleanupStack::Pop( self );
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CPresencePluginXdmUtils::~CPresencePluginXdmUtils()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CPresencePluginXdmUtils::~CPresencePluginXdmUtils()
       
   100     {
       
   101     DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils");
       
   102     if ( iXdmDoc )
       
   103         {
       
   104         DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils 1");
       
   105         if (iXdmEngine)
       
   106             {
       
   107             DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils del doc");
       
   108             TRAP_IGNORE( iXdmEngine->DeleteDocumentModelL( iXdmDoc ));
       
   109             }
       
   110         }
       
   111         
       
   112     DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils 3");
       
   113     delete iXdmEngine;
       
   114     iXdmEngine = NULL;
       
   115 
       
   116 
       
   117     DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils 4");
       
   118     delete iXdmPresRules;
       
   119     iXdmPresRules = NULL;
       
   120 
       
   121 
       
   122     DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils 5");
       
   123     delete iEntityUri;
       
   124     iEntityUri = NULL;
       
   125 
       
   126     iBlockedContacts.ResetAndDestroy();
       
   127 
       
   128     DP_SDA("CPresencePluginXdmUtils::~CPresencePluginXdmUtils end"); 
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CPresencePluginXdmUtils::InitializeXdmL()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CPresencePluginXdmUtils::InitializeXdmL( TRequestStatus& aStatus )
       
   136     {
       
   137     DP_SDA("CPresencePluginXdmUtils::InitializeXdmL");
       
   138     
       
   139     aStatus = KRequestPending;
       
   140 	iClientStatus = &aStatus;
       
   141     
       
   142 	// if resource-list not ready
       
   143     if ( !iXdmOk ) 
       
   144         {
       
   145         DP_SDA("CPresencePluginXdmUtils::InitializeXdmL !iXdmOk");
       
   146         if ( !iLocalMode )
       
   147             {
       
   148             DP_SDA("CPresencePluginXdmUtils::InitializeXdmL NormalMode");
       
   149             GetXdmListsL( ETrue, EFalse );
       
   150             }
       
   151         else
       
   152             {
       
   153             DP_SDA("CPresencePluginXdmUtils::InitializeXdmL LocalMode");
       
   154             GetXdmListsL( ETrue, ETrue );
       
   155             }
       
   156         }
       
   157     else if ( !iPresXdmOk && !iLocalMode )
       
   158         {
       
   159         DP_SDA("CPresencePluginXdmUtils::InitializeXdmL  !iPresXdmOk");
       
   160         GetXdmRulesL();  
       
   161         }
       
   162     else
       
   163         {
       
   164         DP_SDA("CPresencePluginXdmUtils::InitializeXdmL All is OK ");
       
   165         // All is ok
       
   166         DP_SDA("CPresencePluginXdmUtils::InitializeXdmL SEND COMPLETE")        
       
   167         CompleteClientReq( KErrNone );
       
   168         }
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CPresencePluginXdmUtils::InitializeXdmL()
       
   173 // ---------------------------------------------------------------------------
       
   174 //    
       
   175 void CPresencePluginXdmUtils::InitializePresRulesL( )
       
   176     {
       
   177     DP_SDA("CPresencePluginXdmUtils:: MakeInitialRules");
       
   178     iXdmState = ECreateXdmRules;
       
   179 	iRulesUpdateState = EStateInitializeRules;
       
   180     iXdmPresRules->MakeInitialRulesDocumentL( this );
       
   181     UpdateXdmRulesL();
       
   182     DP_SDA("CPresencePluginXdmUtils:: MakeInitialRules done");
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CPresencePluginXdmUtils::GetXdmRulesL()
       
   187 // ---------------------------------------------------------------------------
       
   188 //    
       
   189 void CPresencePluginXdmUtils::GetXdmRulesL()
       
   190     {
       
   191     DP_SDA("CPresencePluginXdmUtils:: GetXdmRulesL");
       
   192 
       
   193 	if ( !iXdmPresRules )
       
   194 		{
       
   195     // get data from a network if not done so yet
       
   196 		if ( !iLocalMode )
       
   197 			{
       
   198 			iXdmPresRules = CPresencePluginXdmPresRules::NewL( 
       
   199 				iSettingsId, EFalse );
       
   200 			}
       
   201 		else
       
   202 			{
       
   203 			/*localmode*/
       
   204 			//iXdmPresRules 
       
   205 			//= CPresencePluginXdmPresRules::NewL( iSettingsId, ETrue );
       
   206 			}
       
   207 		}
       
   208     
       
   209 	if( !iLocalMode && iXdmPresRules )
       
   210 	    {
       
   211 	    User::LeaveIfError( iXdmPresRules->UpdateFromServerL( this ));
       
   212 	    }
       
   213     iXdmState = EGetXdmRules;
       
   214     DP_SDA("CPresencePluginXdmUtils:: GetXdmRulesL done");
       
   215     DP_SDA("CPresencePluginXdmUtils::GetXdmRulesL - add buddies to virtual");
       
   216     AddIdentityToVirtualListL( KPresenceBuddyList );
       
   217     
       
   218     DP_SDA("CPresencePluginXdmUtils::GetXdmRulesL - add blocked to virtual");
       
   219     AddIdentityToVirtualListL( KPresenceBlockedList );
       
   220     }
       
   221         
       
   222 // ---------------------------------------------------------------------------
       
   223 // CPresencePluginXdmUtils::InitializeXdmsOnlyL()
       
   224 // ---------------------------------------------------------------------------
       
   225 //   
       
   226 void CPresencePluginXdmUtils::InitializeXdmsOnlyL( TRequestStatus& aStatus )
       
   227     {
       
   228     DP_SDA("CPresencePluginXdmUtils::InitializeXdmsOnlyL");             
       
   229 	aStatus = KRequestPending;
       
   230     iClientStatus = &aStatus;
       
   231 
       
   232     if ( !iXdmOk )
       
   233         {
       
   234         DP_SDA("CPresencePluginXdmUtils::InitializeXdmsOnlyL 1");
       
   235         GetXdmListsL( EFalse, EFalse );        
       
   236         }
       
   237     else
       
   238         {
       
   239         DP_SDA("CPresencePluginXdmUtils::InitializeXdmsOnlyL all ok");
       
   240         // All is ok
       
   241         DP_SDA("CPresencePluginXdmUtils::InitializeXdmsOnlyL SEND COMPLETE")        
       
   242         CompleteClientReq( KErrNone );
       
   243         }
       
   244     DP_SDA("CPresencePluginXdmUtils::InitializeXdmsOnlyL end");
       
   245     }
       
   246         
       
   247 // ---------------------------------------------------------------------------
       
   248 // CPresencePluginXdmUtils::CheckXdmDoc()
       
   249 // ---------------------------------------------------------------------------
       
   250 //    
       
   251 TBool CPresencePluginXdmUtils::CheckXdmDoc()
       
   252     {
       
   253     DP_SDA("CPresencePluginXdmUtils::CheckXdmDoc");
       
   254     
       
   255     if ( iXdmDoc )
       
   256         {
       
   257         CXdmDocumentNode* root = iXdmDoc->DocumentRoot();
       
   258         DP_SDA("CPresencePluginXdmUtils::CheckXdmDoc2");
       
   259         if( root )
       
   260         	{	
       
   261             TInt count = root->NodeCount();
       
   262             DP_SDA2("CPresencePluginXdmUtils::CheckXdmDoc count %d", count);
       
   263             if ( !count )
       
   264                 {
       
   265                 DP_SDA("CPresencePluginXdmUtils::CheckXdmDoc NotFound");
       
   266                 iXdmOk = EFalse;
       
   267                 }
       
   268             else
       
   269                 {
       
   270                 DP_SDA("CPresencePluginXdmUtils::CheckXdmDoc file ok");
       
   271                 iXdmOk = ETrue;
       
   272                 }
       
   273         	}
       
   274         }
       
   275     else
       
   276         {
       
   277         DP_SDA("CPresencePluginXdmUtils::CheckXdmDoc file False");
       
   278         iXdmOk = EFalse;
       
   279         }
       
   280     
       
   281     return iXdmOk;
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CPresencePluginXdmUtils::CheckIfError
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 TInt CPresencePluginXdmUtils::CheckIfErrorL( TInt aMyStatus )
       
   289     {
       
   290     TInt myStatus = aMyStatus;
       
   291     DP_SDA2("CPresencePluginXdmUtils::CheckIfError ErrorCode %d ", myStatus);
       
   292     if ( myStatus == KErrTimedOut )
       
   293         {
       
   294         DP_SDA("CPresencePluginXdmUtils::CheckIfError  TimeOut error");
       
   295         myStatus = KErrTimedOut;
       
   296         User::Leave( KErrTimedOut );
       
   297         }
       
   298     else if ( myStatus == KErrCouldNotConnect || 
       
   299     	myStatus == KXcapErrorNetworkNotAvailabe )
       
   300         {
       
   301         DP_SDA("CheckIfError KErrCouldNotConnect error");
       
   302         myStatus = aMyStatus;
       
   303         }
       
   304 	else if ( myStatus == KXcapErrorHttpNotFound )
       
   305 		{
       
   306 		DP_SDA("CheckIfError KXcapErrorHttpNotFound");
       
   307         myStatus = aMyStatus;
       
   308 		}
       
   309     else if ( myStatus == KXcapErrorAuthentication )
       
   310         {
       
   311         DP_SDA("CPresencePluginXdmUtils::CheckIfError auth error");                        
       
   312         myStatus = aMyStatus;
       
   313         }
       
   314     else if ( myStatus == KXcapErrorTooManyOccurencies )
       
   315         {
       
   316         DP_SDA("CPresencePluginXdmUtils KXcapErrorTooManyOccurencies");                        
       
   317         myStatus = 0;
       
   318         }
       
   319     else if( myStatus == KErrDisconnected )
       
   320         {
       
   321         myStatus = aMyStatus;
       
   322         User::Leave( KErrCancel );
       
   323         }
       
   324     else if( myStatus == KXcapErrorHttpPrecondFailed )
       
   325     	{
       
   326     	DP_SDA("CheckIfError KXcapErrorHttpPrecondFailed");
       
   327         myStatus = aMyStatus;
       
   328     	}
       
   329     else if ( KErrNoMemory == myStatus )
       
   330         {
       
   331         DP_SDA("CheckIfError KErrNoMemory");
       
   332         User::Leave( KErrNoMemory );
       
   333         }
       
   334     else
       
   335         {
       
   336         DP_SDA("CPresencePluginXdmUtils::CheckIfError ERROR");
       
   337         myStatus = aMyStatus;
       
   338         }
       
   339     return myStatus;
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // CPresencePluginXdmUtils::RunL()
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 void CPresencePluginXdmUtils::RunL(  )
       
   347     {    
       
   348     DP_SDA("CPresencePluginXdmUtils::RunL");    
       
   349     TPluginXdmState origState = iXdmState;
       
   350     iXdmState = EStateIdle;
       
   351     TInt myStatus = iStatus.Int();
       
   352     
       
   353     DP_SDA2("CPresencePluginXdmUtils::RunL mystatus %d ", myStatus);
       
   354     DP_SDA2("CPresencePluginXdmUtils::RunL state %d ", origState);
       
   355     DP_SDA2("CPresencePluginXdmUtils:: ClientStatus %d",iClientStatus->Int() );
       
   356     
       
   357     if ( myStatus == KErrCancel )
       
   358         {
       
   359         DP_SDA("CPresencePluginXdmUtils::RunL CANCEL SEND COMPLETE")
       
   360         CompleteClientReq( KErrCancel );
       
   361         }
       
   362     
       
   363     switch ( origState )
       
   364         {
       
   365         case EGetXdmLists:
       
   366 		case EGetXdmListsOnly:
       
   367             {
       
   368             DoGetXdmListsL( myStatus, origState );
       
   369             }
       
   370         break;
       
   371                 
       
   372         case ECreateXdmLists:
       
   373             {
       
   374             DoCreateXdmListsL( myStatus, origState, EFalse );
       
   375             }
       
   376         break;
       
   377         
       
   378         case ECreateXdmListsOnly:
       
   379             {
       
   380             DoCreateXdmListsL( myStatus, origState, ETrue );
       
   381             }
       
   382         break;
       
   383           
       
   384         case EGetXdmBlockList:
       
   385             {
       
   386             DP_SDA("RunL EGetXdmBlockList SEND COMPLETE");
       
   387             CompleteClientReq( KErrNone );
       
   388             }
       
   389         break;
       
   390         
       
   391         case EUpdateXdmList:
       
   392             {
       
   393             DoUpdateXdmListsL( myStatus, origState );
       
   394             }
       
   395         break;
       
   396 
       
   397         case EUpdateBlockedContactPresenceCache:
       
   398             DoUpdateBlockedContactPresenceCacheL( myStatus );
       
   399             break;
       
   400 
       
   401         default:
       
   402             {
       
   403             DP_SDA("CPresencePluginXdmUtils::RunL last else");        
       
   404             //check myStatus error
       
   405             myStatus = CheckIfErrorL( myStatus );
       
   406                 
       
   407             if ( myStatus )
       
   408                 {
       
   409                 // complete reqular request
       
   410                 DP_SDA("CPresencePluginXdmUtils::RunL SEND LAST COMPLETE");
       
   411                 CompleteClientReq( myStatus );
       
   412                 }
       
   413             DP_SDA("CPresencePluginXdmUtils::RunL default end")
       
   414             }
       
   415         break;
       
   416           
       
   417         }
       
   418     DP_SDA("CPresencePluginXdmUtils::RunL end");
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // CPresencePluginXdmUtils::DoUpdateXdmLists()
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CPresencePluginXdmUtils::DoUpdateXdmListsL( 
       
   426     TInt aMyStatus,
       
   427     TPluginXdmState /*aOrigState*/)
       
   428     {
       
   429     DP_SDA("CPresencePluginXdmUtils::DoUpdateXdmLists EUpdateXdmList");
       
   430     if ( !iLocalMode )
       
   431         {
       
   432         DP_SDA("CPresencePluginXdmUtils::DoUpdateXdmLists updaterules");
       
   433         if( aMyStatus )
       
   434         	{
       
   435         	DP_SDA("DoUpdateXdmLists updaterules error");
       
   436         	aMyStatus = CheckIfErrorL( aMyStatus );
       
   437         	CompleteClientReq( aMyStatus );
       
   438         	}
       
   439         else
       
   440         	{
       
   441         	DP_SDA("DoUpdateXdmLists updaterules else");	 
       
   442         	UpdateXdmRulesL();
       
   443         	}
       
   444         }
       
   445     else
       
   446         {
       
   447         DP_SDA("EUpdateXdmList LOCALMODE SEND COMPLETE");
       
   448         aMyStatus = CheckIfErrorL( aMyStatus );
       
   449         CompleteClientReq( aMyStatus );
       
   450         } 
       
   451     iRulesUpdateState = EStateNoOperation;
       
   452     DP_SDA("CPresencePluginXdmUtils::DoUpdateXdmLists EUpdateXdmList end");
       
   453     }
       
   454     
       
   455 // ---------------------------------------------------------------------------
       
   456 // CPresencePluginXdmUtils::DoCreateXdmLists()
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 void CPresencePluginXdmUtils::DoCreateXdmListsL( 
       
   460     TInt aMyStatus,
       
   461     TPluginXdmState /*aOrigState*/,
       
   462     TBool aOnlyResourceList )
       
   463     {
       
   464     DP_SDA("CPresencePluginXdmUtils::DoCreateXdmListsL ECreateXdmLists");
       
   465     //check myStatus error
       
   466     aMyStatus = CheckIfErrorL( aMyStatus );
       
   467     if( !aOnlyResourceList )
       
   468         {
       
   469         if ( aMyStatus )
       
   470             {
       
   471             DP_SDA("DoCreateXdmLists ECreateXdmLists SEND COMPLETE");
       
   472             CompleteClientReq( aMyStatus );
       
   473             }
       
   474         else if ( !iLocalMode )
       
   475             {
       
   476             DP_SDA("ECreateXdmLists !myStatus GetXdmRules");
       
   477             iXdmOk = ETrue;
       
   478             GetXdmRulesL();
       
   479             }
       
   480         else if ( iLocalMode )
       
   481             {
       
   482             DP_SDA("DoCreateXdmLists ECreateXdmLists SEND COMPLETE 2");
       
   483             iXdmOk = ETrue;
       
   484             CompleteClientReq( aMyStatus );
       
   485             }
       
   486         }
       
   487     else
       
   488         {
       
   489         //check myStatus error
       
   490         aMyStatus = CheckIfErrorL( aMyStatus );     
       
   491         if ( aMyStatus == KErrTimedOut  )
       
   492             { 
       
   493             DP_SDA("DoCreateXdmLists EGetXdmListsOnly 1");
       
   494             aMyStatus = 0;
       
   495             }           
       
   496         if ( !aMyStatus )
       
   497             {
       
   498             DP_SDA("DoCreateXdmLists EGetXdmListsOnly 2");
       
   499             iXdmOk = ETrue;
       
   500             }
       
   501         
       
   502         if( !(KXcapErrorNetworkNotAvailabe == aMyStatus || 
       
   503               KErrCouldNotConnect == aMyStatus ) )
       
   504             {
       
   505             DP_SDA("DoCreateXdmLists EGetXdmListsOnly SEND COMPLETE");
       
   506             CompleteClientReq( aMyStatus );
       
   507             }
       
   508         }
       
   509     DP_SDA("CPresencePluginXdmUtils::DoCreateXdmListsL ECreateXdmLists end");
       
   510     }
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 // CPresencePluginXdmUtils::DoGetXdmLists()
       
   514 // ---------------------------------------------------------------------------
       
   515 //
       
   516 void CPresencePluginXdmUtils::DoGetXdmListsL( 
       
   517     TInt aMyStatus,
       
   518     TPluginXdmState aOrigState )
       
   519     {
       
   520     DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists EGetXdmLists");
       
   521     //check myStatus error
       
   522     aMyStatus = CheckIfErrorL( aMyStatus );
       
   523 
       
   524     if ( aMyStatus )//Check is file includes nodes
       
   525         {
       
   526         DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists CreateXDM");
       
   527         // no resource-list, let's start to create it.
       
   528         CreateXdmListsL( ETrue );
       
   529         }
       
   530     else
       
   531         {
       
   532         DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists EGetXdmLists else");
       
   533         if( iLocalMode )
       
   534             {
       
   535             //Check if document empty
       
   536             TBool empty = CheckXdmDoc();
       
   537             if( !empty )
       
   538                 {
       
   539                 CreateXdmListsL( ETrue );
       
   540                 }
       
   541             else
       
   542                 {
       
   543                 iXdmOk = ETrue;
       
   544                 DP_SDA("DoGetXdmLists Localmode SEND COMPLETE"); 
       
   545                 CompleteClientReq( KErrNone );
       
   546                 }
       
   547             }
       
   548         else
       
   549             {
       
   550             iXdmOk = ETrue;
       
   551             if ( !iPresXdmOk && !iLocalMode && aOrigState == EGetXdmLists )
       
   552                 {
       
   553                 DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists GetXDM");
       
   554                 GetXdmRulesL();
       
   555                 }
       
   556             else
       
   557                 {
       
   558                 DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists SEND COMPLETE"); 
       
   559                 CompleteClientReq( KErrNone );
       
   560                 }
       
   561             }
       
   562         }
       
   563     DP_SDA("CPresencePluginXdmUtils::DoGetXdmLists end");
       
   564     }
       
   565     
       
   566 // ---------------------------------------------------------------------------
       
   567 // CPresencePluginXdmUtils::DoCancel()
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 void CPresencePluginXdmUtils::DoCancel( )
       
   571     {										  
       
   572     DP_SDA("CPresencePluginXdmUtils::DoCancel");
       
   573     iOperation = EXdmCancel;
       
   574 
       
   575     if ( iXdmState == EGetXdmLists || iXdmState == ECreateXdmLists ||
       
   576          iXdmState == EUpdateXdmRules || iXdmState == EUpdateXdmList ||
       
   577          iXdmState == EGetXdmBlockList || iXdmState == ECreateXdmRules ||
       
   578          iXdmState == ESubsBlockList || 
       
   579          iXdmState == EGetResourceListFromServer ||
       
   580          iXdmState == EGetXdmListsOnly || iXdmState == ECreateXdmListsOnly )
       
   581         {
       
   582         DP_SDA("CPresencePluginXdmUtils::DoCancel list get or create");
       
   583         iXdmState = ECancelDocument;
       
   584         iXdmEngine->CancelUpdate( iXdmDoc );
       
   585         // cancel presrules too
       
   586         iXdmPresRules->Cancel();
       
   587         }
       
   588     else
       
   589         {
       
   590         iStatus = KRequestPending;
       
   591         TRequestStatus* s= &iStatus;
       
   592         DP_SDA("CPresencePluginXdmUtils::DoCancel SEND COMPLETE");
       
   593         User::RequestComplete( s, KErrCancel );
       
   594         }
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // CPresencePluginXdmUtils::RunError()
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 TInt CPresencePluginXdmUtils::RunError( TInt aError )
       
   602     {
       
   603     DP_SDA("CPresencePluginXdmUtils::RunError");
       
   604     // complete the open request
       
   605     CompleteClientReq( aError );
       
   606     return KErrNone;
       
   607     }
       
   608 
       
   609 // ---------------------------------------------------------------------------
       
   610 // CPresencePluginXdmUtils::AddEntityToGrantedL()
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 void CPresencePluginXdmUtils::AddEntityToGrantedL(
       
   614     const TDesC&  aUri,
       
   615     TRequestStatus& aStatus )
       
   616     {
       
   617   	DP_SDA("CPresencePluginXdmUtils::AddEntityToGrantedL");
       
   618   	DP_SDA2("CPresencePluginXdmUtils::AddEntityToGrantedL, uri: %S", &aUri );
       
   619   	
       
   620   	TRAPD( err, iEntityUri =  aUri.AllocL() );
       
   621   	DP_SDA2(" AddEntityToGrantedL, uri alloc err: %d", err );
       
   622    
       
   623    //Add entity to virtualGroup
       
   624   	iConnObs.SubscribedContacts()->AddEntityL( iEntityUri->Des() );
       
   625   	
       
   626   	if ( !err )
       
   627   	    {
       
   628   	    DP_SDA("CPresencePluginXdmUtils::AddEntityToGrantedL !err");
       
   629   	    iXdmState = EUpdateXdmList;
       
   630         iClientStatus = &aStatus;
       
   631         iOperation = EXdmAddUserToGroup;
       
   632         iRulesUpdateState = EStateAddToWhiteList;
       
   633         
       
   634         //add user to resouce-list list
       
   635         DoAddUserToListL( KPresenceBuddyList, aUri );
       
   636         DP_SDA("CPresencePluginXdmUtils::AddEntityToGrantedL 1");
       
   637         UpdateXdmsL();
       
   638         
       
   639         *iClientStatus = KRequestPending;
       
   640         DP_SDA("CPresencePluginXdmUtils::AddEntityToGrantedL end");
       
   641   	    }
       
   642   	 else
       
   643   	    {
       
   644   	    DP_SDA("AddEntityToGrantedL else error SEND COMPLETE");
       
   645   	    //If error we can complete request
       
   646   	    CompleteClientReq( KErrNone );
       
   647   	    }
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 // CPresencePluginXdmUtils::AddEntityToBlockedL()
       
   652 // ---------------------------------------------------------------------------
       
   653 //
       
   654 void CPresencePluginXdmUtils::AddEntityToBlockedL(
       
   655     const TDesC&  aUri,
       
   656     TRequestStatus& aStatus )
       
   657     {
       
   658     DP_SDA("CPresencePluginXdmUtils::AddEntityToBlockedL");
       
   659     iClientStatus = &aStatus;
       
   660         
       
   661     if( iLocalMode )
       
   662         {
       
   663         //Block is not used in localmode
       
   664         DP_SDA("AddEntityToBlockedL localmode rules not support");
       
   665         CompleteClientReq( KErrNotSupported );
       
   666         }
       
   667     else
       
   668         {
       
   669         DP_SDA("CPresencePluginXdmUtils::AddEntityToBlockedL !localmode");
       
   670         TRAPD(err, iEntityUri =  aUri.AllocL() );
       
   671 		//Remove entity form subscribed virtual group
       
   672     	iConnObs.SubscribedContacts()->RemoveEntityL( iEntityUri->Des() );
       
   673     	
       
   674         if ( !err )
       
   675             {
       
   676             DP_SDA("CPresencePluginXdmUtils::AddEntityToBlockedL no error");
       
   677             iXdmState = EUpdateXdmList;
       
   678             iOperation = EXdmAddUserToGroup;
       
   679             iRulesUpdateState = EStateAddToBlockList;
       
   680 
       
   681             DoAddUserToListL( KPresenceBlockedList, aUri );
       
   682             UpdateXdmsL();
       
   683 
       
   684             *iClientStatus = KRequestPending;
       
   685             DP_SDA("CPresencePluginXdmUtils::AddEntityToBlockedL ready");
       
   686             }
       
   687         else
       
   688         	{
       
   689         	//If error we can complete request
       
   690         	DP_SDA("AddEntityToBlockedL SEND COMPLETE");
       
   691         	CompleteClientReq( KErrNone );
       
   692         	}
       
   693         }
       
   694     DP_SDA("CPresencePluginXdmUtils::AddEntityToBlockedL end");
       
   695     }
       
   696     
       
   697 // ---------------------------------------------------------------------------
       
   698 // CPresencePluginXdmUtils::DoAddUserToListL()
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 void CPresencePluginXdmUtils::DoAddUserToListL(
       
   702     const TDesC& aList,
       
   703     const TDesC&  aUri )
       
   704     {
       
   705     DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL");
       
   706     DP_SDA2("CPresencePluginXdmUtils::DoAddUserToListL aList: %S", &aList);
       
   707     DP_SDA2("CPresencePluginXdmUtils::DoAddUserToListL aUri: %S", &aUri);
       
   708     
       
   709     using namespace NPresencePlugin::NPresence;
       
   710      
       
   711     CXdmDocumentNode* root = iXdmDoc->DocumentRoot();
       
   712     CXdmDocumentNode* foundNode = SearchListUnderParentL( root, aList );
       
   713         
       
   714     if ( foundNode )
       
   715         {
       
   716         DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL found");
       
   717         if ( !CheckIfEnityExistL( aList, aUri ) )
       
   718             {
       
   719             DP_SDA("DoAddUserToListL entity not exist");
       
   720             if ( foundNode->IsEmptyNode() )
       
   721                 {
       
   722                 DP_SDA("DoAddUserToListL IsEmptyNode");
       
   723                 foundNode->SetEmptyNode( EFalse );
       
   724                 }
       
   725                 
       
   726 			DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL newNode");
       
   727             CXdmDocumentNode* newNode = 
       
   728                 foundNode->CreateChileNodeL( KPresenceEntry );
       
   729             DP_SDA("DoAddUserToListL entry attribute");    
       
   730             CXdmNodeAttribute* attributeEntryUri = 
       
   731                 newNode->CreateAttributeL( KPresenceUri );
       
   732             DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL set entry");    
       
   733             attributeEntryUri->SetAttributeValueL( aUri );
       
   734             DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL Append");
       
   735             iXdmDoc->AppendL( );
       
   736             }
       
   737         }
       
   738     else
       
   739         {
       
   740         DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL leave");
       
   741         User::Leave( KErrNotFound );
       
   742         }
       
   743 	DP_SDA("CPresencePluginXdmUtils::DoAddUserToListL end");
       
   744     }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // CPresencePluginXdmUtils::CheckIfEnityExistL
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 TBool CPresencePluginXdmUtils::CheckIfEnityExistL(
       
   751     const TDesC& aList,
       
   752     const TDesC&  aUri )
       
   753     {
       
   754     DP_SDA("CPresencePluginXdmUtils::CheckIfEnityExist");
       
   755     
       
   756     using namespace NPresencePlugin::NPresence;
       
   757     
       
   758     CXdmNodeAttribute* attr = NULL;
       
   759     RPointerArray<CXdmDocumentNode> nodes;
       
   760     CleanupClosePushL( nodes );
       
   761     TBool state( EFalse );
       
   762     
       
   763     CXdmDocumentNode* root = iXdmDoc->DocumentRoot();
       
   764     CXdmDocumentNode* foundNode = SearchListUnderParentL( root, aList );
       
   765     
       
   766     if ( foundNode )
       
   767         {
       
   768         DP_SDA("CPresencePluginXdmUtils::CheckIfEnityExist check nodes");
       
   769         TInt findErr = foundNode->Find( KPresenceEntry, nodes );
       
   770         DP_SDA2("CheckIfEnityExist - findErr: %d", findErr );
       
   771 
       
   772         if ( findErr )
       
   773             {
       
   774             DP_SDA("CheckIfEnityExist Enity not exist ");
       
   775             state = EFalse;
       
   776             }
       
   777         else
       
   778             {
       
   779             DP_SDA("CPresencePluginXdmUtils::CheckIfEnityExist Else");
       
   780             TInt nodeCount = nodes.Count();
       
   781             for ( TInt i = 0; i < nodeCount; i++ )
       
   782                 {
       
   783                 CXdmDocumentNode* currNode = nodes[i];
       
   784                 attr = ( currNode )->Attribute( KPresenceUri );
       
   785                 
       
   786                 TBool uriMatch( EFalse );
       
   787                 uriMatch = CompareUriWithoutPrefixL( 
       
   788                     aUri, attr->AttributeValue() );
       
   789                 
       
   790                 if ( attr && uriMatch )
       
   791                     {
       
   792                     DP_SDA("CheckIfEnityExist entity exists");
       
   793                     //Enity is exist
       
   794                     state = ETrue;
       
   795                     break;
       
   796                     }
       
   797                 }
       
   798             }
       
   799         }
       
   800     DP_SDA("CPresencePluginXdmUtils::CheckIfEnityExist Destroy nodes");
       
   801     CleanupStack::PopAndDestroy( &nodes ); // >>> nodes    
       
   802     return state;
       
   803     }
       
   804 
       
   805 // ---------------------------------------------------------------------------
       
   806 // CPresencePluginXdmUtils::SearchListUnderParentL
       
   807 // ---------------------------------------------------------------------------
       
   808 //
       
   809 CXdmDocumentNode* CPresencePluginXdmUtils::SearchListUnderParentL(
       
   810     CXdmDocumentNode* aParent,
       
   811     const TDesC& aName )
       
   812     {
       
   813     DP_SDA("CPresencePluginXdmUtils::SearchListUnderParentL");
       
   814     
       
   815     using namespace NPresencePlugin::NPresence;
       
   816 
       
   817     if ( !aParent )
       
   818         {
       
   819         DP_SDA("CPresencePluginXdmUtils::SearchListUnderParentL return NULL");
       
   820         return NULL;
       
   821         }
       
   822 
       
   823     RPointerArray<CXdmDocumentNode> resultArray;
       
   824     RPointerArray<SXdmAttribute16>  attributeArray;
       
   825 
       
   826     CleanupClosePushL( resultArray );           // <<< resultArray
       
   827     CleanupClosePushL( attributeArray );        // <<< attributeArray
       
   828 
       
   829     SXdmAttribute16 attr;
       
   830     attr.iName.Set( KPresenceName );
       
   831     attr.iValue.Set( aName );
       
   832     attributeArray.Append( &attr );
       
   833 
       
   834     CXdmDocumentNode* currNode = NULL;
       
   835 
       
   836     aParent->Find( KPresenceList, resultArray, attributeArray );
       
   837 
       
   838     TInt count = resultArray.Count();
       
   839     DP_SDA2("SearchListUnderParentL node count %d",count);
       
   840     for ( TInt i=0; i < count; i++ )
       
   841         {
       
   842         currNode = resultArray[i];
       
   843         CXdmDocumentNode* parent = currNode->Parent();
       
   844         if ( parent == aParent )
       
   845             {
       
   846             DP_SDA("SearchListUnderParentL parent MATCH");
       
   847             break;
       
   848             }
       
   849         currNode = NULL;
       
   850         }
       
   851 
       
   852     CleanupStack::PopAndDestroy( &attributeArray); // >>> attributeArray
       
   853     CleanupStack::PopAndDestroy( &resultArray );   // >>> resultArray
       
   854     DP_SDA("CPresencePluginXdmUtils::SearchListUnderParentL return");
       
   855     return currNode;
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CPresencePluginXdmUtils::RemoveEntityFromGrantedL()
       
   860 // ---------------------------------------------------------------------------
       
   861 //    
       
   862 void CPresencePluginXdmUtils::RemoveEntityFromGrantedL(
       
   863     const TDesC&  aUri,
       
   864     TRequestStatus& aStatus )
       
   865     {
       
   866     DP_SDA("CPresencePluginXdmUtils::RemoveEntityFromGrantedL");
       
   867     TRAPD(err, iEntityUri =  aUri.AllocL() );
       
   868 
       
   869   	iConnObs.SubscribedContacts()->RemoveEntityL( iEntityUri->Des() );
       
   870     
       
   871     if ( !err )
       
   872         {
       
   873         iClientStatus = &aStatus;
       
   874         iRulesUpdateState = EStateRemoveFromWhiteList;
       
   875         iOperation = EXdmRemoveUserFromGroup;
       
   876 
       
   877         DoRemoveUserFromListL( KPresenceBuddyList, aUri );
       
   878         // send to the server and start wait a response
       
   879         UpdateXdmsL();
       
   880         iXdmState = EUpdateXdmList;
       
   881         *iClientStatus = KRequestPending;
       
   882         }
       
   883     else
       
   884         {
       
   885         //If error we can complete request
       
   886         DP_SDA("RemoveEntityFromGrantedL SEND COMPLETE");
       
   887   	    CompleteClientReq( KErrNone );
       
   888         }
       
   889     }
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 // CPresencePluginXdmUtils::RemoveEntityFromBlockedL()
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 void CPresencePluginXdmUtils::RemoveEntityFromBlockedL(
       
   896     const TDesC&  aUri,
       
   897     TRequestStatus& aStatus )
       
   898     {
       
   899     DP_SDA("CPresencePluginXdmUtils::RemoveEntityFromBlockedL");
       
   900     TRAPD(err, iEntityUri =  aUri.AllocL() );
       
   901     
       
   902     if ( !err )
       
   903         {
       
   904         iClientStatus = &aStatus;
       
   905         iRulesUpdateState = EStateRemoveFromBlackList;
       
   906         iOperation = EXdmRemoveUserFromGroup;
       
   907 
       
   908         DoRemoveUserFromListL( KPresenceBlockedList, aUri );
       
   909         // send to the server and start wait a response
       
   910         UpdateXdmsL();
       
   911         iXdmState = EUpdateXdmList;
       
   912         *iClientStatus = KRequestPending;
       
   913         }
       
   914     else
       
   915         {
       
   916         //If error we can complete request
       
   917         DP_SDA("RemoveEntityFromBlockedL SEND COMPLETE");
       
   918   	    CompleteClientReq( KErrNone );
       
   919         }  
       
   920     }
       
   921 
       
   922 // ---------------------------------------------------------------------------
       
   923 // CPresencePluginXdmUtils::DoRemoveUserFromListL()
       
   924 // ---------------------------------------------------------------------------
       
   925 //    
       
   926 void CPresencePluginXdmUtils::DoRemoveUserFromListL(
       
   927     const TDesC& aList,
       
   928     const TDesC&  aUri )
       
   929     {
       
   930     DP_SDA("CPresencePluginXdmUtils::DoRemoveUserFromListL");
       
   931     CXdmNodeAttribute* attr = NULL;
       
   932 
       
   933     using namespace NPresencePlugin::NPresence;
       
   934 
       
   935     RPointerArray<CXdmDocumentNode> lists;
       
   936     CleanupClosePushL( lists );
       
   937 
       
   938     RPointerArray<CXdmDocumentNode> nodes;
       
   939     CleanupClosePushL( nodes );
       
   940 
       
   941     CXdmDocumentNode* root = iXdmDoc->DocumentRoot();
       
   942     CXdmDocumentNode* foundNode = SearchListUnderParentL( root, aList );
       
   943     if ( foundNode )
       
   944         {
       
   945         DP_SDA("CPresencePluginXdmUtils::DoRemoveUserFromListL Node Found");		
       
   946         User::LeaveIfError( foundNode->Find( KPresenceEntry, nodes ));
       
   947         TInt nodeCount = nodes.Count();
       
   948         for ( TInt i = 0; i < nodeCount; i++ )
       
   949             {
       
   950             CXdmDocumentNode* currNode = nodes[i];         
       
   951             attr = ( currNode )->Attribute( KPresenceUri );
       
   952             
       
   953             TBool uriMatch( EFalse );
       
   954             uriMatch = CompareUriWithoutPrefixL( 
       
   955                 aUri, attr->AttributeValue() );
       
   956             
       
   957             if ( attr && uriMatch )
       
   958                 {
       
   959                 DP_SDA(" DoRemoveUserFromListL Node Found, do delete");	
       
   960             
       
   961                 // This is the user we are looking for deletion.
       
   962                 //First remove currNode form model
       
   963                 iXdmDoc->RemoveFromModelL( currNode );
       
   964                 // Update model to server
       
   965                 iXdmDoc->AppendL();
       
   966                 break;
       
   967                 }
       
   968             }
       
   969         }
       
   970     else
       
   971         {
       
   972         DP_SDA("CPresencePluginXdmUtils::DoRemoveUserFromListL Leave");	
       
   973         User::Leave( KErrNotFound );
       
   974         }
       
   975 
       
   976     CleanupStack::PopAndDestroy( &nodes ); // >>> nodes
       
   977     CleanupStack::PopAndDestroy( &lists ); // >>> lists
       
   978     DP_SDA("CPresencePluginXdmUtils::DoRemoveUserFromListL END");
       
   979     }
       
   980        
       
   981 // ---------------------------------------------------------------------------
       
   982 // CPresencePluginXdmUtils::SubscribeBuddyListL()
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 void CPresencePluginXdmUtils::SubscribeBuddyListL( 
       
   986     RPointerArray<MXIMPIdentity>& aMembers )
       
   987     {
       
   988     DP_SDA("CPresencePluginXdmUtils::SubscribeBuddyListL");
       
   989 
       
   990     iOperation = EXdmGetBuddyList;
       
   991     DoGetListMembersL( KPresenceBuddyList, aMembers );
       
   992 
       
   993     DP_SDA("CPresencePluginXdmUtils::SubscribeBuddyListL end");
       
   994     }
       
   995 
       
   996 // ---------------------------------------------------------------------------
       
   997 // CPresencePluginXdmUtils::SubscribeBlockListL()
       
   998 // ---------------------------------------------------------------------------
       
   999 //
       
  1000 void CPresencePluginXdmUtils::SubscribeBlockListL( 
       
  1001     RPointerArray<MXIMPIdentity>& aMembers )
       
  1002     {
       
  1003     DP_SDA("CPresencePluginXdmUtils::SubscribeBlockListL");
       
  1004 
       
  1005     if ( !iLocalMode )
       
  1006         {
       
  1007         DP_SDA("CPresencePluginXdmUtils::SubscribeBlockListL !iLocalMode");
       
  1008         iOperation = EXdmGetBlockedList;
       
  1009         DoGetListMembersL( KPresenceBlockedList, aMembers );
       
  1010         }
       
  1011     DP_SDA("CPresencePluginXdmUtils::SubscribeBlockListL end");
       
  1012     }
       
  1013 
       
  1014 // ---------------------------------------------------------------------------
       
  1015 // CPresencePluginXdmUtils::DoGetListMembersL()
       
  1016 // ---------------------------------------------------------------------------
       
  1017 //
       
  1018 void CPresencePluginXdmUtils::DoGetListMembersL(
       
  1019     const TDesC& aList,
       
  1020     RPointerArray<MXIMPIdentity>& aMembers  )
       
  1021     {
       
  1022     DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL");
       
  1023     using namespace NPresencePlugin::NPresence;
       
  1024 
       
  1025     aMembers.Reset();
       
  1026 
       
  1027     RPointerArray<CXdmDocumentNode> nodes;
       
  1028     CleanupClosePushL( nodes );
       
  1029 
       
  1030     CXdmDocumentNode* listNode = NULL;
       
  1031     CXdmNodeAttribute* attr = NULL;
       
  1032 
       
  1033     TBool found(EFalse);
       
  1034         
       
  1035     if ( iXdmDoc )
       
  1036         {
       
  1037         DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL iXdmDoc");
       
  1038         User::LeaveIfError( iXdmDoc->Find( KPresenceList, nodes ) );
       
  1039         DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL find ready");
       
  1040         TInt count = nodes.Count();
       
  1041         DP_SDA2("DoGetListMembersL find Count %d", count);
       
  1042         for ( TInt i=0; i < count; i++ )
       
  1043             {
       
  1044             listNode = nodes[i];
       
  1045             attr = listNode->Attribute( KPresenceName );
       
  1046             if ( attr && !attr->AttributeValue().CompareF( aList ))
       
  1047                 {
       
  1048                 // That's the right list
       
  1049                 DP_SDA("DoGetListMembersL Target found");
       
  1050                 found = ETrue;
       
  1051                 break;
       
  1052                 }
       
  1053             }
       
  1054         }
       
  1055    
       
  1056     if ( found )
       
  1057         {
       
  1058         DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL found");
       
  1059         MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
  1060         nodes.Reset();
       
  1061         TInt err = listNode->Find( KPresenceEntry, nodes );
       
  1062         DP_SDA2("CPresencePluginXdmUtils::DoGetListMembersL err %d", err);
       
  1063         if( !err )
       
  1064             {
       
  1065             DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL Entry found");
       
  1066             TInt nodeCount = nodes.Count();
       
  1067             for ( TInt i = 0; i < nodeCount; i++ )
       
  1068                 {
       
  1069                 attr = (nodes[i])->Attribute( KPresenceUri );
       
  1070                 if ( attr )
       
  1071                     {
       
  1072                     DP_SDA("DoGetListMembersL attr check");
       
  1073                     MXIMPIdentity* entity =
       
  1074                         myFactory.NewIdentityLC(); // << entity
       
  1075                     entity->SetIdentityL( attr->AttributeValue() );
       
  1076                     aMembers.Append( entity );
       
  1077                     CleanupStack::Pop(); // >> entity
       
  1078                     }
       
  1079                 }
       
  1080             }
       
  1081         }
       
  1082     CleanupStack::PopAndDestroy( &nodes );
       
  1083     DP_SDA("CPresencePluginXdmUtils::DoGetListMembersL end");
       
  1084     }
       
  1085     
       
  1086 // ---------------------------------------------------------------------------
       
  1087 // CPresencePluginXdmUtils::GetXdmListsL()
       
  1088 // ---------------------------------------------------------------------------
       
  1089 //
       
  1090 void CPresencePluginXdmUtils::GetXdmListsL( 
       
  1091     TBool aCreateRules,
       
  1092     TBool aLocalMode )
       
  1093     {
       
  1094     DP_SDA("CPresencePluginXdmUtils::GetXdmListsL");
       
  1095     //Normal Mode start
       
  1096     if ( !iXdmEngine && !aLocalMode )
       
  1097         {
       
  1098         DP_SDA2("!iXdmEngine settingID = %d", iSettingsId);
       
  1099         
       
  1100 #ifdef _DEBUG
       
  1101         //Get xdmSettings
       
  1102         HBufC* accesPoint = TXdmSettingsApi::PropertyL( 
       
  1103             iSettingsId, EXdmPropToNapId );
       
  1104         CleanupStack::PushL( accesPoint );
       
  1105         DP_SDA2("CPresencePluginXdmUtils::GetXdmListsL accesPoint %S", 
       
  1106             accesPoint);
       
  1107 #endif
       
  1108         
       
  1109         // get data from a network if not done so yet
       
  1110         CXdmProtocolInfo* info = CXdmProtocolInfo::NewL( iSettingsId );
       
  1111         CleanupStack::PushL( info );
       
  1112         
       
  1113         // Notice: we do not use cache for XDM
       
  1114         info->SetCacheUsage( EFalse ); //False in normal case
       
  1115         
       
  1116         iXdmEngine = CXdmEngine::NewL( *info );
       
  1117         CleanupStack::PopAndDestroy( info );
       
  1118 #ifdef _DEBUG        
       
  1119         CleanupStack::PopAndDestroy( accesPoint );
       
  1120 #endif        
       
  1121         }
       
  1122     //LocalMode Start, !!! THERE IS LIMIT !!!
       
  1123     //Only one settings can use localmode 
       
  1124     else if ( !iXdmEngine && aLocalMode )
       
  1125         {
       
  1126         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL aLocalMode");
       
  1127         CXdmProtocolInfo* info =
       
  1128             CXdmProtocolInfo::NewL( 0, KLocalProtocol, KNullDesC );
       
  1129         CleanupStack::PushL( info );
       
  1130         
       
  1131         iXdmEngine = CXdmEngine::NewL( *info );
       
  1132         CleanupStack::PopAndDestroy( info );
       
  1133         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL aLocalMode end");
       
  1134         }   
       
  1135     if ( !iXdmOk )
       
  1136         {
       
  1137         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL !XdmOK "); 
       
  1138         using namespace NPresencePlugin::NPresence;
       
  1139         // Get data from network
       
  1140         DP_SDA("GetXdmListsL Create Document Model ");
       
  1141         
       
  1142         iXdmDoc = iXdmEngine->CreateDocumentModelL( 
       
  1143             KPresenceResourceList, EXdmResourceLists );
       
  1144        
       
  1145         
       
  1146         DP_SDA("Create Document Model FetchData");
       
  1147         iXdmDoc->FetchDataL();    
       
  1148         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL !XdmOK SETACTIVE ");
       
  1149         UpdateXdmsL();
       
  1150         iXdmState = aCreateRules ? EGetXdmLists : EGetXdmListsOnly;
       
  1151         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL !XdmOK END"); 
       
  1152         }
       
  1153     else
       
  1154         {
       
  1155         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL else");
       
  1156         // Document already exists, no need to search from a server
       
  1157         iStatus = KRequestPending;
       
  1158         TRequestStatus* s= &iStatus;
       
  1159         DP_SDA("CPresencePluginXdmUtils::GetXdmListsL SEND COMPLETE");
       
  1160         User::RequestComplete( s, KErrNone );
       
  1161         iXdmState = aCreateRules ? EGetXdmLists : EGetXdmListsOnly;
       
  1162         SetActive();        
       
  1163         }
       
  1164     }
       
  1165 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 // CPresencePluginXdmUtils::CreateXdmListsL()
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //
       
  1170 void CPresencePluginXdmUtils::CreateXdmListsL( TBool aCreateRules )
       
  1171     {
       
  1172     DP_SDA("CPresencePluginXdmUtils::CreateXdmListsL");
       
  1173  
       
  1174     CXdmDocumentNode* root = iXdmDoc->CreateRootL();
       
  1175     CleanupStack::PushL( root );
       
  1176     
       
  1177     using namespace NPresencePlugin::NPresence;
       
  1178     root->SetNameL( KPresenceResourceLists );
       
  1179 
       
  1180     // add all the list nodes
       
  1181     // buddylist
       
  1182     using namespace NPresencePlugin::NPresence;
       
  1183     if ( root->IsEmptyNode() )
       
  1184         {
       
  1185         root->SetEmptyNode( EFalse );
       
  1186         }
       
  1187     //buddy list
       
  1188     CXdmDocumentNode* child1 = root->CreateChileNodeL( KPresenceList );
       
  1189     CleanupStack::PushL( child1 );
       
  1190     CXdmNodeAttribute* name = child1->CreateAttributeL( KPresenceName );
       
  1191     CleanupStack::PushL( name );
       
  1192     name->SetAttributeValueL( KPresenceBuddyList );
       
  1193 
       
  1194     // blockedcontacts
       
  1195     CXdmDocumentNode* child2 = root->CreateChileNodeL( KPresenceList );
       
  1196     CleanupStack::PushL( child2 );
       
  1197     CXdmNodeAttribute* name2 = child2->CreateAttributeL( KPresenceName );
       
  1198     CleanupStack::PushL( name2 );
       
  1199     name2->SetAttributeValueL( KPresenceBlockedList );
       
  1200 
       
  1201     // send to the server and start wait a response
       
  1202     iXdmDoc->AppendL();
       
  1203     UpdateXdmsL();
       
  1204     iXdmState = aCreateRules ? ECreateXdmLists : ECreateXdmListsOnly;
       
  1205     
       
  1206     CleanupStack::Pop( name2 );
       
  1207     CleanupStack::Pop( child2 );
       
  1208     CleanupStack::Pop( name );
       
  1209     CleanupStack::Pop( child1 );
       
  1210     CleanupStack::Pop( root );
       
  1211     DP_SDA("CPresencePluginXdmUtils::CreateXdmListsL end");
       
  1212     }
       
  1213     
       
  1214 // ---------------------------------------------------------------------------
       
  1215 // CPresencePluginXdmUtils::GetEntitiesInListL()
       
  1216 // ---------------------------------------------------------------------------
       
  1217 //
       
  1218 void CPresencePluginXdmUtils::GetEntitiesInListL(
       
  1219     const TDesC&  aList,
       
  1220     MXIMPObjectCollection& aColl )
       
  1221     {
       
  1222     DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL ");
       
  1223     using namespace NPresencePlugin::NPresence;
       
  1224 
       
  1225     CXdmDocumentNode* buddylist = DoGetBuddyListL( aList );
       
  1226 
       
  1227     // make a collection of MXIMPPresentityGroupMemberInfo
       
  1228     RPointerArray<CXdmDocumentNode> entries;
       
  1229     CleanupClosePushL(entries);       // <<< entries
       
  1230 
       
  1231     RPointerArray<CXdmDocumentNode> nodes;
       
  1232     CleanupClosePushL(nodes);         // <<< nodes
       
  1233 
       
  1234     buddylist->Find( KPresenceEntry, entries );
       
  1235     DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL entries");
       
  1236     TInt count = entries.Count();
       
  1237     DP_SDA2("GetEntitiesInListL entries count %d",count);
       
  1238     for ( TInt i=0; i < count; i++ )
       
  1239         {
       
  1240         DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL 1");
       
  1241         // create here MXIMPPresentityGroupMemberInfo
       
  1242         MPresentityGroupMemberInfo* info =
       
  1243             iConnObs.PresenceObjectFactoryOwn().
       
  1244                 NewPresentityGroupMemberInfoLC();
       
  1245 
       
  1246         // ID
       
  1247         CXdmDocumentNode* entry = entries[i];
       
  1248         CXdmNodeAttribute* attr = entry->Attribute( KPresenceUri );
       
  1249         if ( attr )
       
  1250             {
       
  1251             DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL 2");
       
  1252             MXIMPIdentity* id =
       
  1253                 iConnObs.ObjectFactory().NewIdentityLC();//<< id
       
  1254             id->SetIdentityL( attr->AttributeValue() );
       
  1255             info->SetGroupMemberIdL( id );
       
  1256             CleanupStack::Pop(); // >> id
       
  1257             }
       
  1258 
       
  1259         // Display name
       
  1260         TInt err = entry->Find( KPresenceDisplayName, nodes );
       
  1261         // Notice: assume there is only one display-name
       
  1262         if ( !err )
       
  1263             {
       
  1264             DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL display name");
       
  1265             CXdmDocumentNode* disName = nodes[0];
       
  1266                 HBufC16* uri16 = NULL;
       
  1267                 uri16 = 
       
  1268                     CnvUtfConverter::ConvertToUnicodeFromUtf8L( 
       
  1269                         disName->LeafNodeContent() );
       
  1270                     
       
  1271                 CleanupStack::PushL( uri16 );  // << uri16
       
  1272                 info->SetGroupMemberDisplayNameL( uri16->Des() );
       
  1273                 CleanupStack::PopAndDestroy( uri16 );  // >> uri16
       
  1274             }
       
  1275 
       
  1276 		DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL 3");
       
  1277         aColl.AddObjectL( info );
       
  1278         
       
  1279         //if contact is from buddylist add it to virtual subscribed list too
       
  1280         if( !aList.CompareF( KPresenceBuddyList ) )
       
  1281             {
       
  1282             DP_SDA("GetEntitiesInListL add virtualgroup");
       
  1283             //Add identity to virtual list
       
  1284             iConnObs.SubscribedContacts()->AddEntityL( 
       
  1285             	info->GroupMemberId().Identity() );
       
  1286             }
       
  1287             
       
  1288         CleanupStack::Pop(); // >> info
       
  1289         }
       
  1290 
       
  1291     CleanupStack::PopAndDestroy( &nodes ); // >>> nodes
       
  1292     CleanupStack::PopAndDestroy( &entries ); // >>> entries*/
       
  1293     DP_SDA("CPresencePluginXdmUtils::GetEntitiesInListL end");
       
  1294     }
       
  1295 
       
  1296 // ---------------------------------------------------------------------------
       
  1297 // CPresencePluginXdmUtils::AddIdentityToVirtualListL()
       
  1298 // ---------------------------------------------------------------------------
       
  1299 //
       
  1300 void CPresencePluginXdmUtils::AddIdentityToVirtualListL( const TDesC&  aList )
       
  1301 	{
       
  1302 	DP_SDA("CPresencePluginXdmUtils::AddIdentityToVirtualListL ");
       
  1303 	using namespace NPresencePlugin::NPresence;
       
  1304 
       
  1305 	if ( aList.Compare( KPresenceBlockedList ) == NULL )
       
  1306 	    {
       
  1307 	    iBlockedContacts.ResetAndDestroy();
       
  1308 	    }
       
  1309 
       
  1310     CXdmDocumentNode* buddylist = DoGetBuddyListL( aList );
       
  1311 
       
  1312     // make a collection of MXIMPPresentityGroupMemberInfo
       
  1313     RPointerArray<CXdmDocumentNode> entries;
       
  1314     CleanupClosePushL(entries);       // <<< entries
       
  1315 
       
  1316     buddylist->Find( KPresenceEntry, entries );
       
  1317     DP_SDA("CPresencePluginXdmUtils::AddIdentityToVirtualListL entries");
       
  1318     TInt count = entries.Count();
       
  1319     DP_SDA2("AddIdentityToVirtualListL entries count %d",count);
       
  1320     for ( TInt i=0; i < count; i++ )
       
  1321         {
       
  1322         DP_SDA("CPresencePluginXdmUtils::AddIdentityToVirtualListL 1");
       
  1323         // ID
       
  1324         CXdmDocumentNode* entry = entries[i];
       
  1325         CXdmNodeAttribute* attr = entry->Attribute( KPresenceUri );
       
  1326         if ( attr )
       
  1327             {
       
  1328             if( !aList.CompareF( KPresenceBuddyList ) )
       
  1329                 {
       
  1330                 DP_SDA("AddIdentityToVirtualListL add to buddies");
       
  1331                 //Add identity to virtual list
       
  1332                 iConnObs.SubscribedContacts()->AddEntityL( 
       
  1333                 		attr->AttributeValue() );
       
  1334                 }
       
  1335             else if ( !aList.CompareF( KPresenceBlockedList ) )
       
  1336                 {
       
  1337                 DP_SDA("AddIdentityToVirtualListL add to blocked");
       
  1338                 HBufC* withoutPrefix = 
       
  1339                     iConnObs.InternalPresenceAuthorization().
       
  1340                         PluginData().RemovePrefixLC( attr->AttributeValue() );
       
  1341                 CleanupStack::Pop( withoutPrefix );
       
  1342                 iBlockedContacts.AppendL( withoutPrefix );
       
  1343                 }
       
  1344             }
       
  1345         }
       
  1346     CleanupStack::PopAndDestroy( &entries ); // >>> entries
       
  1347     DP_SDA("CPresencePluginXdmUtils::AddIdentityToVirtualListL end");
       
  1348 	}
       
  1349     
       
  1350 // ---------------------------------------------------------------------------
       
  1351 // CPresencePluginXdmUtils::DoGetBuddyListL()
       
  1352 // ---------------------------------------------------------------------------
       
  1353 //
       
  1354 CXdmDocumentNode* CPresencePluginXdmUtils::DoGetBuddyListL( 
       
  1355     const TDesC&  aParent )
       
  1356     {
       
  1357     DP_SDA("CPresencePluginXdmUtils::DoGetBuddyListL");
       
  1358     CXdmDocumentNode* root = iXdmDoc->DocumentRoot();
       
  1359     
       
  1360     CXdmDocumentNode* ret = SearchListUnderParentL( root, aParent );
       
  1361     if ( !ret )
       
  1362         {
       
  1363         DP_SDA("CPresencePluginXdmUtils::DoGetBuddyListL !found");
       
  1364         User::Leave( KErrNotFound );
       
  1365         }
       
  1366     return ret;
       
  1367     }
       
  1368 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 // CPresencePluginXdmUtils::DoGetUserListL()
       
  1371 // ---------------------------------------------------------------------------
       
  1372 //
       
  1373 CXdmDocumentNode* CPresencePluginXdmUtils::DoGetUserListL(
       
  1374     const TDesC& aList, CXdmDocumentNode* aBuddyList )
       
  1375     {
       
  1376     DP_SDA("CPresencePluginXdmUtils::DoGetUserListL");
       
  1377     CXdmDocumentNode* listNode = NULL;
       
  1378     CXdmNodeAttribute* attr = NULL;
       
  1379     TBool found( EFalse );
       
  1380 
       
  1381     using namespace NPresencePlugin::NPresence;
       
  1382 
       
  1383     RPointerArray<CXdmDocumentNode> lists;
       
  1384     CleanupClosePushL( lists );
       
  1385 
       
  1386     User::LeaveIfError( aBuddyList->Find( KPresenceEntry, lists ));
       
  1387     TInt count = lists.Count();
       
  1388     DP_SDA2("CPresencePluginXdmUtils::DoGetUserListL count %d",count);
       
  1389     for ( TInt i=0; i < count; i++ )
       
  1390         {
       
  1391         listNode = lists[i];
       
  1392         attr = listNode->Attribute( KPresenceUri );
       
  1393         if ( attr && !attr->AttributeValue().CompareF( aList ))
       
  1394             {
       
  1395             // List is found
       
  1396             found = ETrue;
       
  1397             break;
       
  1398             }
       
  1399         }
       
  1400     if ( !found )
       
  1401         {
       
  1402         DP_SDA("CPresencePluginXdmUtils::DoGetUserListL !found");
       
  1403         User::Leave( KErrNotFound );
       
  1404         }
       
  1405 
       
  1406     CleanupStack::PopAndDestroy( &lists );
       
  1407     DP_SDA("CPresencePluginXdmUtils::DoGetUserListL end");
       
  1408     return listNode;
       
  1409     }
       
  1410         
       
  1411 // ---------------------------------------------------------------------------
       
  1412 // CPresencePluginXdmUtils::UpdateXdmsL()
       
  1413 // ---------------------------------------------------------------------------
       
  1414 //    
       
  1415 void CPresencePluginXdmUtils::UpdateXdmsL()
       
  1416     {
       
  1417     DP_SDA("CPresencePluginXdmUtils::UpdateXdmsL");
       
  1418     iXdmEngine->UpdateL( iXdmDoc, iStatus );
       
  1419     if ( !IsActive() )
       
  1420     	{
       
  1421     	DP_SDA("CPresencePluginXdmUtils::UpdateXdmsL SetActive");
       
  1422     	SetActive();
       
  1423     	}
       
  1424     DP_SDA("CPresencePluginXdmUtils::UpdateXdmsL end");
       
  1425     }
       
  1426     
       
  1427 // ---------------------------------------------------------------------------
       
  1428 // CPresencePluginXdmUtils::UpdateXdmRulesL()
       
  1429 // ---------------------------------------------------------------------------
       
  1430 //    
       
  1431 void CPresencePluginXdmUtils::UpdateXdmRulesL()
       
  1432     {
       
  1433     DP_SDA("CPresencePluginXdmUtils::UpdateXdmRulesL");
       
  1434     iXdmState = EUpdateXdmRules;
       
  1435     
       
  1436 	if( iRulesUpdateState == EStateInitializeRules )
       
  1437     	{
       
  1438     	User::LeaveIfError( iXdmPresRules->UpdateXdmRulesL( this ));
       
  1439     	}
       
  1440     //Add entity to presrules too
       
  1441     if ( iRulesUpdateState == EStateAddToWhiteList )
       
  1442         {
       
  1443         DP_SDA("EStateAddToWhiteList");
       
  1444         iXdmPresRules->AddEntityToWhiteListL( 
       
  1445         		iEntityUri->Des(), this );
       
  1446         }
       
  1447     if ( iRulesUpdateState == EStateAddToBlockList )
       
  1448         {
       
  1449         DP_SDA("EStateAddToBlockList");
       
  1450         iXdmPresRules->AddEntityToBlockedRulesL( 
       
  1451         		iEntityUri->Des(), this );
       
  1452         }
       
  1453     if ( iRulesUpdateState == EStateRemoveFromWhiteList)
       
  1454         {
       
  1455         DP_SDA("EStateRemoveFromWhiteList");
       
  1456         iXdmPresRules->RemoveEntityFromWhiteListL( 
       
  1457         		iEntityUri->Des(), this );
       
  1458         }
       
  1459     if ( iRulesUpdateState == EStateRemoveFromBlackList)
       
  1460         {
       
  1461         DP_SDA("EStateRemoveFromBlackList");
       
  1462         iXdmPresRules->RemoveEntityBlockedRulesL( 
       
  1463         		iEntityUri->Des(), this );
       
  1464         }
       
  1465     DP_SDA("CPresencePluginXdmUtils::UpdateXdmRulesL end");
       
  1466     }
       
  1467 
       
  1468 // ---------------------------------------------------------------------------
       
  1469 // CPresencePluginXdmUtils::DoHandlePresUpdateDocumentL()
       
  1470 // ---------------------------------------------------------------------------
       
  1471 //      
       
  1472 void CPresencePluginXdmUtils::DoHandlePresUpdateDocumentL( TInt aErrorCode )
       
  1473     {
       
  1474     DP_SDA("CPresencePluginXdmUtils::DoHandlePresUpdateDocumentL");
       
  1475     
       
  1476     // check if error
       
  1477     CheckIfErrorL( aErrorCode );
       
  1478 
       
  1479     if ( iXdmState == EGetXdmRules )
       
  1480         {
       
  1481         DP_SDA("DoHandlePresUpdateDocumentL EGetXdmRules");
       
  1482         iXdmState = EStateIdle;
       
  1483 		if ( aErrorCode && aErrorCode == KXcapErrorHttpNotFound )
       
  1484             {
       
  1485             DP_SDA("DoHandlePresUpdateDocumentL EGetXdmRules ini rules ERROR");
       
  1486 			InitializePresRulesL();
       
  1487             }
       
  1488         else
       
  1489             {
       
  1490             DP_SDA("DoHandlePresUpdateDocumentL EGetXdmRules SEND COMPLETE ");
       
  1491             // Complete with ok or error the last initial opreration
       
  1492 
       
  1493             // update presence cache if needed before complete client req.
       
  1494             iPresXdmOk = ETrue;
       
  1495 
       
  1496             if ( iBlockedContacts.Count() > 0 )
       
  1497                 {
       
  1498                 iConnObs.InternalPresenceAuthorization().
       
  1499                     IsBlockedContactFriendRequestL(
       
  1500                          *iBlockedContacts[ iBlockedContacts.Count() - 1 ],
       
  1501                          *this, iStatus );
       
  1502 
       
  1503                 iXdmState = EUpdateBlockedContactPresenceCache;
       
  1504                 SetActive();
       
  1505                 }
       
  1506             else
       
  1507                 {
       
  1508                 CompleteClientReq( aErrorCode );
       
  1509                 }
       
  1510             }
       
  1511         }
       
  1512     else if ( iXdmState == EUpdateXdmRules )
       
  1513         {
       
  1514         DP_SDA("DoHandlePresUpdateDocumentL EUpdateXdmRules SEND COMPLETE ");
       
  1515         // Complete with ok or error the last initial opreration
       
  1516         CompleteClientReq( aErrorCode );
       
  1517         }
       
  1518     else if ( iXdmState == ECreateXdmRules )
       
  1519         {
       
  1520         DP_SDA("DoHandlePresUpdateDocumentL ECreateXdmRules SEND COMPLETE ");
       
  1521         iPresXdmOk = ETrue;
       
  1522         CompleteClientReq( aErrorCode );
       
  1523         }
       
  1524 
       
  1525 	else if ( iXdmState == EUpdateXdmList)
       
  1526 		{
       
  1527 		DP_SDA("DoHandlePresUpdateDocumentL EUpdateXdmList SEND COMPLETE");
       
  1528 		CompleteClientReq( aErrorCode );
       
  1529 		}
       
  1530     }
       
  1531 
       
  1532 // ---------------------------------------------------------------------------
       
  1533 // CPresencePluginXdmUtils::CompleteClientReq()
       
  1534 // ---------------------------------------------------------------------------
       
  1535 //               
       
  1536 void CPresencePluginXdmUtils::CompleteClientReq( TInt aStatus )
       
  1537     {
       
  1538     DP_SDA("CPresencePluginXdmUtils::CompleteClientReq");
       
  1539     DP_SDA2("CPresencePluginXdmUtils::CompleteClientReq status %d ", aStatus);
       
  1540     iXdmState = EStateIdle;
       
  1541     iOperation = ENoOperation;
       
  1542     TRequestStatus* s = iClientStatus;
       
  1543     User::RequestComplete( s, aStatus );
       
  1544     DP_SDA("CPresencePluginXdmUtils::CompleteClientReq end");
       
  1545     }
       
  1546 
       
  1547 // ---------------------------------------------------------------------------
       
  1548 // CPresencePluginXdmUtils::HandlePresUpdateDocumentL()
       
  1549 // ---------------------------------------------------------------------------
       
  1550 //
       
  1551 void CPresencePluginXdmUtils::HandlePresUpdateDocumentL( 
       
  1552     TInt aErrorCode )
       
  1553     {
       
  1554 #ifdef _DEBUG
       
  1555     DP_SDA2("HandlePresUpdateDocumentL errorCode %d ", aErrorCode );
       
  1556     DP_SDA2("HandlePresUpdateDocumentL mystatus %d ", iStatus.Int());
       
  1557     DP_SDA2("HandlePresUpdateDocumentL state %d ", iXdmState);
       
  1558     DP_SDA2("HandlePresUpdateDocumentL ClientStatus %d",iClientStatus->Int() );
       
  1559 #endif
       
  1560     
       
  1561     DP_SDA("CPresencePluginXdmUtils::HandlePresUpdateDocumentL");      
       
  1562     if ( aErrorCode == KErrTimedOut  )
       
  1563 		{
       
  1564 		DP_SDA("CPresencePluginXdmUtils::HandlePresUpdateDocumentL TimeOut");                        
       
  1565 		aErrorCode  = 0;
       
  1566 		}
       
  1567 	    
       
  1568     TRAPD( err, DoHandlePresUpdateDocumentL( aErrorCode ));
       
  1569     if ( err )
       
  1570         {
       
  1571         DP_SDA("CPresencePluginXdmUtils::HandlePresUpdateDocumentL complete");
       
  1572         // Complete with ok or error the last initial opreration
       
  1573         CompleteClientReq( err );
       
  1574         }
       
  1575     }
       
  1576     
       
  1577 // ---------------------------------------------------------------------------
       
  1578 // CPresencePluginXdmUtils::SearchListUnderParentL
       
  1579 // ---------------------------------------------------------------------------
       
  1580 //
       
  1581 TBool CPresencePluginXdmUtils::CompareUriWithoutPrefixL( 
       
  1582     const TDesC& aUri, const TDesC& aAttribute )
       
  1583     {
       
  1584     DP_SDA("CPresencePluginXdmUtils::CompareUriWithoutPrefixL");
       
  1585     
       
  1586     TBool match( EFalse );
       
  1587     
       
  1588     RBuf uriWithoutPrefix;
       
  1589     CleanupClosePushL( uriWithoutPrefix );
       
  1590     uriWithoutPrefix.CreateL( aUri );
       
  1591     TInt prefixLocation = uriWithoutPrefix.Locate( ':' );
       
  1592                    
       
  1593     if ( KErrNotFound != prefixLocation )
       
  1594         {
       
  1595         uriWithoutPrefix.Delete( 0, ( prefixLocation + 1 ) );
       
  1596         }
       
  1597         
       
  1598      RBuf attributeWithoutprefix;
       
  1599      CleanupClosePushL( attributeWithoutprefix );
       
  1600      attributeWithoutprefix.CreateL( aAttribute );
       
  1601      prefixLocation = attributeWithoutprefix.Locate( ':' );
       
  1602                    
       
  1603      if ( KErrNotFound != prefixLocation )
       
  1604          {
       
  1605          attributeWithoutprefix.Delete( 0, ( prefixLocation + 1 ) );
       
  1606          }
       
  1607                     
       
  1608      DP_SDA2("    --> uri without prefix=%S", &uriWithoutPrefix );
       
  1609      DP_SDA2("    --> attribute without prefix=%S", &attributeWithoutprefix );                 
       
  1610                 
       
  1611      if ( uriWithoutPrefix.Compare( attributeWithoutprefix ) == 0 )
       
  1612          {
       
  1613          match = ETrue;
       
  1614          }
       
  1615                    
       
  1616     CleanupStack::PopAndDestroy( &attributeWithoutprefix );
       
  1617     CleanupStack::PopAndDestroy( &uriWithoutPrefix );
       
  1618     
       
  1619     return match;
       
  1620     }
       
  1621 
       
  1622 
       
  1623 // ---------------------------------------------------------------------------
       
  1624 // CPresencePluginXdmUtils::DoUpdateBlockedContactPresenceCacheL()
       
  1625 // ---------------------------------------------------------------------------
       
  1626 //
       
  1627 void CPresencePluginXdmUtils::DoUpdateBlockedContactPresenceCacheL(
       
  1628     TInt aMyStatus )
       
  1629     {
       
  1630     DP_SDA( "CPresencePluginXdmUtils::DoUpdateBlockedContactPresenceCache" );
       
  1631 
       
  1632     const TInt KTextBufferSize = 10;
       
  1633     TInt contactsCount = iBlockedContacts.Count();
       
  1634 
       
  1635     if ( contactsCount > 0 )
       
  1636         {
       
  1637         if ( iPresenceContactsAsyncReqResult )
       
  1638             {
       
  1639             DP_SDA(" RunL  -write blocked status to cache" );
       
  1640             TBuf<KTextBufferSize> buf;
       
  1641             buf.Copy( KBlockedExtensionValue );
       
  1642             iConnObs.InternalPresenceAuthorization().PluginData().
       
  1643                 WriteStatusToCacheL( *iBlockedContacts[ contactsCount - 1 ],
       
  1644                      MPresenceBuddyInfo2::EUnknownAvailability,
       
  1645                      buf,
       
  1646                      KNullDesC() );
       
  1647            }
       
  1648        delete iBlockedContacts[ contactsCount - 1 ];
       
  1649        iBlockedContacts.Remove( contactsCount - 1 );
       
  1650 
       
  1651        if ( iBlockedContacts.Count() > 0 )
       
  1652            {
       
  1653             iConnObs.InternalPresenceAuthorization().
       
  1654                 IsBlockedContactFriendRequestL(
       
  1655                     *iBlockedContacts[ iBlockedContacts.Count() - 1 ],
       
  1656                     *this, iStatus );
       
  1657 
       
  1658            iXdmState = EUpdateBlockedContactPresenceCache;
       
  1659            SetActive();
       
  1660            }
       
  1661        else
       
  1662            {
       
  1663            CompleteClientReq( aMyStatus );
       
  1664            }
       
  1665         }
       
  1666     }
       
  1667 
       
  1668 
       
  1669 // ---------------------------------------------------------------------------
       
  1670 // From MPresencePluginContactsObs
       
  1671 // CPresencePluginXdmUtils::RequestComplete
       
  1672 // ---------------------------------------------------------------------------
       
  1673 //
       
  1674 void CPresencePluginXdmUtils::RequestComplete( TAny* aResult,
       
  1675     TPresenceContactsOperation /*aOperation*/, TInt aError )
       
  1676     {
       
  1677     iPresenceContactsAsyncReqResult = EFalse;
       
  1678     if ( NULL != aResult && KErrNone == aError )
       
  1679         {
       
  1680         iPresenceContactsAsyncReqResult =
       
  1681             *static_cast<TBool*>( aResult );
       
  1682         }
       
  1683     }
       
  1684 
       
  1685 // End of file