sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "CCertAppsConduit.h" sl@0: #include "CFSCertAppsServer.h" sl@0: #include sl@0: #include "fstokencliserv.h" sl@0: #include "fstokenutil.h" sl@0: #include "fsmarshaller.h" sl@0: sl@0: _LIT_SECURITY_POLICY_C1(KAddRemovePolicy, ECapabilityWriteDeviceData); sl@0: sl@0: CCertAppsConduit* CCertAppsConduit::NewL(CFSCertAppsServer& aServer) sl@0: { sl@0: CCertAppsConduit* self = new (ELeave) CCertAppsConduit(aServer); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CCertAppsConduit::CCertAppsConduit(CFSCertAppsServer& aServer) : sl@0: iServer(aServer) sl@0: { sl@0: } sl@0: sl@0: void CCertAppsConduit::ConstructL() sl@0: { sl@0: } sl@0: sl@0: CCertAppsConduit::~CCertAppsConduit() sl@0: { sl@0: } sl@0: sl@0: void CCertAppsConduit::ServiceCertAppsRequestL(const RMessage2& aMessage) sl@0: { sl@0: switch(aMessage.Function()) sl@0: { sl@0: case EAddApp: sl@0: AddL(aMessage); sl@0: break; sl@0: sl@0: case ERemoveApp: sl@0: RemoveL(aMessage); sl@0: break; sl@0: sl@0: case EGetAppCount: sl@0: ApplicationCountL(aMessage); sl@0: break; sl@0: sl@0: case EGetApps: sl@0: ApplicationsL(aMessage); sl@0: break; sl@0: sl@0: case EGetApplication: sl@0: ApplicationL(aMessage); sl@0: break; sl@0: sl@0: default: sl@0: // Client made an illegal request sl@0: PanicClient(aMessage, EPanicInvalidRequest); sl@0: } sl@0: sl@0: aMessage.Complete(KErrNone); sl@0: } sl@0: sl@0: void CCertAppsConduit::AddL(const RMessage2& aMessage) const sl@0: { sl@0: // Add message is composed of the following structure sl@0: // Parameter 1 - TPckg sl@0: sl@0: // Check the calling process has the correct capabilities sl@0: if (!KAddRemovePolicy.CheckPolicy(aMessage)) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: sl@0: TCertificateAppInfo appInfo; sl@0: TPckg pckg(appInfo); sl@0: aMessage.ReadL(1, pckg); sl@0: sl@0: // Now that we have extracted the appInfo, we can call the sl@0: // real server sl@0: iServer.AddL(appInfo); sl@0: } sl@0: sl@0: void CCertAppsConduit::RemoveL(const RMessage2& aMessage) const sl@0: { sl@0: // Remove message is composed of a single TPckg sl@0: sl@0: // Check the calling process has the correct capabilities sl@0: if (!KAddRemovePolicy.CheckPolicy(aMessage)) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: sl@0: TUid uid; sl@0: TPckg pckg(uid); sl@0: aMessage.ReadL(1, pckg); sl@0: iServer.RemoveL(uid); sl@0: } sl@0: sl@0: void CCertAppsConduit::ApplicationCountL(const RMessage2& aMessage) const sl@0: { sl@0: // This message contains a single output descriptor of type sl@0: // TPckg sl@0: TInt appCount = iServer.ApplicationCountL(); sl@0: aMessage.WriteL(1, TPckg(appCount)); sl@0: } sl@0: sl@0: void CCertAppsConduit::ApplicationsL(const RMessage2& aMessage) const sl@0: { sl@0: // This message contains the following parameters: sl@0: // Param1: [IN] TInt - maximum buffer length allowed sl@0: // Param2: [OUT] TDes8 - The buffer to write into; if buffer size too sl@0: // small then will return KErrOverflow with param 2 being sl@0: // required size sl@0: sl@0: // Firstly, the maximum allowable length of the buffer sl@0: sl@0: // now get the array to be transmitted sl@0: RArray arr; sl@0: CleanupClosePushL(arr); sl@0: sl@0: // retrieve the array and marshall them into the message sl@0: iServer.ApplicationsL(arr); sl@0: sl@0: TInt reqdSize = TokenDataMarshaller::Size(arr); sl@0: TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(2)); sl@0: sl@0: if (reqdSize <= bufLen) sl@0: { sl@0: HBufC8* buf = HBufC8::NewMaxLC(reqdSize); sl@0: TPtr8 ptr(buf->Des()); sl@0: TokenDataMarshaller::Write(arr, ptr); sl@0: aMessage.WriteL(2, ptr); sl@0: CleanupStack::PopAndDestroy(buf); sl@0: } sl@0: else sl@0: { sl@0: aMessage.WriteL(2, TPckg(reqdSize)); sl@0: User::Leave(KErrOverflow); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(&arr); sl@0: } sl@0: sl@0: void CCertAppsConduit::ApplicationL(const RMessage2& aMessage) const sl@0: { sl@0: // The parameters for the ApplicationL function are as follows: sl@0: // Param1: [IN] TUid - The Uid of the app to retrieve sl@0: // Param2: [OUT] TCertificateAppInfo - The app info returned sl@0: sl@0: // Read the UID first sl@0: TUid uid; sl@0: TPckg pckgUid(uid); sl@0: aMessage.ReadL(1, pckgUid); sl@0: sl@0: // Now call the server sl@0: TCertificateAppInfo appInfo; sl@0: iServer.ApplicationL(uid, appInfo); sl@0: sl@0: // Now wrap the returned parameters into packages sl@0: aMessage.WriteL(2, TPckg(appInfo)); sl@0: }