installationservices/swi/test/tsisfile/tsisocspserver.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 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 the License "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 "tocspserver.h"
       
    20 #include "tocspclientserver.h"
       
    21 
       
    22 using Swi::Test::COcspServer;
       
    23 using Swi::Test::COcspStateMachine;
       
    24 using Swi::Test::COcspSession;
       
    25 using Swi::Test::COcspServerShutdown;
       
    26 
       
    27 static void PanicClient(const RMessagePtr2& aMessage, 
       
    28 						Swi::Test::TOcspServerPanic aPanic)
       
    29 	{
       
    30 	aMessage.Panic(Swi::Test::KOcspServerName, aPanic);
       
    31 	}
       
    32 
       
    33 /////
       
    34 ///// TOCSP Server
       
    35 /////
       
    36 
       
    37 /*static*/ COcspServer* COcspServer::NewLC()
       
    38 	{
       
    39 	COcspServer* self = new(ELeave) COcspServer();
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	return self;
       
    43 	}
       
    44 	
       
    45 void COcspServer::AddSession()
       
    46 	{
       
    47 	++iSessionCount;
       
    48 	iShutdown->Cancel();
       
    49 	}
       
    50 	
       
    51 void COcspServer::DropSession()
       
    52 	{
       
    53 	if (--iSessionCount==0)
       
    54 		{
       
    55 		iShutdown->Start();
       
    56 		}
       
    57 	}
       
    58 
       
    59 COcspServer::~COcspServer()
       
    60 	{
       
    61 	delete iShutdown;
       
    62 	}
       
    63 
       
    64 COcspServer::COcspServer() : CServer2(EPriorityNormal, ESharableSessions)
       
    65 	{
       
    66 	}
       
    67 
       
    68 void COcspServer::ConstructL()
       
    69 	{
       
    70 	StartL(Swi::Test::KOcspServerName);
       
    71 //	iConsole = Console::NewL(_L("SWI Console Server Test"), TSize(KDefaultConsWidth, KDefaultConsHeight));
       
    72 	iShutdown = COcspServerShutdown::NewL();
       
    73 	// Ensure that the server still exits even if the 1st client fails to
       
    74 	// connect
       
    75 	iShutdown->Start();
       
    76 	}
       
    77 
       
    78 CSession2* COcspServer::NewSessionL(const TVersion& /*aVersion*/, 
       
    79 									   const RMessage2& /*aMessage*/) const
       
    80 	{
       
    81 	return new(ELeave) COcspSession();
       
    82 	}
       
    83 
       
    84 void COcspSession::CreateL()
       
    85 	{
       
    86 	Server().AddSession();
       
    87 	}
       
    88 
       
    89 COcspSession::COcspSession(/*CConsoleBase& aConsole*/) : CSession2() //, iConsole(aConsole)
       
    90 	{
       
    91 	}
       
    92 
       
    93 COcspSession::~COcspSession()
       
    94 	{
       
    95 	Server().DropSession();
       
    96 	}
       
    97 
       
    98 COcspServer& COcspSession::Server()
       
    99 	{
       
   100 	return *static_cast<COcspServer*>(
       
   101 		const_cast<CServer2*>(CSession2::Server()));
       
   102 	}
       
   103 
       
   104 /////
       
   105 ///// COcspSession		
       
   106 /////
       
   107 	
       
   108 void COcspSession::ServiceL(const RMessage2& aMessage)
       
   109 	{
       
   110 	switch (aMessage.Function())
       
   111 		{
       
   112 		case ECheck:
       
   113 			{
       
   114 			if (iStateMachine)
       
   115 				{
       
   116 				delete iStateMachine;
       
   117 				}
       
   118 			iStateMachine = COcspStateMachine::NewL(aMessage);
       
   119 			iStateMachine->DoCheck();
       
   120 			}
       
   121 			break;
       
   122 			
       
   123 		default:
       
   124 			{
       
   125 			PanicClient(aMessage, Swi::Test::EPanicOcspServerIllegalFunction);
       
   126 			break;
       
   127 			}
       
   128 		}
       
   129 	}
       
   130 
       
   131 void COcspSession::ServiceError(const RMessage2& aMessage, TInt aError)
       
   132 	{
       
   133 	if (aError==KErrBadDescriptor)
       
   134 		{
       
   135 		PanicClient(aMessage, Swi::Test::EPanicOcspServerBadDescriptor);
       
   136 		}
       
   137 	CSession2::ServiceError(aMessage, aError);
       
   138 	}
       
   139 
       
   140 /////
       
   141 ///// CInstallServerShutdown
       
   142 /////
       
   143 		
       
   144 inline COcspServerShutdown::COcspServerShutdown() : CTimer(-1)
       
   145 	{
       
   146 	CActiveScheduler::Add(this);
       
   147 	}
       
   148 
       
   149 inline void COcspServerShutdown::ConstructL()
       
   150 	{
       
   151 	CTimer::ConstructL();
       
   152 	}
       
   153 
       
   154 inline void COcspServerShutdown::Start()
       
   155 	{
       
   156 	After(KShutdownDelay);
       
   157 	}
       
   158 
       
   159 /*static*/ COcspServerShutdown* COcspServerShutdown::NewL()
       
   160 	{
       
   161 	COcspServerShutdown* self = new(ELeave) COcspServerShutdown();
       
   162 	CleanupStack::PushL(self);
       
   163 	self->ConstructL();
       
   164 	CleanupStack::Pop(self);
       
   165 	return self;
       
   166 	}
       
   167 
       
   168 // Initiate server exit when the timer expires
       
   169 void COcspServerShutdown::RunL()
       
   170 	{
       
   171 	CActiveScheduler::Stop();
       
   172 	}
       
   173 
       
   174 
       
   175 
       
   176 ////
       
   177 //// State Machine
       
   178 ////
       
   179 
       
   180 /*static*/ COcspStateMachine* COcspStateMachine::NewL(const RMessage2& aMessage)
       
   181 	{
       
   182 	COcspStateMachine* self = new (ELeave) COcspStateMachine(aMessage);
       
   183 	CleanupStack::PushL(self);
       
   184 	self->ConstructL();
       
   185 	CleanupStack::Pop(self);
       
   186 	return self;
       
   187 	}
       
   188 
       
   189 COcspStateMachine::COcspStateMachine(const RMessage2& aMessage) : CActive(EPriorityNormal), iClientMessage(aMessage)
       
   190 	{
       
   191 	CActiveScheduler::Add(this);
       
   192 	}
       
   193 
       
   194 COcspStateMachine::~COcspStateMachine()
       
   195 	{
       
   196 	if (iSecurityManager)
       
   197 		{
       
   198 		delete iSecurityManager;
       
   199 		}
       
   200 
       
   201 	iOcspOutcomes.ResetAndDestroy();
       
   202 	iCerts.ResetAndDestroy();
       
   203 
       
   204 	if (iOcspUri) 
       
   205 		{
       
   206 		delete iOcspUri;
       
   207 		}
       
   208 	}
       
   209 	
       
   210 void COcspStateMachine::ConstructL()
       
   211 	{	
       
   212 	}
       
   213 
       
   214 void COcspStateMachine::DoCheck()
       
   215 	{
       
   216 	iSecurityManager = CSecurityManager::NewL();
       
   217 
       
   218 	iState = EDone;	
       
   219 	iIap = 0;
       
   220 	iSecurityManager->PerformOcspL(*iOcspUri, 
       
   221 								   iIap,
       
   222 							   	   iRevocationMessage, 
       
   223 							   	   iOcspOutcomes, 
       
   224 							   	   iCerts,
       
   225 							   	   iStatus);
       
   226 	SetActive();
       
   227 	}
       
   228 
       
   229 	
       
   230 void COcspStateMachine::RunL()
       
   231 	{
       
   232 	if (iStatus.Int() != KErrNone)
       
   233 		{
       
   234 		User::Leave(iStatus.Int()); // Hop into RunError()
       
   235 		}
       
   236 
       
   237 	switch (iState)
       
   238 		{
       
   239 		case EDone:
       
   240 			{
       
   241 			iClientMessage.Complete(static_cast<TInt>(*iRevocationMessage));
       
   242 			}
       
   243 			break;
       
   244 			
       
   245 		default:
       
   246 			{
       
   247 			User::Panic(_L("Test OCSP Server"), 1);
       
   248 			}
       
   249 		}
       
   250 	}
       
   251 	
       
   252 void COcspStateMachine::DoCancel()
       
   253 	{
       
   254 	
       
   255 	}
       
   256 	
       
   257 TInt COcspStateMachine::RunError(TInt aError)
       
   258 	{
       
   259 	iClientMessage.Complete(aError);
       
   260 	
       
   261 	return KErrNone;
       
   262 	}
       
   263