pkiutilities/securitydialognotifiersrv/src/securitydialognotifiersession.cpp
branchRCL_3
changeset 21 09b1ac925e3f
equal deleted inserted replaced
20:63339781d179 21:09b1ac925e3f
       
     1 /*
       
     2 * Copyright (c) 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:  Security dialog notifier server session
       
    15 *
       
    16 */
       
    17 
       
    18 #include "securitydialognotifiersession.h"  // CSecurityDialogNotifierSession
       
    19 #include "securitydialognotifierserver.h"   // CSecurityDialogNotifierServer
       
    20 #include "securitydialognotifierservername.h" // KSecurityDialogsCancelOperation
       
    21 #include "securitydialogoperserverauthfail.h" // CServerAuthFailOperation
       
    22 #include "securitydialogstrace.h"           // TRACE macro
       
    23 #include <secdlgimpldefs.h>                 // TSecurityDialogOperation
       
    24 
       
    25 const TInt KInputParam = 0;
       
    26 const TInt KOutputParam = 1;
       
    27 
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CSecurityDialogNotifierSession::NewL()
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CSecurityDialogNotifierSession* CSecurityDialogNotifierSession::NewL()
       
    36     {
       
    37     CSecurityDialogNotifierSession* self = new( ELeave ) CSecurityDialogNotifierSession;
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CSecurityDialogNotifierSession::~CSecurityDialogNotifierSession()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CSecurityDialogNotifierSession::~CSecurityDialogNotifierSession()
       
    49     {
       
    50     TRACE( "CSecurityDialogNotifierSession::~CSecurityDialogNotifierSession, begin" );
       
    51     Server().RemoveSession();
       
    52     delete iOperationHandler;
       
    53     iOperationHandler = NULL;
       
    54     delete iInputBuffer;
       
    55     iInputBuffer = NULL;
       
    56     TRACE( "CSecurityDialogNotifierSession::~CSecurityDialogNotifierSession, end" );
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CSecurityDialogNotifierSession::CreateL()
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CSecurityDialogNotifierSession::CreateL()
       
    64     {
       
    65     TRACE( "CSecurityDialogNotifierSession::~CSecurityDialogNotifierSession" );
       
    66     Server().AddSession();
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CSecurityDialogNotifierSession::ServiceL()
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CSecurityDialogNotifierSession::ServiceL( const RMessage2& aMessage )
       
    74     {
       
    75     TRACE( "CSecurityDialogNotifierSession::ServiceL, message 0x%08x", aMessage.Handle() );
       
    76     TRAPD( error, DispatchMessageL( aMessage ) );
       
    77     TRACE( "CSecurityDialogNotifierSession::ServiceL, dispatched, error %d", error );
       
    78     if( error && !aMessage.IsNull() )
       
    79         {
       
    80         TRACE( "CSecurityDialogNotifierSession::ServiceL, completing msg 0x%08x",
       
    81                 aMessage.Handle() );
       
    82         aMessage.Complete( error );
       
    83         }
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CSecurityDialogNotifierSession::OperationComplete()
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CSecurityDialogNotifierSession::OperationComplete()
       
    91     {
       
    92     TRACE( "CSecurityDialogNotifierSession::OperationComplete, begin" );
       
    93     delete iOperationHandler;
       
    94     iOperationHandler = NULL;
       
    95     TRACE( "CSecurityDialogNotifierSession::OperationComplete, end" );
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CSecurityDialogNotifierSession::CSecurityDialogNotifierSession()
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CSecurityDialogNotifierSession::CSecurityDialogNotifierSession()
       
   103     {
       
   104     TRACE( "CSecurityDialogNotifierSession::CSecurityDialogNotifierSession" );
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CSecurityDialogNotifierSession::ConstructL()
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CSecurityDialogNotifierSession::ConstructL()
       
   112     {
       
   113     TRACE( "CSecurityDialogNotifierSession::ConstructL" );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CSecurityDialogNotifierSession::Server()
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 CSecurityDialogNotifierServer& CSecurityDialogNotifierSession::Server()
       
   121     {
       
   122     return *static_cast< CSecurityDialogNotifierServer* >(
       
   123             const_cast< CServer2* >( CSession2::Server() ) );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CSecurityDialogNotifierSession::DispatchMessageL()
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CSecurityDialogNotifierSession::DispatchMessageL( const RMessage2& aMessage )
       
   131     {
       
   132     TRACE( "CSecurityDialogNotifierSession::DispatchMessageL, begin" );
       
   133     if( !IsOperationCancelled( aMessage ) )
       
   134         {
       
   135         TSecurityDialogOperation operation =
       
   136                 static_cast< TSecurityDialogOperation >( aMessage.Function() );
       
   137         TRACE( "CSecurityDialogNotifierSession::DispatchMessageL, operation=%d", operation );
       
   138         switch( operation )
       
   139             {
       
   140             case ESecureConnection:
       
   141             case ESignText:
       
   142             case EEnterPIN:
       
   143             case EEnablePIN:
       
   144             case EDisablePIN:
       
   145             case EChangePIN:
       
   146             case EUnblockPIN:
       
   147             case EPINBlocked:
       
   148             case ETotalBlocked:
       
   149             case EUnblockPINInClear:
       
   150                 User::Leave( KErrNotSupported );
       
   151                 break;
       
   152             case EServerAuthenticationFailure:
       
   153                 ServerAuthenticationFailureL( aMessage );
       
   154                 break;
       
   155             default:
       
   156                 User::Leave( KErrNotSupported );
       
   157                 break;
       
   158             }
       
   159         }
       
   160     TRACE( "CSecurityDialogNotifierSession::DispatchMessageL, end" );
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSecurityDialogNotifierSession::IsOperationCancelled()
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TBool CSecurityDialogNotifierSession::IsOperationCancelled( const RMessage2& aMessage )
       
   168     {
       
   169     TBool isCancelled = EFalse;
       
   170     if( aMessage.Function() == KSecurityDialogCancelOperation )
       
   171         {
       
   172         if( iOperationHandler )
       
   173             {
       
   174             TRACE( "CSecurityDialogNotifierSession::CheckIfOperationCancelledL, cancelling" );
       
   175             iOperationHandler->CancelOperation();
       
   176             }
       
   177         TRACE( "CSecurityDialogNotifierSession::CheckIfOperationCancelledL, completing msg 0x%08x",
       
   178                 aMessage.Handle() );
       
   179         aMessage.Complete( KErrNone );
       
   180         isCancelled = ETrue;
       
   181         }
       
   182     return isCancelled;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CSecurityDialogNotifierSession::ServerAuthenticationFailureL()
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CSecurityDialogNotifierSession::ServerAuthenticationFailureL( const RMessage2& aMessage )
       
   190     {
       
   191     TRACE( "CSecurityDialogNotifierSession::ServerAuthenticationFailureL, begin" );
       
   192     GetInputBufferL( aMessage );
       
   193 
       
   194     __ASSERT_DEBUG( iOperationHandler == NULL, User::Invariant() );
       
   195     iOperationHandler = CServerAuthFailOperation::NewL( *this, aMessage, KOutputParam );
       
   196     iOperationHandler->StartL( *iInputBuffer );
       
   197 
       
   198     TRACE( "CSecurityDialogNotifierSession::ServerAuthenticationFailureL, end" );
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CSecurityDialogNotifierSession::GetInputBufferL()
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CSecurityDialogNotifierSession::GetInputBufferL( const RMessage2& aMessage )
       
   206     {
       
   207     TInt inputLength = aMessage.GetDesLength( KInputParam );
       
   208     TRACE( "CSecurityDialogNotifierSession::GetInputBufferL, inputLength=%d", inputLength );
       
   209     __ASSERT_ALWAYS( inputLength > 0, User::Leave( KErrCorrupt ) );
       
   210     if( iInputBuffer )
       
   211         {
       
   212         delete iInputBuffer;
       
   213         iInputBuffer = NULL;
       
   214         }
       
   215     iInputBuffer = HBufC8::NewL( inputLength );
       
   216     TPtr8 inputBufferPtr( iInputBuffer->Des() );
       
   217     aMessage.ReadL( KInputParam, inputBufferPtr );
       
   218     TRACE( "CSecurityDialogNotifierSession::GetInputBufferL, read complete" );
       
   219     }
       
   220