os/security/cryptoservices/filebasedcertificateandkeystores/source/certapps/server/CCertAppsConduit.cpp
Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "CCertAppsConduit.h"
20 #include "CFSCertAppsServer.h"
21 #include <certificateapps.h>
22 #include "fstokencliserv.h"
23 #include "fstokenutil.h"
24 #include "fsmarshaller.h"
26 _LIT_SECURITY_POLICY_C1(KAddRemovePolicy, ECapabilityWriteDeviceData);
28 CCertAppsConduit* CCertAppsConduit::NewL(CFSCertAppsServer& aServer)
30 CCertAppsConduit* self = new (ELeave) CCertAppsConduit(aServer);
31 CleanupStack::PushL(self);
33 CleanupStack::Pop(self);
37 CCertAppsConduit::CCertAppsConduit(CFSCertAppsServer& aServer) :
42 void CCertAppsConduit::ConstructL()
46 CCertAppsConduit::~CCertAppsConduit()
50 void CCertAppsConduit::ServiceCertAppsRequestL(const RMessage2& aMessage)
52 switch(aMessage.Function())
63 ApplicationCountL(aMessage);
67 ApplicationsL(aMessage);
71 ApplicationL(aMessage);
75 // Client made an illegal request
76 PanicClient(aMessage, EPanicInvalidRequest);
79 aMessage.Complete(KErrNone);
82 void CCertAppsConduit::AddL(const RMessage2& aMessage) const
84 // Add message is composed of the following structure
85 // Parameter 1 - TPckg<TCertificateAppInfo>
87 // Check the calling process has the correct capabilities
88 if (!KAddRemovePolicy.CheckPolicy(aMessage))
90 User::Leave(KErrPermissionDenied);
93 TCertificateAppInfo appInfo;
94 TPckg<TCertificateAppInfo> pckg(appInfo);
95 aMessage.ReadL(1, pckg);
97 // Now that we have extracted the appInfo, we can call the
99 iServer.AddL(appInfo);
102 void CCertAppsConduit::RemoveL(const RMessage2& aMessage) const
104 // Remove message is composed of a single TPckg<TUid>
106 // Check the calling process has the correct capabilities
107 if (!KAddRemovePolicy.CheckPolicy(aMessage))
109 User::Leave(KErrPermissionDenied);
113 TPckg<TUid> pckg(uid);
114 aMessage.ReadL(1, pckg);
115 iServer.RemoveL(uid);
118 void CCertAppsConduit::ApplicationCountL(const RMessage2& aMessage) const
120 // This message contains a single output descriptor of type
122 TInt appCount = iServer.ApplicationCountL();
123 aMessage.WriteL(1, TPckg<TInt>(appCount));
126 void CCertAppsConduit::ApplicationsL(const RMessage2& aMessage) const
128 // This message contains the following parameters:
129 // Param1: [IN] TInt - maximum buffer length allowed
130 // Param2: [OUT] TDes8 - The buffer to write into; if buffer size too
131 // small then will return KErrOverflow with param 2 being
134 // Firstly, the maximum allowable length of the buffer
136 // now get the array to be transmitted
137 RArray<TCertificateAppInfo> arr;
138 CleanupClosePushL(arr);
140 // retrieve the array and marshall them into the message
141 iServer.ApplicationsL(arr);
143 TInt reqdSize = TokenDataMarshaller::Size(arr);
144 TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(2));
146 if (reqdSize <= bufLen)
148 HBufC8* buf = HBufC8::NewMaxLC(reqdSize);
149 TPtr8 ptr(buf->Des());
150 TokenDataMarshaller::Write(arr, ptr);
151 aMessage.WriteL(2, ptr);
152 CleanupStack::PopAndDestroy(buf);
156 aMessage.WriteL(2, TPckg<TInt>(reqdSize));
157 User::Leave(KErrOverflow);
160 CleanupStack::PopAndDestroy(&arr);
163 void CCertAppsConduit::ApplicationL(const RMessage2& aMessage) const
165 // The parameters for the ApplicationL function are as follows:
166 // Param1: [IN] TUid - The Uid of the app to retrieve
167 // Param2: [OUT] TCertificateAppInfo - The app info returned
169 // Read the UID first
171 TPckg<TUid> pckgUid(uid);
172 aMessage.ReadL(1, pckgUid);
174 // Now call the server
175 TCertificateAppInfo appInfo;
176 iServer.ApplicationL(uid, appInfo);
178 // Now wrap the returned parameters into packages
179 aMessage.WriteL(2, TPckg<TCertificateAppInfo>(appInfo));