authenticationservices/authenticationserver/source/server/authserversession.cpp
changeset 19 ece3df019add
equal deleted inserted replaced
17:cd501b96611d 19:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2005-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 * authserverserversession.cpp
       
    16 * CAuthserverSession class implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file 
       
    23 */
       
    24 
       
    25 #include "authserver_impl.h"
       
    26 #include "log.h"
       
    27 
       
    28 using namespace AuthServer;
       
    29 
       
    30 void CAuthServerSession::PanicClient(const RMessagePtr2& aMessage,
       
    31 									 TAuthServerPanic aPanic)
       
    32 	{
       
    33 	aMessage.Panic(KAuthServerShortName, aPanic);
       
    34 	}
       
    35 
       
    36 //
       
    37 // 2nd phase construct for sessions - called by the CServer framework
       
    38 //
       
    39 void CAuthServerSession::CreateL()
       
    40 	{
       
    41 	iAuthServer =
       
    42 	  static_cast<CAuthServer*>(const_cast<CServer2*>(CSession2::Server()));
       
    43 	}
       
    44 CAuthServerSession* CAuthServerSession::NewL(CAuthServer &aServer)
       
    45 /**
       
    46 	Factory function allocates new instance of CAuthServerSession.
       
    47 
       
    48 	@return					New, initialized instance of CAuthServerSession
       
    49 							which is owned by the caller.
       
    50  */
       
    51 	{
       
    52 	CAuthServerSession* self = new(ELeave) CAuthServerSession(aServer);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL();			// CScsSession implementation
       
    55 	CleanupStack::Pop(self);
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 CAuthServerSession::CAuthServerSession(CAuthServer &aServer)
       
    60 /**
       
    61 	This private constructor prevents direct instantiation.
       
    62  */
       
    63  :	CScsSession(aServer)
       
    64 	{
       
    65 	// empty.
       
    66 	}
       
    67 
       
    68 
       
    69 CAuthServerSession::~CAuthServerSession()
       
    70 	{
       
    71 	}
       
    72 
       
    73 //
       
    74 // Handle a client request.
       
    75 // Leaving is handled by CAuthServer::ServiceError() which reports
       
    76 // the error code to the client
       
    77 //
       
    78 TBool CAuthServerSession::DoServiceL(TInt aFunction, const RMessage2& aMessage)
       
    79 /**
       
    80 	Implement CScsSession by handling the supplied message.
       
    81 
       
    82 	Note the subsession creation command is automatically sent to
       
    83 	DoCreateSubsessionL, and not this function.
       
    84 
       
    85 	@param	aFunction		Function identifier without SCS code.
       
    86 	@param	aMessage		Standard server-side handle to message.	 Not used.
       
    87  */
       
    88 	{
       
    89 	TAuthServerMessages func = static_cast<TAuthServerMessages>(aFunction);
       
    90 	
       
    91 	switch (func)
       
    92 		{
       
    93     case EAuthenticate:
       
    94         iAuthServer->AuthenticateL(aMessage);
       
    95         break;
       
    96     case ECancel:
       
    97 		iAuthServer->CancelL(aMessage);
       
    98 		break;
       
    99 	case EPlugins:
       
   100 		iAuthServer->PluginsL(aMessage);
       
   101 		break;
       
   102 	case EActivePlugins:
       
   103 		iAuthServer->ActivePluginsL(aMessage);
       
   104 		break;
       
   105 	case EPluginsByType:
       
   106 		iAuthServer->PluginsByTypeL(aMessage);
       
   107 		break;
       
   108 	case EPluginsByTraining:
       
   109 		iAuthServer->PluginsByTrainingL(aMessage);
       
   110 		break;
       
   111 	case EIdentities:
       
   112 		iAuthServer->IdentitiesL(aMessage);
       
   113 		break;
       
   114 	case EIdentityString:
       
   115 		iAuthServer->IdentityStringL(aMessage);
       
   116 		break;
       
   117 	case ESetIdentityString:
       
   118 		iAuthServer->SetIdentityStringL(aMessage);
       
   119 		break;
       
   120 	case ERegisterIdentity:
       
   121 		iAuthServer->RegisterIdentityL(aMessage);
       
   122 		break;
       
   123 	case ERemoveIdentity:
       
   124 		iAuthServer->RemoveIdentityL(aMessage);
       
   125 		break;
       
   126 	case ETrainPlugin:
       
   127 		iAuthServer->TrainPluginL(aMessage);
       
   128 		break;
       
   129 	case EForgetPlugin:
       
   130 		iAuthServer->ForgetPluginL(aMessage); 
       
   131 		break;
       
   132     case EDeauthenticate:
       
   133 		iAuthServer->DeauthenticateL(aMessage);
       
   134 		break;
       
   135 	case EGetAuthPreferences:
       
   136 		iAuthServer->PreferredTypePluginL(aMessage);
       
   137 	    break;
       
   138 	case ESetAuthPreferences:
       
   139 		iAuthServer->SetPreferredTypePluginL(aMessage);
       
   140 		break;
       
   141 	case EIdentitiesWithString:
       
   142 		iAuthServer->IdentitiesWithStringL(aMessage);
       
   143 		break;
       
   144 	case EListAuthAliases:
       
   145 		iAuthServer->ListAuthAliasesL(aMessage);
       
   146 		break;
       
   147 	case EResolveExpression:
       
   148 		iAuthServer->ResolveExpressionL(aMessage);
       
   149 		break;
       
   150 	case EResetIdentity:
       
   151 	case EResetIdentityByType:
       
   152 		iAuthServer->ResetIdentityL(aFunction, aMessage);
       
   153 		break;
       
   154 	case EResetIdentityByList:
       
   155 		iAuthServer->ResetIdentityByListL(aMessage);
       
   156 		break;
       
   157 	default:
       
   158 		PanicClient(aMessage,EPanicInvalidFunction);
       
   159 		break;
       
   160 		}
       
   161 	return EFalse;
       
   162 	}
       
   163 
       
   164 //
       
   165 // Handle an error from CAuthServerSession::ServiceL()
       
   166 // A bad descriptor error implies a badly programmed client, so panic it;
       
   167 // otherwise use the default handling (report the error to the client)
       
   168 //
       
   169 void CAuthServerSession::ServiceError(const RMessage2& aMessage, TInt aError)
       
   170 	{
       
   171 	TBool panicClient = ETrue;
       
   172 	TAuthServerPanic cliPanicReason = EPanicCorruptDescriptor;	//Init
       
   173 	
       
   174 	switch (aError)
       
   175 		{
       
   176 	case KErrBadDescriptor:
       
   177 		cliPanicReason = EPanicCorruptDescriptor;
       
   178 		break;
       
   179 	
       
   180 	case KErrAuthServInvalidInternalizeExpr:
       
   181 		cliPanicReason = EPanicBadExternalizedAuthExpr;
       
   182 		break;
       
   183 	case KErrAuthServNoSuchPlugin:
       
   184 		cliPanicReason = EPanicNoSuchAuthPlugin;
       
   185 		break;
       
   186 	
       
   187 	default:
       
   188 		panicClient = EFalse;
       
   189 		}
       
   190 	DEBUG_PRINTF3(_L8("Error in CAuthServerSession %d, func %d"), aError, aMessage.Function());
       
   191 
       
   192 	if (panicClient)
       
   193 		PanicClient(aMessage, cliPanicReason);
       
   194 	else
       
   195 		CScsSession::ServiceError(aMessage, aError);
       
   196 	}