wim/WimPlugin/src/WimTokenType.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  This class is instantiated via ECom for a particular token type
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "WimTokenType.h"
       
    22 #include "WimToken.h"
       
    23 #include "WimImplementationUID.hrh"
       
    24 #include <ecom/implementationproxy.h>
       
    25 #include "WimTrace.h"
       
    26 //#include "WimDebug.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CWimTokenType::CWimTokenType()
       
    32 // Default constructor
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CWimTokenType::CWimTokenType()
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWimTokenType::ConstructL()
       
    41 // Second phase constructor
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CWimTokenType::ConstructL()
       
    45     {
       
    46     _WIMTRACE ( _L( "CWimTokenType::ConstructL()" ) );
       
    47     iWimSecModuleMgr = CWimSecModuleMgr::NewL(); 
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CWimTokenType::NewL()
       
    52 // Two-phased constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CWimTokenType* CWimTokenType::NewL() 
       
    56     {
       
    57     CWimTokenType* self = new( ELeave ) CWimTokenType();
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CWimTokenType::~CWimTokenType()
       
    66 // Destructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CWimTokenType::~CWimTokenType()
       
    70     {
       
    71     _WIMTRACE ( _L( "CWimTokenType::~CWimTokenType()" ) );
       
    72     delete iWimSecModuleMgr;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CWimTokenType::List()
       
    77 // List all the tokens of this type.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CWimTokenType::List( RCPointerArray<HBufC>& aTokens,  
       
    81                           TRequestStatus& aStatus )
       
    82     {
       
    83     _WIMTRACE ( _L( "CWimTokenType::List" ) );
       
    84     aStatus = KRequestPending;
       
    85     iWimSecModuleMgr->GetEntries( aTokens, aStatus );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CWimTokenType::CancelList()
       
    90 // Cancel a list operation.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CWimTokenType::CancelList()
       
    94     {
       
    95     _WIMTRACE ( _L( "CWimTokenType::CancelList" ) );
       
    96     iWimSecModuleMgr->CancelList();
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CTokenTypeImplementation::OpenToken() 
       
   101 // Opens new token, which name is specified in aTokenInfo
       
   102 // This is not true asynchronous function.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CWimTokenType::OpenToken( const TDesC& aTokenInfo, 
       
   106                                MCTToken*& aToken,
       
   107                                TRequestStatus& aStatus )
       
   108     { 
       
   109     _WIMTRACE ( _L( "CWimTokenType::OpenToken with name" ) );
       
   110     TInt err   = KErrNone;
       
   111     TInt i     = 0;
       
   112 
       
   113     aStatus    = KRequestPending;
       
   114 
       
   115     // Get the right Wim and pass it to CWimToken to be created.
       
   116     // Stack Wim count for efficiency reasons
       
   117     TInt count = iWimSecModuleMgr->WimCount(); 
       
   118     for ( i = 0; i < count && err == KErrNone; i++ ) 
       
   119         {
       
   120         HBufC* label = NULL;    // from heap
       
   121         // Get Wim label
       
   122         TRAP( err, label = iWimSecModuleMgr->WimLabelByIndexL( i ).AllocL() );
       
   123         if ( err == KErrNone ) 
       
   124             {
       
   125             // If labels match...
       
   126             if ( !aTokenInfo.Compare( label->Des() ) )
       
   127                 {
       
   128                 // Create token
       
   129                 TRAP( err, aToken = CWimToken::NewL( iWimSecModuleMgr->GetWimSecModuleByIndexL( i ), *this ) );
       
   130                 i = count + 1; // This completes for loop and separates
       
   131                                // from normal for loop end (i == count)
       
   132                 if ( err == KErrNone )
       
   133                     {
       
   134                     IncReferenceCount();
       
   135                     }
       
   136                 }
       
   137             }
       
   138         delete label;
       
   139         }
       
   140 
       
   141     if ( i == count && err == KErrNone ) // Not match found
       
   142         {
       
   143         err = KErrNotFound;
       
   144         }
       
   145 
       
   146     TRequestStatus* r = &aStatus;
       
   147     User::RequestComplete( r, err );
       
   148 
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CWimTokenType::OpenToken()
       
   153 // Open new token, The handle of the required token is used to get needed 
       
   154 // information. Before opening new token we need to compare token numbers.
       
   155 // This is not true asynchronous function.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CWimTokenType::OpenToken( TCTTokenHandle aHandle,
       
   159                                MCTToken*& aToken,
       
   160                                TRequestStatus& aStatus )
       
   161     {
       
   162     _WIMTRACE ( _L( "CWimTokenType::OpenToken with handle" ) );
       
   163     TInt err   = KErrNone;
       
   164     TInt i     = 0;
       
   165     TInt count = 0;
       
   166 
       
   167     aStatus = KRequestPending; 
       
   168 
       
   169     // Current tokentype and requested token's tokentype must be the same
       
   170     if ( Type() == aHandle.iTokenTypeUid )
       
   171         {
       
   172         // Count of security modules:
       
   173         count = iWimSecModuleMgr->WimCount();
       
   174         // For effectivity reasons, stack the given handle
       
   175         TInt mytokennumber = aHandle.iTokenId;      
       
   176         // Let's go through all Wims and try to match handles
       
   177         for ( i = 0; i < count && err == KErrNone; i++ )
       
   178             {
       
   179             // Stack Wim handle
       
   180             TInt histokennumber = 0;    
       
   181             TRAP( err, histokennumber = iWimSecModuleMgr->
       
   182                                         WimTokenNumberByIndexL( i ) );
       
   183             if ( err == KErrNone )
       
   184                 {
       
   185                 if ( mytokennumber == histokennumber )
       
   186                     {   
       
   187                     HBufC* label = NULL;// From heap
       
   188                     // Let's get Wim label and use another 
       
   189                     // API function to get token info
       
   190                     TRAP( err, label = iWimSecModuleMgr->
       
   191                                        WimLabelByIndexL( i ).AllocL() );
       
   192                     if ( err == KErrNone )
       
   193                         {
       
   194                         // The completion of the next statement is handled 
       
   195                         // in the associated function
       
   196                         OpenToken( label->Des(), aToken, aStatus );
       
   197                         delete label;
       
   198                         return; // Must quit here, RequestComplete is done
       
   199                         }
       
   200                     delete label;   // Here we go if error in last TRAP
       
   201                     i = count + 1;  // This completes for loop and
       
   202                                     // separates from normal for loop end
       
   203                     }
       
   204                 }
       
   205             } // for loop...
       
   206         } // if ( Type()...
       
   207 
       
   208     if ( i == count && err == KErrNone ) // No match found 
       
   209         {
       
   210         err = KErrNotFound;
       
   211         }
       
   212 
       
   213     TRequestStatus* r = &aStatus;
       
   214     User::RequestComplete( r, err );
       
   215 
       
   216     }
       
   217 // -----------------------------------------------------------------------------
       
   218 // CWimTokenType::CancelOpenToken()
       
   219 // Cancel an OpenToken operation.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CWimTokenType::CancelOpenToken()
       
   223     {
       
   224     _WIMTRACE ( _L( "CWimTokenType::CancelOpenToken" ) );
       
   225     // It's not really async, so you can't cancel.
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // TImplementationProxy ImplementationTable[] 
       
   230 // An array listing the NewL functions of all the plugins.
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 const TImplementationProxy ImplementationTable[] = 
       
   234     {
       
   235     {{WIM_IMPLEMENTATION_UID},     (TProxyNewLPtr) CWimTokenType::NewL} //CARD-WIM
       
   236     };
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // TImplementationProxy* ImplementationGroupProxy()
       
   240 // This function is needed by ECom and is the only one exported function
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C const TImplementationProxy* 
       
   244                 ImplementationGroupProxy( TInt& aTableCount )
       
   245     {
       
   246     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   247 
       
   248     return ImplementationTable;
       
   249     }
       
   250 
       
   251