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