vpnengine/pkiservice/src/pkiservice.cpp
changeset 0 33413c0669b9
child 1 c9c2ad51f972
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:   PKI server main module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "pkiservice.h"
       
    21 #include "pkisession.h"
       
    22 #include "PKIMapper.h"
       
    23 #include "pkiserviceclientservercommon.h"
       
    24 #include "certificaterequeststore.h"
       
    25 #include "keyoperationqueue.h"
       
    26 #include "log_r6.h"
       
    27 #include "pkiserviceassert.h"
       
    28 
       
    29 const TUint CPKIService::iRangeCount = 2;
       
    30 
       
    31 const TInt CPKIService::iRanges[iRangeCount] = 
       
    32     {
       
    33     PkiService::ELogon,
       
    34     PkiService::ESetInformational+1
       
    35     };
       
    36 
       
    37 const TUint8 CPKIService::iElementIndex[iRangeCount] = 
       
    38     {
       
    39     0,
       
    40     CPolicyServer::ENotSupported
       
    41     };
       
    42 
       
    43 const CPolicyServer::TPolicyElement CPKIService::iElements[] =
       
    44     {
       
    45 	{_INIT_SECURITY_POLICY_C1(ECapabilityNetworkControl), CPolicyServer::EFailClient},
       
    46     };
       
    47 
       
    48 const CPolicyServer::TPolicy CPKIService::iPolicy =
       
    49     {
       
    50     0, 						// All connect attempts are checked
       
    51     iRangeCount,            // Count of ranges
       
    52     iRanges,                // 0-25, 26...
       
    53     iElementIndex,          // Only range 0-25§ are checked
       
    54     iElements               // The list of policy elements
       
    55     };
       
    56     
       
    57 CPKIService::CPKIService(void):CPolicyServer(EPriorityStandard,iPolicy)
       
    58     {
       
    59     iSessionCount = 0;
       
    60     }
       
    61 
       
    62 
       
    63 CPKIService::~CPKIService(void)
       
    64     {    
       
    65     delete iKeyOperationQueue;
       
    66     delete iMapper;    
       
    67     delete iShutdown;
       
    68     delete iCertificateRequestStore;
       
    69     }
       
    70 
       
    71 
       
    72 CPKIService* CPKIService::NewL(void)
       
    73     {
       
    74     CPKIService* self = new (ELeave) CPKIService;
       
    75     CleanupStack::PushL(self);
       
    76     
       
    77     self->ConstructL();
       
    78     
       
    79     CleanupStack::Pop(self);
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 void CPKIService::ConstructL()
       
    85     {
       
    86     //Makes sure private path exists
       
    87     RFs fileServer;
       
    88     User::LeaveIfError(fileServer.Connect());
       
    89     CleanupClosePushL(fileServer);
       
    90     TInt err = fileServer.CreatePrivatePath(EDriveC);
       
    91     if (err != KErrNone &&
       
    92         err != KErrAlreadyExists)
       
    93         {
       
    94         User::Leave(err);
       
    95         }
       
    96     CleanupStack::PopAndDestroy(); //fileServer    
       
    97     
       
    98     iCertificateRequestStore = CCertificateRequestStore::NewL();    
       
    99     iShutdown = new (ELeave) CSuspendedShutdown();
       
   100     iShutdown->Construct();    
       
   101     
       
   102     iMapper = CPKIMapper::NewL();
       
   103     iKeyOperationQueue = CKeyOperationQueue::NewL(*iMapper);
       
   104     
       
   105         
       
   106     StartL(KPkiServerName);
       
   107     }
       
   108         
       
   109 
       
   110 CSession2* CPKIService::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const
       
   111     {
       
   112     iShutdown->Cancel();
       
   113     CSession2* session = CPKISession::NewL(*const_cast<CPKIService*>(this), *iMapper, *iKeyOperationQueue);        
       
   114     iSessionCount++;
       
   115     return session;
       
   116     }
       
   117 
       
   118 void CPKIService::SessionDeleted()
       
   119     {
       
   120     LOG_("-> CPKIService::SessionDeleted()");    
       
   121     iSessionCount--;
       
   122     
       
   123     LOG_1("iSessionCount (%d)", iSessionCount);    
       
   124     PKISERVICE_ASSERT(iSessionCount >= 0);
       
   125     
       
   126     
       
   127     if (iSessionCount == 0)
       
   128         {
       
   129         if (iStopImmediately)
       
   130             {
       
   131             CActiveScheduler::Stop();
       
   132             }
       
   133         else
       
   134             {
       
   135             iShutdown->ArmShutdown();
       
   136             }
       
   137         }
       
   138     LOG_("<- CPKIService::SessionDeleted()");    
       
   139     }
       
   140 
       
   141 CCertificateRequestStore& CPKIService::CertificateRequestStore()
       
   142     {
       
   143     return *iCertificateRequestStore;
       
   144     }
       
   145 
       
   146 
       
   147 const TInt KSuspendTime = 240000000;  // 240 sec
       
   148 //const TInt KSuspendTime = 5000000;  // 5 sec
       
   149 
       
   150 CSuspendedShutdown::CSuspendedShutdown() : CActive(EPriorityStandard)
       
   151 {
       
   152 }
       
   153 
       
   154 void CSuspendedShutdown::Construct()
       
   155 {
       
   156     iTimer.CreateLocal();
       
   157     CActiveScheduler::Add(this);
       
   158 }
       
   159 
       
   160 CSuspendedShutdown::~CSuspendedShutdown()
       
   161 {
       
   162     iTimer.Close();
       
   163 }
       
   164 
       
   165 void CSuspendedShutdown::ArmShutdown()
       
   166 {
       
   167     iTimer.After(iStatus, KSuspendTime);
       
   168     SetActive();
       
   169 }
       
   170 
       
   171 void CSuspendedShutdown::DoCancel()
       
   172 {
       
   173     iTimer.Cancel();
       
   174 }
       
   175 
       
   176 void CSuspendedShutdown::RunL()
       
   177 {
       
   178     CActiveScheduler::Stop();
       
   179 }