javamanager/javacaptain/extensionplugins/javacertstore/src.s60/smartcardcertextrasreader.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "smartcardcertextrasreader.h"
       
    20 
       
    21 using namespace std;
       
    22 
       
    23 namespace java
       
    24 {
       
    25 namespace security
       
    26 {
       
    27 
       
    28 SmartCardCertExtrasReader* SmartCardCertExtrasReader::NewL()
       
    29 {
       
    30     SmartCardCertExtrasReader* self = new(ELeave) SmartCardCertExtrasReader();
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35 }
       
    36 
       
    37 void SmartCardCertExtrasReader::GetCertTrustedUsages(TDesC8& aSmartCardCertId, RCPointerArray<HBufC>& aSmartCardCertTrustedUsages)
       
    38 {
       
    39     // make a copy of the cert id
       
    40     if (iSmartCardCertId)
       
    41     {
       
    42         delete iSmartCardCertId;
       
    43         iSmartCardCertId = NULL;
       
    44     }
       
    45     iSmartCardCertId = aSmartCardCertId.Alloc();
       
    46 
       
    47     // keep a pointer to the provided array (this will be
       
    48     // filled with the smart card cert's trusted usages)
       
    49     iSmartCardCertTrustedUsages = &aSmartCardCertTrustedUsages;
       
    50 
       
    51     // issue& complete the first request, so that we enter the state machine
       
    52     //(implemented inside RunL method)
       
    53     SetActive();
       
    54     CompleteRequest(KErrNone);
       
    55 
       
    56     // start the active scheduler
       
    57     CActiveScheduler::Start();
       
    58 }
       
    59 
       
    60 void SmartCardCertExtrasReader::RunL()
       
    61 {
       
    62     if (iStatus.Int() != KErrNone)
       
    63     {
       
    64         iState = EFinish;
       
    65     }
       
    66     switch (iState)
       
    67     {
       
    68     case EStart:
       
    69         NextState(Initialize());
       
    70         break;
       
    71     case EGetExtras:
       
    72         NextState(GetExtras());
       
    73         break;
       
    74     case EFinish:
       
    75         NextState(Finish());
       
    76         return;
       
    77     }
       
    78     // re-issue a new request
       
    79     SetActive();
       
    80 }
       
    81 
       
    82 void SmartCardCertExtrasReader::DoCancel()
       
    83 {
       
    84     switch (iState)
       
    85     {
       
    86     case EStart:
       
    87         CancelInitialize();
       
    88         break;
       
    89     case EGetExtras:
       
    90         CancelGetExtras();
       
    91         break;
       
    92     }
       
    93 }
       
    94 
       
    95 TInt SmartCardCertExtrasReader::RunError(TInt /*aError*/)
       
    96 {
       
    97     CActiveScheduler::Stop();
       
    98     return KErrNone;
       
    99 }
       
   100 
       
   101 
       
   102 bool SmartCardCertExtrasReader::Initialize()
       
   103 {
       
   104     // do the initialization
       
   105     iSmartCardCertExtras->Initialize(iStatus);
       
   106     // the operation did succeed
       
   107     return true;
       
   108 }
       
   109 
       
   110 bool SmartCardCertExtrasReader::GetExtras()
       
   111 {
       
   112     // retrieve the certificate's extra info
       
   113     iSmartCardCertExtras->GetExtras(iSmartCardCertId->Des(), *iSmartCardCertTrustedUsages, iSmartCardCertLocation, iStatus);
       
   114     // the operation did succeed
       
   115     return true;
       
   116 }
       
   117 
       
   118 bool SmartCardCertExtrasReader::Finish()
       
   119 {
       
   120     // this is the final state
       
   121     CActiveScheduler::Stop();
       
   122     // the operation did succeed
       
   123     return true;
       
   124 }
       
   125 
       
   126 
       
   127 
       
   128 void SmartCardCertExtrasReader::CancelInitialize()
       
   129 {
       
   130     iSmartCardCertExtras->CancelInitialize();
       
   131 }
       
   132 
       
   133 void SmartCardCertExtrasReader::CancelGetExtras()
       
   134 {
       
   135     iSmartCardCertExtras->CancelGetExtras();
       
   136 }
       
   137 
       
   138 void SmartCardCertExtrasReader::ConstructL()
       
   139 {
       
   140     CActiveScheduler* CurrentActiveScheduler = CActiveScheduler::Current();
       
   141     if (CurrentActiveScheduler == NULL)
       
   142     {
       
   143         iActiveScheduler = new(ELeave) CActiveScheduler;
       
   144         CActiveScheduler::Install(iActiveScheduler);
       
   145     }
       
   146     CActiveScheduler::Add(this);
       
   147     iSmartCardCertExtras = CWimCert::NewL();
       
   148 }
       
   149 
       
   150 SmartCardCertExtrasReader::SmartCardCertExtrasReader()
       
   151         : CActive(EPriorityNormal), iState(EStart), iSmartCardCertTrustedUsages(NULL), iSmartCardCertExtras(NULL), iSmartCardCertId(NULL), iActiveScheduler(NULL)
       
   152 {
       
   153 }
       
   154 
       
   155 SmartCardCertExtrasReader::~SmartCardCertExtrasReader()
       
   156 {
       
   157     if (iSmartCardCertExtras)
       
   158     {
       
   159         delete iSmartCardCertExtras;
       
   160         iSmartCardCertExtras = NULL;
       
   161     }
       
   162     if (iSmartCardCertId)
       
   163     {
       
   164         delete iSmartCardCertId;
       
   165         iSmartCardCertId = NULL;
       
   166     }
       
   167     if (iActiveScheduler)
       
   168     {
       
   169         delete iActiveScheduler;
       
   170         iActiveScheduler = NULL;
       
   171     }
       
   172 }
       
   173 
       
   174 void SmartCardCertExtrasReader::CompleteRequest(TInt aCompletionCode)
       
   175 {
       
   176     TRequestStatus* status = &iStatus;
       
   177     User::RequestComplete(status,aCompletionCode);
       
   178 }
       
   179 
       
   180 void SmartCardCertExtrasReader::NextState(bool aCurrentOperationSucceeded)
       
   181 {
       
   182     if (!aCurrentOperationSucceeded)
       
   183     {
       
   184         // cancel the outstanding request
       
   185         CompleteRequest(KErrCancel);
       
   186         // move on to the last state
       
   187         iState = EFinish;
       
   188         return;
       
   189     }
       
   190     switch (iState)
       
   191     {
       
   192     case EStart:
       
   193         iState = EGetExtras;
       
   194         break;
       
   195     case EGetExtras:
       
   196         iState = EFinish;
       
   197         break;
       
   198     case EFinish:
       
   199         // reset the state to getextras
       
   200         // (not to EStart, since we are already initialized)
       
   201         iState = EGetExtras;
       
   202         break;
       
   203     }
       
   204 }
       
   205 
       
   206 } //end namespace security
       
   207 } //end namespace java