pkiutilities/securitydialognotifier/src/securitydialogs.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:  CSecurityDialogs active object
       
    15 *
       
    16 */
       
    17 
       
    18 #include "securitydialogs.h"            // CSecurityDialogs
       
    19 #include "securitydialogstrace.h"       // TRACE macro
       
    20 
       
    21 
       
    22 // ======== MEMBER FUNCTIONS ========
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // CSecurityDialogs::NewL()
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CSecurityDialogs* CSecurityDialogs::NewL(  TBool& aIsDeleted )
       
    29     {
       
    30     return new( ELeave ) CSecurityDialogs( aIsDeleted );
       
    31     }
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CSecurityDialogs::~CSecurityDialogs()
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CSecurityDialogs::~CSecurityDialogs()
       
    38     {
       
    39     TRACE( "CSecurityDialogs::~CSecurityDialogs, begin" );
       
    40     Cancel();
       
    41     iServer.Close();
       
    42     delete iInputBuffer;
       
    43     iInputBuffer = NULL;
       
    44     delete iOutputBuffer;
       
    45     iOutputBuffer = NULL;
       
    46     iIsDeleted = ETrue;
       
    47     TRACE( "CSecurityDialogs::~CSecurityDialogs, end" );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CSecurityDialogs::StartLD()
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CSecurityDialogs::StartLD( const TDesC8& aBuffer, TInt aReplySlot,
       
    55         const RMessagePtr2& aMessage )
       
    56     {
       
    57     TRACE( "CSecurityDialogs::StartLD, begin" );
       
    58     User::LeaveIfError( iServer.Connect() );
       
    59 
       
    60     const TInt* ptr = reinterpret_cast< const TInt* >( aBuffer.Ptr() );
       
    61     iOperation = static_cast< TSecurityDialogOperation >( *ptr & KSecurityDialogOperationMask );
       
    62     iReplySlot = aReplySlot;
       
    63 
       
    64     TRACE( "CSecurityDialogs::StartLD, message 0x%08x", iMessagePtr.Handle() );
       
    65     iMessagePtr = aMessage;
       
    66 
       
    67     TRACE( "CSecurityDialogs::StartLD, iOperation=%d", iOperation );
       
    68     __ASSERT_DEBUG( iOutputBuffer == NULL, User::Invariant() );
       
    69     TInt outputBufLen = 0;
       
    70     switch( iOperation )
       
    71         {
       
    72         case ESecureConnection:
       
    73         case ESignText:
       
    74             iOutputBuffer = new( ELeave ) TCTTokenObjectHandleBuf;
       
    75             outputBufLen = sizeof( TCTTokenObjectHandleBuf );
       
    76             break;
       
    77         case EEnterPIN:
       
    78         case EEnablePIN:
       
    79         case EDisablePIN:
       
    80             iOutputBuffer = new( ELeave ) TPINValueBuf;
       
    81             outputBufLen = sizeof( TPINValueBuf );
       
    82             break;
       
    83         case EChangePIN:
       
    84         case EUnblockPIN:
       
    85             iOutputBuffer = new( ELeave ) TTwoPINOutputBuf;
       
    86             outputBufLen = sizeof( TTwoPINOutputBuf );
       
    87             break;
       
    88         case EPINBlocked:
       
    89         case ETotalBlocked:
       
    90             break;
       
    91         case EUnblockPINInClear:
       
    92             iOutputBuffer = new( ELeave ) TUnblockPINInClearOutputBuf;
       
    93             outputBufLen = sizeof( TUnblockPINInClearOutputBuf );
       
    94             break;
       
    95         case EServerAuthenticationFailure:
       
    96             iOutputBuffer = new( ELeave ) TServerAuthenticationFailureOutputBuf;
       
    97             outputBufLen = sizeof( TServerAuthenticationFailureOutputBuf );
       
    98             break;
       
    99         default:
       
   100             User::Leave( KErrNotSupported );
       
   101             break;
       
   102         }
       
   103 
       
   104     __ASSERT_DEBUG( iInputBuffer == NULL, User::Invariant() );
       
   105     iInputBuffer = aBuffer.AllocL();
       
   106 
       
   107     if( iOutputBuffer )
       
   108         {
       
   109         iOutputPtr.Set( static_cast< TUint8* >( iOutputBuffer ), outputBufLen, outputBufLen );
       
   110         iServer.SecurityDialogOperation( iOperation, *iInputBuffer, iOutputPtr, iStatus );
       
   111         }
       
   112     else
       
   113         {
       
   114         User::Leave( KErrNotSupported );
       
   115         }
       
   116     SetActive();
       
   117     TRACE( "CSecurityDialogs::StartLD, end" );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CSecurityDialogs::RunL()
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CSecurityDialogs::RunL()
       
   125     {
       
   126     TRACE( "CSecurityDialogs::RunL, iStatus.Int()=%d", iStatus.Int() );
       
   127     TInt error = iStatus.Int();
       
   128     User::LeaveIfError( error );
       
   129     __ASSERT_DEBUG( iOutputPtr.Ptr(), User::Invariant() );
       
   130     iMessagePtr.WriteL( iReplySlot, iOutputPtr );
       
   131 
       
   132     TRACE( "CSecurityDialogs::RunL, completing message 0x%08x", iMessagePtr.Handle() );
       
   133     iMessagePtr.Complete( error );
       
   134 
       
   135     TRACE( "CSecurityDialogs::RunL, deleting this" );
       
   136     delete this;
       
   137     TRACE( "CSecurityDialogs::RunL, end" );
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CSecurityDialogs::DoCancel()
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CSecurityDialogs::DoCancel()
       
   145     {
       
   146     TRACE( "CSecurityDialogs::DoCancel, begin" );
       
   147     iServer.CancelOperation();
       
   148     if( !iMessagePtr.IsNull() )
       
   149         {
       
   150         TRACE( "CSecurityDialogs::DoCancel, completing message 0x%08x", iMessagePtr.Handle() );
       
   151         iMessagePtr.Complete( KErrCancel );
       
   152         }
       
   153     TRACE( "CSecurityDialogs::DoCancel(), end" );
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSecurityDialogs::RunError()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 TInt CSecurityDialogs::RunError( TInt aError )
       
   161     {
       
   162     TRACE( "CSecurityDialogs::RunError, aError=%d", aError );
       
   163     if( !iMessagePtr.IsNull() )
       
   164         {
       
   165         TRACE( "CSecurityDialogs::RunError, completing message 0x%08x", iMessagePtr.Handle() );
       
   166         iMessagePtr.Complete( aError );
       
   167         }
       
   168 
       
   169     TRACE( "CSecurityDialogs::RunError, deleting this" );
       
   170     delete this;
       
   171 
       
   172     TRACE( "CSecurityDialogs::RunError, end" );
       
   173     return KErrNone;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CSecurityDialogs::CSecurityDialogs()
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 CSecurityDialogs::CSecurityDialogs( TBool& aIsDeleted ) : CActive( CActive::EPriorityLow ),
       
   181         iIsDeleted( aIsDeleted ), iOutputPtr( NULL, 0, 0 )
       
   182     {
       
   183     TRACE( "CSecurityDialogs::CSecurityDialogs" );
       
   184     CActiveScheduler::Add( this );
       
   185     iIsDeleted = EFalse;
       
   186     }
       
   187