presadap12/impsplugin/src/presenceauthorization/cblockpresenceforpresentityrequest.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  Create Presentity Group Request to the Network Server.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnectionhost.h>
       
    20 #include "CBlockPresenceForPresentityRequest.h"
       
    21 #include "impsconnectionmanagercontrolif.h"
       
    22 #include "impsdebugprint.h"
       
    23 #include "CImpsPluginAccessHandler.h"
       
    24 #include "CImpsPluginPureDataHandler.h"
       
    25 
       
    26 #include <protocolpresenceauthorizationdatahost.h>
       
    27 
       
    28 #include "CPEngXMLParser.h"
       
    29 #include "MPEngXMLParser.h"
       
    30 #include "CPEngXmlSerializer.h"
       
    31 #include "MPEngXmlSerializer.h"
       
    32 #include "CImpsPluginConnectionManager.h"
       
    33 #include "PEngXMLTags.h"
       
    34 #include "impsplugintags.h"
       
    35 
       
    36 #include <ximpobjectfactory.h>
       
    37 #include <protocolpresencedatahost.h>
       
    38 #include <presenceobjectfactory.h>
       
    39 #include <ximpobjectcollection.h>
       
    40 #include <protocolpresentitygroupsdatahost.h>
       
    41 #include <presentitygroupinfo.h>
       
    42 #include <presentitygroupmemberinfo.h>
       
    43 #include <ximpidentity.h>
       
    44 #include <presenceblockinfo.h>
       
    45 #include <ximpdatasubscriptionstate.h>
       
    46 #include "PImpsAdapXMLTools.h"
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CBlockPresenceForPresentityRequest::CBlockPresenceForPresentityRequest
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CBlockPresenceForPresentityRequest::CBlockPresenceForPresentityRequest(
       
    56     MImpsPrtPluginConnectionManager& aConnMan,
       
    57     TXIMPRequestId aRequestId ) :
       
    58         CActive( EPriorityNormal ),
       
    59         iRequestId( aRequestId ),
       
    60         iConnMan( aConnMan )
       
    61     {
       
    62     IMPS_DP( D_IMPS_LIT( "::CBlockPresenceForPresentityRequest Start" ) );
       
    63     CActiveScheduler::Add( this );
       
    64     IMPS_DP( D_IMPS_LIT( "::CBlockPresenceForPresentityRequest End" ) );
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CBlockPresenceForPresentityRequest::ConstructL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CBlockPresenceForPresentityRequest::ConstructL()
       
    73     {
       
    74     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::ConstructL Start-End" ) );
       
    75 
       
    76     iParser = CreateXMLParserL();
       
    77     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::ConstructL End" ) );
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CBlockPresenceForPresentityRequest::NewL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CBlockPresenceForPresentityRequest* CBlockPresenceForPresentityRequest::NewL(
       
    86     MImpsPrtPluginConnectionManager& aConnMan,
       
    87     TXIMPRequestId aRequestId )
       
    88     {
       
    89     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::NewL Start" ) );
       
    90 
       
    91     CBlockPresenceForPresentityRequest* self = new( ELeave )
       
    92     CBlockPresenceForPresentityRequest( aConnMan, aRequestId );
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95     CleanupStack::Pop( self );
       
    96 
       
    97     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::NewL End" ) );
       
    98     return self;
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CBlockPresenceForPresentityRequest::NewLC
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CBlockPresenceForPresentityRequest* CBlockPresenceForPresentityRequest::NewLC(
       
   107     MImpsPrtPluginConnectionManager& aConnMan,
       
   108     TXIMPRequestId aRequestId )
       
   109     {
       
   110     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::NewLC Start" ) );
       
   111 
       
   112     CBlockPresenceForPresentityRequest* self =
       
   113         CBlockPresenceForPresentityRequest::NewL( aConnMan, aRequestId );
       
   114     CleanupStack::PushL( self );
       
   115 
       
   116     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::NewLC End" ) );
       
   117     return self;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CBlockPresenceForPresentityRequest::~CBlockPresenceForPresentityRequest
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CBlockPresenceForPresentityRequest::~CBlockPresenceForPresentityRequest()
       
   125     {
       
   126     IMPS_DP( D_IMPS_LIT( "::~CBlockPresenceForPresentityRequest Start" ) );
       
   127     delete iResponse;
       
   128     CActive::Cancel();
       
   129     iConnMan.Remove( this );
       
   130     delete iParser;
       
   131     delete iGroupName;
       
   132     IMPS_DP( D_IMPS_LIT( "::~CBlockPresenceForPresentityRequest End" ) );
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CBlockPresenceForPresentityRequest::DoCancel()
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CBlockPresenceForPresentityRequest::DoCancel()
       
   141     {
       
   142     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::DoCancel Start" ) );
       
   143 
       
   144     iConnMan.DataHandler().CancelSending( iSendId );
       
   145 
       
   146     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::DoCancel End" ) );
       
   147     }
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CBlockPresenceForPresentityRequest::RunL()
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CBlockPresenceForPresentityRequest::RunL()
       
   155     {
       
   156     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::RunL Start" ) );
       
   157 
       
   158     User::LeaveIfError( iStatus.Int() );
       
   159 
       
   160     iResponse = iConnMan.DataHandler().ResponseL( iSendId );
       
   161 
       
   162     TPtrC8 resultBlock( NULL, 0 );
       
   163     TInt wvErrorCode = KErrNone;
       
   164 
       
   165     // Check if we got 200
       
   166     if ( iParser->DecodeL( *iResponse, KResultXMLTag, ETrue ) )
       
   167         {
       
   168         resultBlock.Set( iParser->ResultL() );
       
   169         if ( iParser->DecodeL( resultBlock, KCodeXMLTag, EFalse ) )
       
   170             {
       
   171             TPtrC8 cspStatusCodeBlock( iParser->ResultL() );
       
   172             TInt cspStatusInt;
       
   173             TLex8 lexer( cspStatusCodeBlock );
       
   174             lexer.SkipSpace();
       
   175             TInt lexErr = lexer.Val( cspStatusInt );
       
   176             if ( lexErr == KErrNone )
       
   177                 {
       
   178                 wvErrorCode = cspStatusInt;
       
   179                 }
       
   180             }
       
   181         }
       
   182 
       
   183     // prfw does not provide any interface for MPresenceBlockInfo
       
   184     // write this interface in prfw and then compile this code
       
   185 
       
   186     MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   187     MPresenceObjectFactory& prObjFact =
       
   188         iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory();
       
   189     MXIMPIdentity* blockIdentity  = prfwObjFact.NewIdentityLC();
       
   190     blockIdentity->SetIdentityL( *iGroupName );
       
   191 
       
   192     MPresenceBlockInfo* blockInfo  = prObjFact.NewPresenceBlockInfoLC();
       
   193     blockInfo->SetBlockedEntityIdL( blockIdentity );
       
   194 
       
   195     // issue the request to prfw
       
   196     iConnMan.HandleToHost().ProtocolPresenceDataHost().AuthorizationDataHost().HandlePresenceBlockedL( blockInfo );
       
   197     CleanupStack::Pop( 1 ); // blockIdentity
       
   198     CleanupStack::Pop( 1 ); // blockInfo
       
   199 
       
   200     MXIMPDataSubscriptionState* dataSubscriptionState = prfwObjFact.NewDataSubscriptionStateLC();
       
   201     dataSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable );
       
   202     dataSubscriptionState->SetSubscriptionStateL( MXIMPDataSubscriptionState::ESubscriptionActive );
       
   203 
       
   204     // change the state
       
   205     iConnMan.HandleToHost().ProtocolPresenceDataHost().AuthorizationDataHost().SetPresenceBlockDataSubscriptionStateL(
       
   206         dataSubscriptionState, NULL );
       
   207 
       
   208     CleanupStack::Pop( 1 ); // dataSubscriptionState
       
   209 
       
   210     // update datacache
       
   211     // completet the group content request
       
   212     IMPS_DP( D_IMPS_LIT( "BlockPresenceForPresentityL Return Code %d" ), wvErrorCode );
       
   213     if ( wvErrorCode == KWVRequestResponseResultCode )
       
   214         {
       
   215         wvErrorCode = KErrNone;
       
   216         }
       
   217     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode );
       
   218 
       
   219     delete this;
       
   220     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::RunL End" ) );
       
   221     }
       
   222 
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CBlockPresenceForPresentityRequest::RunError
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 TInt CBlockPresenceForPresentityRequest::RunError( TInt  aError )
       
   229     {
       
   230     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::RunError Start" ) );
       
   231 
       
   232     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   233 
       
   234     delete this;
       
   235     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::RunError End" ) );
       
   236     return KErrNone;
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CBlockPresenceForPresentityRequest::BlockPresenceForPresentityL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CBlockPresenceForPresentityRequest::BlockPresenceForPresentityL(
       
   244     const MXIMPIdentity& aPresentityId )
       
   245     {
       
   246     IMPS_DP( D_IMPS_LIT( "::BlockPresenceForPresentityL Start" ) );
       
   247 
       
   248     IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) );
       
   249 
       
   250     IMPS_DP( D_IMPS_LIT( "---------------------Data from framework to presadap1.2-----------" ) );
       
   251 
       
   252     IMPS_DP( D_IMPS_LIT( "CBlockPresenceForPresentityRequest::BlockPresenceForPresentityL:PresentityId:%S " ), &aPresentityId.Identity() );
       
   253 
       
   254     TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() );
       
   255     MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer );
       
   256 
       
   257     iGroupName = aPresentityId.Identity().AllocL();
       
   258 
       
   259 
       
   260     NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() );
       
   261 
       
   262     serializer->StartTagL( KCreateAttributeList );
       
   263 
       
   264     serializer->StartTagL( KPresenceSubList );
       
   265     serializer->AttributeL( KXmlXmlns, KPresenceSubListAttributesNS_CSP12 );
       
   266 
       
   267 
       
   268     serializer->EndTagL( KPresenceSubList );
       
   269 
       
   270     if ( KErrNone == iGroupName->Left( KPEngAttrWVIdPrefixLength ).CompareF( KPengWVIDPrefix ) )
       
   271         {
       
   272         serializer->StartTagL( KUserIDXMLTag
       
   273                              ).WvAddressL( aPresentityId.Identity()
       
   274                                          ).EndTagL( KUserIDXMLTag );
       
   275         }
       
   276     else
       
   277         {
       
   278         serializer->StartTagL( KUserIDXMLTag
       
   279                              ).NarrowTextL( KWVXMLTag
       
   280                                           ).WvAddressL( aPresentityId.Identity()
       
   281                                                       ).EndTagL( KUserIDXMLTag );
       
   282         }
       
   283 
       
   284     serializer->StartTagL( KDefaultList ).NarrowTextL( KXMLValueFalse ).EndTagL( KDefaultList );
       
   285     serializer->EndTagL( KCreateAttributeList );
       
   286 
       
   287     serializer->EndTagL( KTransactionContent );
       
   288 
       
   289     IMPS_DP( D_IMPS_LIT( "BlockPresenceForPresentityL" ) );
       
   290 
       
   291     CleanupStack::PopAndDestroy(); //serializer
       
   292 
       
   293     iSendId = iConnMan.DataHandler().SendDataL( iStatus );
       
   294 
       
   295     // signal the scheduler
       
   296     SetActive();
       
   297 
       
   298     IMPS_DP( D_IMPS_LIT( "::BlockPresenceForPresentityL End" ) );
       
   299     }
       
   300 
       
   301 // End of file