simpledatamodeladapter/src/presencepluginauthorization.cpp
branchRCL_3
changeset 18 fbd2e7cec7ef
equal deleted inserted replaced
17:2669f8761a99 18:fbd2e7cec7ef
       
     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 #include <e32std.h>
       
    19 #include <s32strm.h>
       
    20 #include <utf.h>
       
    21 #include <ximpdatasubscriptionstate.h>
       
    22 #include <protocolpresenceauthorizationdatahost.h>
       
    23 #include <ximpobjectfactory.h>
       
    24 #include <presenceobjectfactory.h>
       
    25 #include <ximpstatus.h>
       
    26 #include <ximpidentity.h>
       
    27 #include <presencegrantrequestinfo.h>
       
    28 #include <ximpobjectcollection.h>
       
    29 #include <presenceblockinfo.h>
       
    30 #include <presenceinfofilter.h>
       
    31 #include <msimplewinfo.h>
       
    32 #include <msimpleelement.h>
       
    33 
       
    34 #include <presenceinfo.h>
       
    35 #include <presenceinfofieldcollection.h>
       
    36 #include <personpresenceinfo.h>
       
    37 #include <presenceinfofield.h>
       
    38 #include <presenceinfofieldvalueenum.h>
       
    39 #include <avabilitytext.h>
       
    40 
       
    41 #include "presencepluginauthorization.h"
       
    42 #include "presencepluginwinfo.h"
       
    43 #include "presenceplugincommon.h"
       
    44 #include "presencepluginxdmutils.h"
       
    45 #include "presencepluginwatcher.h"
       
    46 #include "presenceplugindata.h"
       
    47 #include "presencepluginutility.h"
       
    48 #include "presenceplugingroup.h"
       
    49 #include "presencepluginvirtualgroup.h"
       
    50 #include "presenceplugincontacts.h"
       
    51 
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CPresencePluginAuthorization::CPresencePluginAuthorization()
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CPresencePluginAuthorization::CPresencePluginAuthorization(
       
    60     MPresencePluginConnectionObs& aObs,
       
    61     CPresencePluginData* aPresenceData )
       
    62     : CActive( CActive::EPriorityStandard ),
       
    63     iConnObs(aObs), iSubscribed( EFalse ),
       
    64     iOperation( ENoOperation ), iXdmOk( EFalse ),
       
    65     iComplete( EFalse ), iPresenceData( aPresenceData ),
       
    66     iContactIsStored( ETrue )
       
    67     {
       
    68     CActiveScheduler::Add(this);
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CPresencePluginAuthorization::NewL()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CPresencePluginAuthorization* CPresencePluginAuthorization::NewL(
       
    76     MPresencePluginConnectionObs& aObs,
       
    77     CPresencePluginData* aPresenceData )
       
    78     {
       
    79     DP_SDA("CPresencePluginAuthorization::NewL ");
       
    80     CPresencePluginAuthorization* self =
       
    81         new( ELeave ) CPresencePluginAuthorization( aObs, aPresenceData );
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop( self );
       
    85     return self;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CPresencePluginAuthorization::ConstructL()
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CPresencePluginAuthorization::ConstructL()
       
    93     {
       
    94     HBufC* serviceName =
       
    95         iPresenceData->ServiceNameLC( iPresenceData->ServiceId() );
       
    96     iContacts = CPresencePluginContacts::NewL(
       
    97         iPresenceData->ServiceId(), *serviceName, *this );
       
    98     CleanupStack::PopAndDestroy( serviceName );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CPresencePluginAuthorization::~CPresencePluginAuthorization()
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CPresencePluginAuthorization::~CPresencePluginAuthorization()
       
   106     {
       
   107     delete iPresIdentity;
       
   108     delete iContacts;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CPresencePluginAuthorization::SetDataHost()
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CPresencePluginAuthorization::SetDataHost( 
       
   116     MProtocolPresenceAuthorizationDataHost& aDataHost )
       
   117     {
       
   118     DP_SDA("CPresencePluginAuthorization::SetDataHost ");
       
   119     iDataHost = &aDataHost;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CPresencePluginAuthorization::WinfoTerminatedL()
       
   124 // ---------------------------------------------------------------------------
       
   125 // 
       
   126 void CPresencePluginAuthorization::WinfoTerminatedL( TInt aReason )
       
   127     {
       
   128     DP_SDA("CPresencePluginAuthorization::WinfoTerminatedL ");
       
   129     
       
   130     if ( iSubscribed )
       
   131         {
       
   132         MXIMPDataSubscriptionState* myState =
       
   133             iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
   134         MXIMPStatus* myStatus = iConnObs.ObjectFactory().NewStatusLC();
       
   135         myStatus->SetResultCode( aReason ? aReason : KErrCompletion );
       
   136         myState->SetSubscriptionStateL( 
       
   137             MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   138         
       
   139         // parameters' OWNERSHIP is taken   
       
   140         iDataHost->SetPresenceGrantRequestDataSubscriptionStateL( 
       
   141             myState,  
       
   142             myStatus );
       
   143         
       
   144         CleanupStack::Pop( /*myStatus*/ );
       
   145         CleanupStack::Pop( /*myState*/ );
       
   146         }
       
   147     
       
   148     DP_SDA("CPresencePluginAuthorization::WinfoTerminatedL end");
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CPresencePluginAuthorization::DoSubscribePresenceGrantRequestListL()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CPresencePluginAuthorization::DoSubscribePresenceGrantRequestListL(
       
   156     TXIMPRequestId aReqId )
       
   157     {
       
   158     DP_SDA("DoSubscribePresenceGrantRequestListL ");
       
   159     iConnObs.WinfoHandlerL()->SubscribeWinfoListL( aReqId );
       
   160     iSubscribed = ETrue;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CPresencePluginAuthorization::DoUnsubscribePresenceGrantRequestListL()
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CPresencePluginAuthorization::DoUnsubscribePresenceGrantRequestListL(
       
   168     TXIMPRequestId aReqId )
       
   169     {
       
   170     DP_SDA("DoUnsubscribePresenceGrantRequestListL ");
       
   171     iConnObs.WinfoHandlerL()->UnsubscribeWinfoListL( aReqId );
       
   172     iSubscribed = EFalse;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CPresencePluginAuthorization::DoGrantPresenceForPresentityL()
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CPresencePluginAuthorization::DoGrantPresenceForPresentityL(
       
   180     const MXIMPIdentity& aPresentityId,
       
   181     const MPresenceInfoFilter& /*aPif*/,  // notice: pif support
       
   182     TXIMPRequestId aReqId )
       
   183     {
       
   184     DP_SDA("CPresencePluginAuthorization::DoGrantPresenceForPresentityL ");
       
   185     
       
   186     // Workaround for clients that can only grant when accepting buddy request.
       
   187     // SIMPLE also requires grant + subscribe so do both here even though
       
   188     // it is agains ximp api definitions.
       
   189     
       
   190     _LIT( KDefaultBuddyList, "buddylist" );
       
   191     
       
   192     iAuthState = EStateAcceptBuddyRequest;
       
   193     MXIMPIdentity* buddyList = iConnObs.ObjectFactory().NewIdentityLC(); 
       
   194     buddyList->SetIdentityL( KDefaultBuddyList() ); 
       
   195     
       
   196     iConnObs.GroupsL().DoAddPresentityGroupMemberL( *buddyList, aPresentityId,
       
   197         KNullDesC(), aReqId );
       
   198     CleanupStack::PopAndDestroy( 1 ); // buddyList 
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CPresencePluginAuthorization::DoPerformGrantPresenceForPresentityL()
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CPresencePluginAuthorization::DoPerformGrantPresenceForPresentityL(
       
   206     const MXIMPIdentity& aPresentityId,
       
   207     TRequestStatus& aClientStatus )
       
   208     {
       
   209     DP_SDA("CPresencePluginAuthorization::DoPerformGrantPresenceForPresentityL");
       
   210     StartXdmOperationL( aPresentityId, 
       
   211         EGrantPresenceForPresentity, aClientStatus );
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CPresencePluginAuthorization::DoUpdatePresenceGrantPifForPresentityL()
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CPresencePluginAuthorization::DoUpdatePresenceGrantPifForPresentityL(
       
   219     const MXIMPIdentity& /*aPresentityId*/,
       
   220     const MPresenceInfoFilter& /*aPif*/,
       
   221     TXIMPRequestId /*aReqId*/ )
       
   222     {
       
   223     // Notice: later
       
   224     User::Leave( KErrNotSupported );
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CPresencePluginAuthorization::DoWithdrawPresenceGrantFromPresentityL()
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CPresencePluginAuthorization::DoWithdrawPresenceGrantFromPresentityL(
       
   232     const MXIMPIdentity& aPresentityId,
       
   233     TXIMPRequestId aReqId )
       
   234     {
       
   235     DP_SDA("CPresencePluginAuth::DoWithdrawPresenceGrantFromPresentityL ");
       
   236     StartXdmOperationL( aPresentityId, aReqId, EWithdrawFromPresentity );
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CPresencePluginAuthorization::DoPerformWithdrawPresGrantFromPresentityL()
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CPresencePluginAuthorization::DoPerformWithdrawPresGrantFromPresentityL(
       
   244     const MXIMPIdentity& aPresentityId,
       
   245     TRequestStatus& aClientStatus )
       
   246     {
       
   247     DP_SDA("CPresencePluginAuthorization");
       
   248     DP_SDA(" -> DoPerformWithdrawPresGrantFromPresentityL");
       
   249     StartXdmOperationL( aPresentityId,
       
   250         EWithdrawFromPresentity, aClientStatus );
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CPresencePluginAuthorization::DoGrantPresenceForPresentityGroupMembersL()
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CPresencePluginAuthorization::DoGrantPresenceForPresentityGroupMembersL(
       
   258     const MXIMPIdentity& /*aGroupId*/,
       
   259     const MPresenceInfoFilter& /*aPif*/,
       
   260     TXIMPRequestId /*aReqId*/ )
       
   261     {
       
   262     DP_SDA("CPresencePluginAuthorization::DoGrantPresenceForPresentityGroupMembersL -not supported");
       
   263     
       
   264     User::Leave( KErrNotSupported );
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CPresencePluginAuthorization::
       
   269 // DoUpdatePresenceGrantPifForPresentityGroupMembersL()
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CPresencePluginAuthorization::
       
   273     DoUpdatePresenceGrantPifForPresentityGroupMembersL(
       
   274     const MXIMPIdentity& /*aGroupId*/,
       
   275     const MPresenceInfoFilter& /*aPif*/,
       
   276     TXIMPRequestId /*aReqId*/ )
       
   277     {
       
   278     DP_SDA("CPresencePluginAuthorization::DoUpdatePresenceGrantPifForPresentityGroupMembersL -not supported");
       
   279     
       
   280     User::Leave( KErrNotSupported );
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CPresencePluginAuthorization::
       
   285 // DoWithdrawPresenceGrantFromPresentityGroupMembersL()
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CPresencePluginAuthorization::
       
   289     DoWithdrawPresenceGrantFromPresentityGroupMembersL(
       
   290     const MXIMPIdentity& /*aGroupId*/,
       
   291     TXIMPRequestId /*aReqId*/ )
       
   292     {
       
   293     DP_SDA("CPresencePluginAuthorization::DoWithdrawPresenceGrantFromPresentityGroupMembersL -not supported");
       
   294     
       
   295     User::Leave( KErrNotSupported );
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // CPresencePluginAuthorization::DoGrantPresenceForEveryoneL()
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CPresencePluginAuthorization::DoGrantPresenceForEveryoneL(
       
   303     const MPresenceInfoFilter& /*aPif*/,
       
   304     TXIMPRequestId /*aReqId*/ )
       
   305     {
       
   306     DP_SDA("CPresencePluginAuthorization::DoGrantPresenceForEveryoneL -not supported");
       
   307     
       
   308     User::Leave( KErrNotSupported );
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CPresencePluginAuthorization::DoUpdatePresenceGrantPifForEveryoneL()
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CPresencePluginAuthorization::DoUpdatePresenceGrantPifForEveryoneL(
       
   316     const MPresenceInfoFilter& /*aPif*/,
       
   317     TXIMPRequestId /*aReqId*/ )
       
   318     {
       
   319     DP_SDA("CPresencePluginAuthorization::DoUpdatePresenceGrantPifForEveryoneL -not supported");
       
   320     
       
   321     User::Leave( KErrNotSupported );
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CPresencePluginAuthorization::DoWithdrawPresenceGrantFromEveryoneL()
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CPresencePluginAuthorization::DoWithdrawPresenceGrantFromEveryoneL(
       
   329     TXIMPRequestId /*aReqId*/ )
       
   330     {
       
   331     DP_SDA("CPresencePluginAuthorization::DoWithdrawPresenceGrantFromEveryoneL -not supported");
       
   332     
       
   333     User::Leave( KErrNotSupported );
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CPresencePluginAuthorization::DoSubscribePresenceBlockListL()
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CPresencePluginAuthorization::DoSubscribePresenceBlockListL(
       
   341     TXIMPRequestId aReqId )
       
   342     {
       
   343     DP_SDA("CPresencePluginAuthorization::DoSubscribePresenceBlockListL ");
       
   344     MXIMPIdentity* nobody = iConnObs.ObjectFactory().NewIdentityLC(); 
       
   345     StartXdmOperationL( *nobody, aReqId, ESubscribeBlockList );
       
   346     // Cannot PopAndDestroy by name
       
   347     CleanupStack::PopAndDestroy( );
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CPresencePluginAuthorization::DoUnsubscribePresenceBlockListL()
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void CPresencePluginAuthorization::DoUnsubscribePresenceBlockListL(
       
   355     TXIMPRequestId aReqId )
       
   356     {
       
   357     DP_SDA("CPresencePluginAuthorization::DoUnsubscribePresenceBlockListL ");
       
   358     MXIMPIdentity* nobody = iConnObs.ObjectFactory().NewIdentityLC();
       
   359     StartXdmOperationL( *nobody, aReqId, EUnsubscribeBlockList );
       
   360     // Cannot PopAndDestroy by name
       
   361     CleanupStack::PopAndDestroy();
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // CPresencePluginAuthorization::DoBlockPresenceForPresentityL()
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 void CPresencePluginAuthorization::DoBlockPresenceForPresentityL(
       
   369     const MXIMPIdentity& aPresentityId,
       
   370     TXIMPRequestId aReqId )
       
   371     {
       
   372     DP_SDA("CPresencePluginAuthorization::DoBlockPresenceForPresentityL ");
       
   373     StartXdmOperationL( aPresentityId, aReqId, EBlockPresentity );
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CPresencePluginAuthorization::DoPerformBlockPresenceForPresentityL()
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CPresencePluginAuthorization::DoPerformBlockPresenceForPresentityL(
       
   381     const MXIMPIdentity& aPresentityId,
       
   382     TRequestStatus& aClientStatus )
       
   383     {
       
   384     DP_SDA(
       
   385         "CPresencePluginAuthorization::DoPerformBlockPresenceForPresentityL");
       
   386     StartXdmOperationL( aPresentityId, EBlockPresentity, aClientStatus );
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPresencePluginAuthorization::DoCancelPresenceBlockFromPresentityL()
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CPresencePluginAuthorization::DoCancelPresenceBlockFromPresentityL(
       
   394     const MXIMPIdentity& aPresentityId,
       
   395     TXIMPRequestId aReqId )
       
   396     {
       
   397     DP_SDA(" DoCancelPresenceBlockFromPresentityL ");
       
   398     StartXdmOperationL( aPresentityId, aReqId, EUnblockPresentity );
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CPresencePluginAuthorization::DoPerformCancelPresenceBlockFromPresentityL()
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CPresencePluginAuthorization::DoPerformCancelPresenceBlockFromPresentityL(
       
   406     const MXIMPIdentity& aPresentityId,
       
   407     TRequestStatus& aClientStatus )
       
   408     {
       
   409     DP_SDA(" DoPerformCancelPresenceBlockFromPresentityL (list)");
       
   410     StartXdmOperationL( aPresentityId, EUnblockPresentity, aClientStatus );
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // CPresencePluginAuthorization::DoCancel()
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CPresencePluginAuthorization::DoCancel(  )
       
   418     {
       
   419     iXdmUtils->Cancel();
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CPresencePluginAuthorization::RunL()
       
   424 // ---------------------------------------------------------------------------
       
   425 //
       
   426 void CPresencePluginAuthorization::RunL(  )
       
   427     {
       
   428     TInt myStatus = iStatus.Int();
       
   429     
       
   430     DP_SDA2( "CPresencePluginAuthorization::RunL mystatus %d ", myStatus );
       
   431     DP_SDA2( "CPresencePluginAuthorization::RunL state %d ",iOperation );
       
   432     
       
   433     if ( !iXdmOk && !myStatus )
       
   434         {
       
   435         DP_SDA( "CPresencePluginAuthorization::RunL !iXdmOk && !myStatus" );
       
   436         iXdmOk = ETrue;
       
   437         CallActualXdmOperationL();
       
   438         }
       
   439     else if ( iClientStatus )
       
   440         {
       
   441         DP_SDA( "CPresencePluginAuthorization::RunL - complete client" );
       
   442         TRequestStatus* s = iClientStatus;
       
   443         User::RequestComplete( s, myStatus );
       
   444         iClientStatus = NULL;
       
   445         DP_SDA( "CPresencePluginAuthorization::RunL - complete client ok" );
       
   446         }
       
   447     else if ( !myStatus )
       
   448         {
       
   449         switch ( iAuthState )
       
   450             {
       
   451             case EStateDoBlock:
       
   452                 {
       
   453                 DP_SDA( "CPresencePluginAuthorization::RunL - Block presentity" );
       
   454                 BlockPresentityL();
       
   455                 iAuthState = EStateRemovePresentityFromGranted;
       
   456                 }
       
   457                 break;
       
   458                 
       
   459             case EStateRemovePresentityFromGranted:
       
   460                 {
       
   461                 DP_SDA( "CPresencePluginAuthorization::RunL - Remove presentity from granted" );
       
   462                 WithdrawFromPresentityL();
       
   463                 iAuthState = EStateBlocked;
       
   464                 }
       
   465                 break;
       
   466             
       
   467             case EStateBlocked:
       
   468                 {
       
   469                 DP_SDA( "CPresencePluginAuthorization::RunL - Blocked" );
       
   470                 SetPresentityBlockedToXIMPL();
       
   471                 iAuthState = EStateIdle;
       
   472                 CompleteXIMPReq( myStatus );
       
   473                 }
       
   474                 break;
       
   475 
       
   476             case EStateIsContactBlockedBuddyRequest:
       
   477                 {
       
   478                 DP_SDA( "CPresencePluginAuthorization::RunL - Resolve contact type" );
       
   479                 // resolve is contact blocked friend request
       
   480                 HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
   481                 IsBlockedContactFriendRequestL( *withoutPrefix, *this, iStatus );
       
   482                 CleanupStack::PopAndDestroy( withoutPrefix );
       
   483                 SetActive();
       
   484                 iAuthState = EStateDoUnBlock;
       
   485                 }
       
   486                 break;
       
   487                 
       
   488             case EStateDoUnBlock:
       
   489                 {
       
   490                 if ( iContactIsStored )
       
   491                     {
       
   492                     DP_SDA( "CPresencePluginAuthorization::RunL - Grant presence for presentity" );
       
   493                     GrantPresenceForPresentityL();
       
   494                     iAuthState = EStatePresenceGranted;
       
   495                     }
       
   496                 else
       
   497                     {
       
   498                     DP_SDA( "CPresencePluginAuthorization::RunL - Complete unblock" );
       
   499                     iAuthState = EStateIdle;
       
   500                     CompleteXIMPReq( myStatus );
       
   501                     }
       
   502                 }
       
   503                 break;
       
   504             
       
   505             case EStatePresenceGranted:
       
   506                 {
       
   507                 DP_SDA( "CPresencePluginAuthorization::RunL -Subscribe presentity presence" );  
       
   508                 MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
       
   509                 identity->SetIdentityL( iPresIdentity->Des() ); 
       
   510                 iConnObs.WatcherHandlerL()->DoPerformSubscribePresentityPresenceL( *identity, iStatus );
       
   511                 CleanupStack::PopAndDestroy( ); //identity 
       
   512                 iAuthState = EStateSubscribe;
       
   513                 SetActive();
       
   514                 }
       
   515                 break;
       
   516                 
       
   517             case EStateSubscribe:
       
   518                 {
       
   519                 DP_SDA( "CPresencePluginAuthorization::RunL -UnBlock completed" ); 
       
   520                 HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
   521                 iPresenceData->WriteStatusToCacheL( *withoutPrefix, 
       
   522                     MPresenceBuddyInfo2::ENotAvailable,
       
   523                     KInvisibleState(),
       
   524                     KNullDesC() );
       
   525                 CleanupStack::PopAndDestroy( withoutPrefix );
       
   526                 iAuthState = EStateIdle;
       
   527                 CompleteXIMPReq( myStatus );
       
   528                 }
       
   529                 break;
       
   530                 
       
   531             default:
       
   532                 {
       
   533                 DP_SDA( "CPresencePluginAuthorization::RunL - default case" );
       
   534                 CompleteXIMPReq( myStatus );
       
   535                 }
       
   536                 break;
       
   537             }
       
   538         }
       
   539     else if ( KErrNotFound == myStatus && EStateDoBlock == iAuthState )
       
   540         {
       
   541         // When blocking friend request, watcher was not found but request
       
   542         // has to be blocked anyways.
       
   543         DP_SDA( "CPresencePluginAuthorization::RunL - Block presentity" );
       
   544         BlockPresentityL();
       
   545         iAuthState = EStateBlocked;
       
   546         }
       
   547     else
       
   548         {
       
   549         DP_SDA( "CPresencePluginAuthorization::RunL -error" );
       
   550         CompleteXIMPReq( myStatus );
       
   551         }
       
   552         
       
   553     if ( EStateAcceptBuddyRequest == iAuthState && EGrantPresenceForPresentity == iOperation )
       
   554         {
       
   555         iAuthState = EStateIdle;
       
   556         HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
   557         CallHandlePresenceGrantRequestObsoletedL( *withoutPrefix );
       
   558         iConnObs.SubscribedContacts()->HandlePresentityGroupMemberAddedL( *withoutPrefix );
       
   559         CleanupStack::PopAndDestroy( withoutPrefix );
       
   560         }
       
   561     
       
   562     DP_SDA( "CPresencePluginAuthorization::RunL - exit" );
       
   563     }
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 // CPresencePluginAuthorization::CallActualXdmOperationL()
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 void CPresencePluginAuthorization::CallActualXdmOperationL()
       
   570     {
       
   571     DP_SDA("CPresencePluginAuthorization::CallActualXdmOperationL ");
       
   572     DP_SDA2("CallActualXdmOperationL operation %d", iOperation );
       
   573     iComplete = EFalse;
       
   574     switch ( iOperation )
       
   575         {
       
   576         case EGrantPresenceForPresentity:
       
   577             {
       
   578             DP_SDA("CallActualXdmOperationL EGrantPresenceForPresentity");
       
   579             GrantPresenceForPresentityL();
       
   580             }
       
   581             break;
       
   582             
       
   583         case EWithdrawFromPresentity:
       
   584             {
       
   585             DP_SDA("CallActualXdmOperationL EWithdrawFromPresentity");
       
   586             WithdrawFromPresentityL();
       
   587             }
       
   588             break;
       
   589             
       
   590         case ESubscribeBlockList:
       
   591             {
       
   592             SubscribeBlockListL( );
       
   593             }
       
   594             break;
       
   595             
       
   596         case EUnsubscribeBlockList:
       
   597             {
       
   598             UnSubscribeBlockListL();
       
   599             }
       
   600             break;
       
   601             
       
   602         case EBlockPresentity:
       
   603             {
       
   604             DP_SDA( "CallActualXdmOperationL EBlockPresentity" );
       
   605             
       
   606             TRAPD( error, UnsubscribePresentityPresenceL() );
       
   607             
       
   608             if( error )
       
   609                 {
       
   610                 DP_SDA2( "Unsubscribe presentity FAIL, error = %d" , error );
       
   611                 
       
   612                 if ( KErrNotFound != error  )
       
   613                     {
       
   614                     User::Leave( error );
       
   615                     }
       
   616                 BlockPresentityL();
       
   617                 iAuthState = EStateBlocked;
       
   618                 }
       
   619             else
       
   620                 {
       
   621                 iAuthState = EStateDoBlock;
       
   622                 }
       
   623             }
       
   624             break;
       
   625             
       
   626         case EUnblockPresentity:
       
   627             {
       
   628             DP_SDA("CallActualXdmOperationL EUnblockPresentity"); 
       
   629             UnblockPresentityL();
       
   630             }
       
   631             break;
       
   632             
       
   633         default:
       
   634             User::Leave( KErrNotSupported );
       
   635             break;
       
   636         }
       
   637     DP_SDA("CPresencePluginAuthorization::CallActualXdmOperationL end");
       
   638     }
       
   639 
       
   640 // ---------------------------------------------------------------------------
       
   641 // CPresencePluginAuthorization::RunError()
       
   642 // ---------------------------------------------------------------------------
       
   643 //
       
   644 TInt CPresencePluginAuthorization::RunError( TInt aError )
       
   645     {
       
   646     // complete the open request
       
   647     CompleteXIMPReq( aError );
       
   648     return KErrNone;
       
   649     }
       
   650 
       
   651 // ---------------------------------------------------------------------------
       
   652 // CPresencePluginAuthorization::GetInterface()
       
   653 // ---------------------------------------------------------------------------
       
   654 //
       
   655 TAny* CPresencePluginAuthorization::GetInterface(
       
   656     TInt32 aInterfaceId,
       
   657     TIfGetOps aOptions )
       
   658     {
       
   659     if ( aInterfaceId == GetInterfaceId() )
       
   660         {
       
   661         // caller wants this interface
       
   662         return this;
       
   663         }
       
   664     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   665         {
       
   666         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   667         }  
       
   668     return NULL;
       
   669     }
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // CPresencePluginAuthorization::GetInterface() const
       
   673 // ---------------------------------------------------------------------------
       
   674 //
       
   675 const TAny* CPresencePluginAuthorization::GetInterface(
       
   676     TInt32 aInterfaceId,
       
   677     TIfGetOps aOptions ) const
       
   678     {
       
   679     if ( aInterfaceId == GetInterfaceId() )
       
   680         {
       
   681         // caller wants this interface
       
   682         return const_cast<CPresencePluginAuthorization*>(this);
       
   683         }
       
   684     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   685         {
       
   686         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   687         }  
       
   688     return NULL;
       
   689     }
       
   690     
       
   691 // ---------------------------------------------------------------------------
       
   692 // CPresencePluginAuthorization::GetInterfaceId()
       
   693 // ---------------------------------------------------------------------------
       
   694 //
       
   695 TInt32 CPresencePluginAuthorization::GetInterfaceId() const
       
   696     {
       
   697     return MProtocolPresenceAuthorization::KInterfaceId;
       
   698     }
       
   699 
       
   700 // ---------------------------------------------------------------------------
       
   701 // CPresencePluginAuthorization::SetPresIdentityL()
       
   702 // ---------------------------------------------------------------------------
       
   703 //
       
   704 void CPresencePluginAuthorization::SetPresIdentityL(
       
   705     const MXIMPIdentity& aPresentityId,
       
   706     TBool aFormatUri )
       
   707     {  
       
   708     DP_SDA2("CPresencePluginAuthorization::SetPresIdentityL: %S",
       
   709         &aPresentityId.Identity() );
       
   710     
       
   711     delete iPresIdentity;
       
   712     iPresIdentity = NULL;
       
   713     
       
   714     if ( aFormatUri )
       
   715         {
       
   716         DP_SDA("CPresencePluginAuthorization::SetPresIdentityL, add prefix");
       
   717         
       
   718         HBufC8* identityCopy = HBufC8::NewLC( KBufSize255 );
       
   719         TPtr8 identityCopyPtr( identityCopy->Des() );
       
   720         identityCopyPtr.Copy( aPresentityId.Identity() );
       
   721         
       
   722         HBufC8* prefixUri = iPresenceData->CreatePresenceUri8LC( 
       
   723             identityCopyPtr );
       
   724         
       
   725         HBufC* prefixUri16 = HBufC::NewLC( KBufSize255 );
       
   726         TPtr prefixUri16Ptr( prefixUri16->Des() );
       
   727         prefixUri16Ptr.Copy( *prefixUri );
       
   728         
       
   729         iPresIdentity = prefixUri16;
       
   730         CleanupStack::Pop( prefixUri16 );
       
   731         CleanupStack::PopAndDestroy( prefixUri );
       
   732         CleanupStack::PopAndDestroy( identityCopy );
       
   733         }
       
   734     else
       
   735         {
       
   736         DP_SDA(" SetPresIdentityL, use as it is");
       
   737         iPresIdentity = aPresentityId.Identity().AllocL();
       
   738         }
       
   739     DP_SDA( "CPresencePluginAuthorization::SetPresIdentityL -exit" );
       
   740     }
       
   741 
       
   742 // ---------------------------------------------------------------------------
       
   743 // CPresencePluginAuthorization::WinfoNotificationL()
       
   744 // ---------------------------------------------------------------------------
       
   745 //
       
   746 void CPresencePluginAuthorization::WinfoNotificationL(
       
   747     MSimpleWinfo& aWinfo )
       
   748     {
       
   749     DP_SDA("CPresencePluginAuthorization::WinfoNotificationL");
       
   750     // Ignore notification if not subscribed
       
   751     using namespace NPresencePlugin::NPresence;
       
   752     
       
   753     RPointerArray<MSimpleElement> elems;
       
   754     CleanupClosePushL( elems );
       
   755     TInt err = aWinfo.SimpleElementsL( elems );
       
   756     User::LeaveIfError( err );
       
   757     TInt count = elems.Count();
       
   758     
       
   759     DP_SDA2("CPresencePluginAuthorization::WinfoNotificationL count %d",
       
   760         count);
       
   761     
       
   762     if ( !count ) 
       
   763         { 
       
   764         // stop parsing empty notification 
       
   765         DP_SDA("CPresencePluginAuthorization::WinfoNotificationL LEAVE");
       
   766         User::Leave( KErrArgument ); 
       
   767         } 
       
   768     
       
   769     const TDesC8* stateVal = aWinfo.AttrValue( KPresenceState8 ); 
       
   770     if ( stateVal && !stateVal->CompareF( KPresenceFull8 )) 
       
   771         { 
       
   772         // Call full list method
       
   773         DP_SDA("CPresencePluginAuthorization::WinfoNotificationL FULL winfo");
       
   774         HandleFullWinfoNotificationL( aWinfo ); 
       
   775         } 
       
   776     else 
       
   777         { 
       
   778         // Indicate changes in WINFO list one by one.
       
   779         DP_SDA("CPresencePluginAuthorization::WinfoNotificationLPARTIAL winfo");
       
   780         HandlePartialWinfoNotificationL( aWinfo );
       
   781         } 
       
   782     CleanupStack::PopAndDestroy( &elems );
       
   783     DP_SDA("CPresencePluginAuthorization::WinfoNotificationL end");
       
   784     }
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // CPresencePluginAuthorization::StartXdmOperationL()
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 void CPresencePluginAuthorization::StartXdmOperationL(
       
   791     const MXIMPIdentity& aId,
       
   792     TXIMPRequestId aReqId,
       
   793     TPluginAuthOperation aOperation )
       
   794     {
       
   795     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrNotReady ) );
       
   796     DP_SDA("CPresencePluginAuthorization::StartXdmOperationL 2");
       
   797     SetPresIdentityL( aId, ETrue );
       
   798     
       
   799     iXIMPId = aReqId;
       
   800     iOperation = aOperation;
       
   801     if ( !iXdmUtils )
       
   802         {
       
   803         DP_SDA("StartXdmOperationL !iXdmUtils");
       
   804         iXdmUtils = iConnObs.XdmUtilsL();
       
   805         }
       
   806     if ( iXdmUtils->CheckXdmDoc() )
       
   807         {
       
   808         DP_SDA("StartXdmOperationL iXdmOk");
       
   809         iXdmOk = ETrue;
       
   810         CallActualXdmOperationL();
       
   811         }
       
   812     else
       
   813         {
       
   814         DP_SDA("StartXdmOperationL else");
       
   815         iXdmUtils->InitializeXdmL( iStatus );
       
   816         SetActive();
       
   817         }
       
   818     DP_SDA("CPresencePluginAuthorization::StartXdmOperationL end");
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // CPresencePluginAuthorization::StartXdmOperationL()
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 void CPresencePluginAuthorization::StartXdmOperationL(
       
   826     const MXIMPIdentity& aId,
       
   827     TPluginAuthOperation aOperation,
       
   828     TRequestStatus& aClientStatus )
       
   829     {
       
   830     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrNotReady ) );
       
   831     DP_SDA("CPresencePluginAuthorization::StartXdmOperationL 3 (list)");
       
   832     
       
   833     SetPresIdentityL( aId, EFalse );
       
   834     
       
   835     iClientStatus = &aClientStatus;
       
   836     *iClientStatus = KRequestPending;
       
   837     
       
   838     iOperation = aOperation;
       
   839     
       
   840     if ( !iXdmUtils )
       
   841         {
       
   842         DP_SDA("StartXdmOperationL !iXdmUtils");
       
   843         iXdmUtils = iConnObs.XdmUtilsL();
       
   844         }
       
   845     if ( iXdmUtils->CheckXdmDoc() )
       
   846         {
       
   847         DP_SDA("StartXdmOperationL iXdmOk");
       
   848         iXdmOk = ETrue;
       
   849         CallActualXdmOperationL();
       
   850         }
       
   851     else
       
   852         {
       
   853         DP_SDA("StartXdmOperationL else");
       
   854         iXdmUtils->InitializeXdmL( iStatus );
       
   855         SetActive();
       
   856         }
       
   857     DP_SDA("CPresencePluginAuthorization::StartXdmOperationL end");
       
   858     }
       
   859 
       
   860 // ---------------------------------------------------------------------------
       
   861 // CPresencePluginAuthorization::CompleteXIMPReq()
       
   862 // ---------------------------------------------------------------------------
       
   863 //
       
   864 void CPresencePluginAuthorization::CompleteXIMPReq( TInt aStatus )
       
   865     {
       
   866     DP_SDA("CPresencePluginAuthorization::CompleteXIMPReq");
       
   867     iOperation = ENoOperation;
       
   868     iConnObs.CompleteReq( iXIMPId, aStatus );
       
   869     iXIMPId = TXIMPRequestId();
       
   870     DP_SDA("CPresencePluginAuthorization::CompleteXIMPReq end");
       
   871     }
       
   872 
       
   873 // ---------------------------------------------------------------------------
       
   874 // CPresencePluginAuthorization::SubscribeBlockListL()
       
   875 // ---------------------------------------------------------------------------
       
   876 //
       
   877 void CPresencePluginAuthorization::SubscribeBlockListL()
       
   878     {
       
   879     DP_SDA("CPresencePluginAuthorization::SubscribeBlockList");
       
   880     
       
   881     RPointerArray<MXIMPIdentity> blocked;
       
   882     CleanupStack::PushL( TCleanupItem(
       
   883         TPresencePluginUtility::ResetAndDestroyIdentities,
       
   884         &blocked ) );
       
   885     
       
   886     iXdmUtils->SubscribeBlockListL( blocked );
       
   887     MXIMPObjectCollection* coll =
       
   888         iConnObs.ObjectFactory().NewObjectCollectionLC(); // << coll
       
   889     
       
   890     TInt count = blocked.Count();
       
   891     for ( TInt i = 0; i < count; i++ )
       
   892         {
       
   893         MXIMPIdentity* currId = blocked[i];
       
   894         HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( currId->Identity() );
       
   895         currId->SetIdentityL( *withoutPrefix );
       
   896         CleanupStack::PopAndDestroy( withoutPrefix );
       
   897         MPresenceBlockInfo* bInfo =
       
   898             iConnObs.PresenceObjectFactoryOwn().NewPresenceBlockInfoLC();
       
   899         bInfo->SetBlockedEntityIdL( currId ); // ownership is taken
       
   900         blocked.Remove( i ); // remove currId from blocked
       
   901         blocked.InsertL( NULL, i );
       
   902         bInfo->SetBlockedEntityDisplayNameL( currId->Identity() );
       
   903         coll->AddObjectL( bInfo );// ownership is taken
       
   904         CleanupStack::Pop();// >> bInfo
       
   905         }
       
   906     
       
   907     DP_SDA("SubscribeBlockList complete request");
       
   908     CompleteXIMPReq( KErrNone );
       
   909     
       
   910     MXIMPDataSubscriptionState* myState =
       
   911        iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
   912     
       
   913     MXIMPStatus* myStatus = iConnObs.ObjectFactory().NewStatusLC();
       
   914     
       
   915     // Notice: consider XIMP error codes
       
   916     myStatus->SetResultCode( KErrNone );
       
   917     myState->SetSubscriptionStateL(
       
   918         MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   919     
       
   920     iDataHost->SetPresenceBlockDataSubscriptionStateL(
       
   921         myState, myStatus );
       
   922     
       
   923     iDataHost->HandlePresenceBlockListL( coll );
       
   924     //Callback for subscription result
       
   925     CleanupStack::Pop( 3 ); // >> myState, myStatus, coll
       
   926     CleanupStack::PopAndDestroy( &blocked );
       
   927     DP_SDA("CPresencePluginAuthorization::SubscribeBlockList end");
       
   928     }
       
   929 
       
   930 // ---------------------------------------------------------------------------
       
   931 // CPresencePluginAuthorization::UnSubscribeBlockListL()
       
   932 // ---------------------------------------------------------------------------
       
   933 //
       
   934 void CPresencePluginAuthorization::UnSubscribeBlockListL()
       
   935     {
       
   936     DP_SDA("CPresencePluginAuthorization::UnSubscribeBlockListL");
       
   937     
       
   938     MXIMPObjectCollection* coll =
       
   939         iConnObs.ObjectFactory().NewObjectCollectionLC();
       
   940     
       
   941     MXIMPDataSubscriptionState* myState =
       
   942         iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
   943     
       
   944     MXIMPStatus* myStatus = iConnObs.ObjectFactory().NewStatusLC();
       
   945     
       
   946     myStatus->SetResultCode( KErrNone );
       
   947     myState->SetSubscriptionStateL(
       
   948         MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   949     
       
   950     iDataHost->SetPresenceBlockDataSubscriptionStateL(
       
   951         myState, myStatus );
       
   952     
       
   953     iDataHost->HandlePresenceBlockListL( coll );
       
   954     
       
   955     CleanupStack::Pop( 3 );
       
   956     
       
   957     CompleteXIMPReq( KErrNone );
       
   958     
       
   959     DP_SDA("CPresencePluginAuthorization::UnSubscribeBlockListL end");
       
   960     }
       
   961 
       
   962 // ---------------------------------------------------------------------------
       
   963 // CPresencePluginAuthorization::ReturnListSubsState()
       
   964 // ---------------------------------------------------------------------------
       
   965 //
       
   966 TBool CPresencePluginAuthorization::ReturnListSubsState()
       
   967     {
       
   968     return iSubscribed;
       
   969     }
       
   970 
       
   971 // ---------------------------------------------------------------------------
       
   972 // CPresencePluginAuthorization::PluginData()
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 CPresencePluginData& CPresencePluginAuthorization::PluginData()
       
   976     {
       
   977     return *iPresenceData;
       
   978     }
       
   979 
       
   980 // --------------------------------------------------------------------------- 
       
   981 // CPresencePluginAuthorization::HandleFullWinfoNotificationL 
       
   982 // --------------------------------------------------------------------------- 
       
   983 // 
       
   984 void CPresencePluginAuthorization::HandleFullWinfoNotificationL( 
       
   985     MSimpleWinfo& aWinfo )
       
   986     {
       
   987     using namespace NPresencePlugin::NPresence;
       
   988     
       
   989     RPointerArray<MSimpleElement> elems;
       
   990     CleanupClosePushL( elems );
       
   991     TInt err = aWinfo.SimpleElementsL( elems );
       
   992     User::LeaveIfError( err );
       
   993     TInt count = elems.Count();
       
   994     
       
   995     MSimpleElement* elem = elems[0];
       
   996     TPtrC8 p8 = elem->LocalName();
       
   997     err = p8.CompareF( KPresenceWatcherList8 ); //watcher-list
       
   998     DP_SDA2("HandleFullWinfoNotificationL leave if watcherlist error %d", err);
       
   999     User::LeaveIfError( err );
       
  1000     
       
  1001     err = elem->SimpleElementsL( elems );
       
  1002     DP_SDA2("HandleFullWinfoNotificationL error %d", err);
       
  1003     User::LeaveIfError( err );
       
  1004     
       
  1005     count = elems.Count();
       
  1006     DP_SDA("HandleFullWinfoNotificationL watcher list is valid");
       
  1007     
       
  1008     // Search watchers who are pending (status = pending)
       
  1009     HBufC* nodeContent = NULL;
       
  1010     MXIMPObjectCollection *pendings =
       
  1011         iConnObs.ObjectFactory().NewObjectCollectionLC();
       
  1012     
       
  1013     TBool pendingFound(EFalse);
       
  1014     
       
  1015     for ( TInt i = 0; i < count; i++ )
       
  1016         {
       
  1017         elem = elems[i];
       
  1018         p8.Set( elem->LocalName());
       
  1019         if (!( p8.CompareF( KPresenceWatcher8 )))
       
  1020             {
       
  1021             const TDesC8* pp8 = elem->AttrValue( KPresenceStatus8 );
       
  1022             if ( pp8 && !pp8->CompareF( KPresencePending8 ))
       
  1023                 {
       
  1024                 DP_SDA("HandleFullWinfoNotificationL least one pending");
       
  1025                 // Build collection of grant requests
       
  1026                 // Find the child node containing the SIP entity
       
  1027                 nodeContent = elem->ContentUnicodeL();
       
  1028                 CleanupStack::PushL( nodeContent );
       
  1029                 // create the collection entry here 
       
  1030                 MPresenceGrantRequestInfo* grInfo =
       
  1031                    iConnObs.PresenceObjectFactoryOwn().
       
  1032                        NewPresenceGrantRequestInfoLC();
       
  1033                 MXIMPIdentity* identity =
       
  1034                     iConnObs.ObjectFactory().NewIdentityLC();
       
  1035                 
       
  1036                 // Remove prefix to keep client side protocol agnostic
       
  1037                 HBufC16* withoutPrefix = iPresenceData->RemovePrefixLC( 
       
  1038                     *nodeContent );
       
  1039                 identity->SetIdentityL( *withoutPrefix );
       
  1040                 CleanupStack::PopAndDestroy( withoutPrefix );
       
  1041                 
       
  1042                 grInfo->SetRequestorIdL( identity ); // ownership is taken
       
  1043                 
       
  1044                 pendings->AddObjectL( grInfo ); // ownership is taken
       
  1045                 pendingFound = ETrue;
       
  1046                 CleanupStack::Pop( 2 ); //grInfo, identity
       
  1047                 CleanupStack::PopAndDestroy( nodeContent );
       
  1048                 }
       
  1049             }
       
  1050         }
       
  1051     
       
  1052     if ( pendingFound )
       
  1053         {
       
  1054         DP_SDA("HandleFullWinfoNotificationL send pending");
       
  1055         iXIMPIdOwn = iDataHost->HandlePresenceGrantRequestListL( pendings );
       
  1056         CleanupStack::Pop();    // >> pendings
       
  1057         }
       
  1058     else
       
  1059         {
       
  1060         DP_SDA("HandleFullWinfoNotificationL pop pending");
       
  1061         CleanupStack::PopAndDestroy( ); // >> pendings
       
  1062         }
       
  1063     
       
  1064     CleanupStack::PopAndDestroy( &elems );
       
  1065     DP_SDA("CPresencePluginAuthorization::HandleFullWinfoNotificationL END");
       
  1066     } 
       
  1067  
       
  1068 // --------------------------------------------------------------------------- 
       
  1069 // CPresencePluginAuthorization::HandlePartialWinfoNotificationL 
       
  1070 // --------------------------------------------------------------------------- 
       
  1071 // 
       
  1072 void CPresencePluginAuthorization::HandlePartialWinfoNotificationL( 
       
  1073     MSimpleWinfo& aWinfo )
       
  1074     {
       
  1075     DP_SDA("CPresencePluginAuthorization::HandlePartialWinfoNotificationL");
       
  1076     using namespace NPresencePlugin::NPresence;
       
  1077     
       
  1078     RPointerArray<MSimpleElement> elems;
       
  1079     CleanupClosePushL( elems );
       
  1080     TInt err = aWinfo.SimpleElementsL( elems );
       
  1081     User::LeaveIfError( err );
       
  1082     TInt count = elems.Count();
       
  1083     
       
  1084     MSimpleElement* elem = elems[0];
       
  1085     TPtrC8 p8 = elem->LocalName();
       
  1086     err = p8.CompareF( KPresenceWatcherList8 );
       
  1087     User::LeaveIfError( err );
       
  1088     
       
  1089     err = elem->SimpleElementsL( elems );
       
  1090     User::LeaveIfError( err );
       
  1091     count = elems.Count();
       
  1092     
       
  1093     HBufC* nodeContent = NULL;
       
  1094     
       
  1095     for ( TInt i = 0; i < count; i++ )
       
  1096         {
       
  1097         elem = elems[i]; 
       
  1098         p8.Set( elem->LocalName());
       
  1099         if (!( p8.CompareF( KPresenceWatcher8 )))
       
  1100             { 
       
  1101             const TDesC8* pp8 = elem->AttrValue( KPresenceStatus8 );
       
  1102             if ( pp8 && !pp8->CompareF( KPresencePending8 ))
       
  1103                 {
       
  1104                 nodeContent = elem->ContentUnicodeL();
       
  1105                 CleanupStack::PushL( nodeContent );
       
  1106                 
       
  1107                 // Remove prefix to keep client side protocol agnostic
       
  1108                 HBufC16* withoutPrefix = iPresenceData->RemovePrefixLC( 
       
  1109                     *nodeContent );
       
  1110                 CallHandlePresenceGrantRequestReceivedL( *withoutPrefix ); 
       
  1111                 CleanupStack::PopAndDestroy( withoutPrefix );
       
  1112                 CleanupStack::PopAndDestroy( nodeContent ); 
       
  1113                 } 
       
  1114             else if ( pp8 && !pp8->CompareF( KPresenceTerminated8 )) 
       
  1115                 {
       
  1116                 nodeContent = elem->ContentUnicodeL(); 
       
  1117                 CleanupStack::PushL( nodeContent ); 
       
  1118 
       
  1119                 // Remove prefix to keep client side protocol agnostic
       
  1120                 HBufC16* withoutPrefix = iPresenceData->RemovePrefixLC( 
       
  1121                     *nodeContent );
       
  1122                 CallHandlePresenceGrantRequestObsoletedL( *withoutPrefix ); 
       
  1123                 CleanupStack::PopAndDestroy( withoutPrefix );
       
  1124                 CleanupStack::PopAndDestroy( nodeContent ); 
       
  1125                 }
       
  1126             else if ( pp8 && !pp8->CompareF( KPresenceActive8 ))
       
  1127                 {
       
  1128                 DP_SDA( "CPresencePluginAuthorization::HandlePartialWinfoNotificationL presence active" );
       
  1129                 
       
  1130                 nodeContent = elem->ContentUnicodeL();
       
  1131                 CleanupStack::PushL( nodeContent );
       
  1132                 TInt pos( 0 );
       
  1133                 if ( iConnObs.SubscribedContacts()->
       
  1134                     GetVirtualIdentityArray()->Find( *nodeContent, pos ) == 0  )
       
  1135                     {
       
  1136                     HBufC8* buffer = HBufC8::NewLC( nodeContent->Length() );
       
  1137                     buffer->Des().Copy( *nodeContent );
       
  1138                     if ( !iConnObs.WatcherHandlerL()->MatchWatcherId( *buffer ) )
       
  1139                         {
       
  1140                         DP_SDA( "CPresencePluginAuthorization::HandlePartialWinfoNotificationL -subscribe presence" );
       
  1141                         iConnObs.WatcherHandlerL()->SubscribeL( *nodeContent );
       
  1142                         }
       
  1143                     CleanupStack::PopAndDestroy( buffer );
       
  1144                     }
       
  1145                 CleanupStack::PopAndDestroy( nodeContent );
       
  1146                 }
       
  1147             }
       
  1148         }
       
  1149     CleanupStack::PopAndDestroy( &elems );
       
  1150     DP_SDA("CPresencePluginAuthorization::HandlePartialWinfoNotificationL END");
       
  1151     } 
       
  1152 
       
  1153 // --------------------------------------------------------------------------- 
       
  1154 // CPresencePluginAuthorization::CallHandlePresenceGrantRequestReceivedL 
       
  1155 // --------------------------------------------------------------------------- 
       
  1156 // 
       
  1157 void CPresencePluginAuthorization::CallHandlePresenceGrantRequestReceivedL(
       
  1158     const TDesC& aUserId ) 
       
  1159     {
       
  1160     DP_SDA("PluginAuthorization::CallHandlePresenceGrantRequestReceivedL");
       
  1161     // create the collection entry here 
       
  1162     MPresenceGrantRequestInfo* grInfo = 
       
  1163         iConnObs.PresenceObjectFactoryOwn().NewPresenceGrantRequestInfoLC();
       
  1164     MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
       
  1165     identity->SetIdentityL( aUserId ); 
       
  1166     grInfo->SetRequestorIdL( identity ); // ownership is taken
       
  1167     CleanupStack::Pop( ); // -identity 
       
  1168     
       
  1169     iDataHost->HandlePresenceGrantRequestReceivedL( grInfo );//ownership taken 
       
  1170     CleanupStack::Pop( );           // -grInfo
       
  1171     DP_SDA("PluginAuthorization::CallHandlePresenceGrantRequestReceivedL END");
       
  1172     } 
       
  1173 
       
  1174 // --------------------------------------------------------------------------- 
       
  1175 // CPresencePluginAuthorization::CallHandlePresenceGrantRequestObsoletedL 
       
  1176 // --------------------------------------------------------------------------- 
       
  1177 // 
       
  1178 void CPresencePluginAuthorization::CallHandlePresenceGrantRequestObsoletedL(
       
  1179     const TDesC& aUserId )
       
  1180     {
       
  1181     DP_SDA("PluginAuthorization::CallHandlePresenceGrantRequestObsoletedL");
       
  1182     MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC(); 
       
  1183     identity->SetIdentityL( aUserId ); 
       
  1184     iDataHost->HandlePresenceGrantRequestObsoletedL( identity );//taken 
       
  1185     CleanupStack::Pop( );// >> identity
       
  1186     DP_SDA("PluginAuthorization::CallHandlePresenceGrantRequestObsoletedL END");
       
  1187     }
       
  1188 
       
  1189 // ---------------------------------------------------------------------------
       
  1190 // CPresencePluginAuthorization::GrantPresenceForPresentityL()
       
  1191 // ---------------------------------------------------------------------------
       
  1192 //
       
  1193 void CPresencePluginAuthorization::GrantPresenceForPresentityL()
       
  1194     {
       
  1195     iXdmUtils->AddEntityToGrantedL( 
       
  1196         iPresIdentity->Des(), iStatus );
       
  1197     SetActive();
       
  1198     }
       
  1199 
       
  1200 // ---------------------------------------------------------------------------
       
  1201 // CPresencePluginAuthorization::WithdrawFromPresentityL()
       
  1202 // ---------------------------------------------------------------------------
       
  1203 //
       
  1204 void CPresencePluginAuthorization::WithdrawFromPresentityL()
       
  1205     {
       
  1206     iXdmUtils->RemoveEntityFromGrantedL( 
       
  1207         iPresIdentity->Des(),iStatus );
       
  1208     SetActive();
       
  1209     }
       
  1210 
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // CPresencePluginAuthorization::UnsubscribePresentityPresenceL()
       
  1213 // ---------------------------------------------------------------------------
       
  1214 //
       
  1215 void CPresencePluginAuthorization::UnsubscribePresentityPresenceL()
       
  1216     {
       
  1217     DP_SDA( "CPresencePluginAuthorization::UnsubscribePresentityPresence" );
       
  1218     
       
  1219     MXIMPIdentity* identity =
       
  1220         iConnObs.ObjectFactory().NewIdentityLC();
       
  1221     identity->SetIdentityL( iPresIdentity->Des() );
       
  1222     iConnObs.WatcherHandlerL()->
       
  1223         DoPerformUnsubscribePresentityPresenceL( *identity, iStatus );
       
  1224     CleanupStack::PopAndDestroy(); // identity
       
  1225     SetActive();
       
  1226     
       
  1227     DP_SDA( "CPresencePluginAuthorization::UnsubscribePresentityPresence -Exit" );
       
  1228     }
       
  1229 
       
  1230 // ---------------------------------------------------------------------------
       
  1231 // CPresencePluginAuthorization::BlockPresentityL()
       
  1232 // ---------------------------------------------------------------------------
       
  1233 //
       
  1234 void CPresencePluginAuthorization::BlockPresentityL()
       
  1235     {
       
  1236     DP_SDA( "CPresencePluginAuthorization::BlockPresentityL" );
       
  1237     // add entity to block list
       
  1238     iXdmUtils->AddEntityToBlockedL( 
       
  1239         iPresIdentity->Des(), iStatus );
       
  1240     SetActive();
       
  1241     }
       
  1242 
       
  1243 // ---------------------------------------------------------------------------
       
  1244 // CPresencePluginAuthorization::BlockPresentityL()
       
  1245 // ---------------------------------------------------------------------------
       
  1246 //
       
  1247 void CPresencePluginAuthorization::SetPresentityBlockedToXIMPL()
       
  1248     {
       
  1249     DP_SDA( "CPresencePluginAuthorization::SetPresentityBlockedToXIMPL" );
       
  1250     
       
  1251     MPresenceBlockInfo* bInfo =
       
  1252         iConnObs.PresenceObjectFactoryOwn().NewPresenceBlockInfoLC();
       
  1253     MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
       
  1254     HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
  1255     identity->SetIdentityL( *withoutPrefix ); 
       
  1256     bInfo->SetBlockedEntityIdL( identity ); // ownership is taken
       
  1257     // Write blocked state into the presence cache
       
  1258     TBuf<20> buf;
       
  1259     buf.Copy( KBlockedExtensionValue );
       
  1260     iPresenceData->WriteStatusToCacheL(
       
  1261         *withoutPrefix, 
       
  1262         MPresenceBuddyInfo2::EUnknownAvailability,
       
  1263         buf,
       
  1264         KNullDesC() );
       
  1265     CleanupStack::PopAndDestroy( withoutPrefix );
       
  1266     iDataHost->HandlePresenceBlockedL( bInfo );
       
  1267     CleanupStack::Pop();// >> identity
       
  1268     CleanupStack::Pop();// >> bInfo
       
  1269     
       
  1270     DP_SDA( "CPresencePluginAuthorization::SetPresentityBlockedToXIMPL -Exit" );
       
  1271     }
       
  1272 
       
  1273 // ---------------------------------------------------------------------------
       
  1274 // CPresencePluginAuthorization::UnblockPresentityL()
       
  1275 // ---------------------------------------------------------------------------
       
  1276 //
       
  1277 void CPresencePluginAuthorization::UnblockPresentityL()
       
  1278     {
       
  1279     DP_SDA( "CPresencePluginAuthorization::UnblockPresentityL" );
       
  1280      
       
  1281     //remove entity from blocked list 
       
  1282     iXdmUtils->RemoveEntityFromBlockedL( 
       
  1283         iPresIdentity->Des(), iStatus );
       
  1284     //remove enity from ximp blocked too
       
  1285     MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
       
  1286     HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
  1287     identity->SetIdentityL( *withoutPrefix );
       
  1288     CleanupStack::PopAndDestroy( withoutPrefix );
       
  1289     iDataHost->HandlePresenceBlockCanceledL( identity );
       
  1290     CleanupStack::Pop();// >> identity
       
  1291     iAuthState = EStateIsContactBlockedBuddyRequest;
       
  1292     SetActive();
       
  1293     
       
  1294     DP_SDA( "CPresencePluginAuthorization::UnblockPresentityL -Exit" );
       
  1295     }
       
  1296 
       
  1297 
       
  1298 // ---------------------------------------------------------------------------
       
  1299 // CPresencePluginAuthorization::IsBlockedContactFriendRequest()
       
  1300 // ---------------------------------------------------------------------------
       
  1301 //
       
  1302 void CPresencePluginAuthorization::IsBlockedContactFriendRequestL(
       
  1303     const TDesC& aPresenceId,
       
  1304     MPresencePluginContactsObs& aObserver,
       
  1305     TRequestStatus& aStatus )
       
  1306     {
       
  1307     DP_SDA( "CPresencePluginAuthorization::IsBlockedContactFriendRequest" );
       
  1308 
       
  1309     delete iContacts;
       
  1310     iContacts = NULL;
       
  1311 
       
  1312     HBufC* serviceName =
       
  1313         iPresenceData->ServiceNameLC( iPresenceData->ServiceId() );
       
  1314 
       
  1315     iContacts = CPresencePluginContacts::NewL(
       
  1316         iPresenceData->ServiceId(), *serviceName, aObserver );
       
  1317 
       
  1318     CleanupStack::PopAndDestroy( serviceName );
       
  1319 
       
  1320     iContacts->IsPresenceIdStoredL( aPresenceId, aStatus );
       
  1321 
       
  1322     DP_SDA( "CPresencePluginAuthorization::IsBlockedContactFriendRequest -exit" );
       
  1323     }
       
  1324 
       
  1325 
       
  1326 // ---------------------------------------------------------------------------
       
  1327 // From base class MPresencePluginContactsObs
       
  1328 // CPresencePluginAuthorization::RequestComplete()
       
  1329 // ---------------------------------------------------------------------------
       
  1330 //
       
  1331 void CPresencePluginAuthorization::RequestComplete( TAny* aResult,
       
  1332     TPresenceContactsOperation aOperation, TInt aError )
       
  1333     {
       
  1334     DP_SDA( "CPresencePluginAuthorization::RequestComplete" );
       
  1335     
       
  1336     switch( aOperation )
       
  1337         {
       
  1338         case EOperationIsPresenceStoredToContacts:
       
  1339             if ( aResult != NULL && KErrNone == aError  )
       
  1340                 {
       
  1341                 iContactIsStored = *static_cast<TBool*>( aResult );
       
  1342                 }
       
  1343             break;
       
  1344         default:
       
  1345             break;
       
  1346         }
       
  1347     DP_SDA2( "CPresencePluginAuthorization::RequestComplete - iContactIsStored = %d", iContactIsStored );
       
  1348     }
       
  1349 
       
  1350 // End of file