Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "clientrequest.h"
23 #ifndef __ECOMSERVER_TESTING__
28 TClientRequest::TClientRequest(const RMessage2& aMessage)
29 : iMessage(aMessage), iSecurityInfo(aMessage)
33 TBool TClientRequest::IsNull() const
35 return iMessage.IsNull();
38 TInt TClientRequest::Function() const
40 return iMessage.Function();
43 void TClientRequest::Complete(TInt aReason) const
45 iMessage.Complete(aReason);
48 void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
50 iMessage.Panic(aCategory, aReason);
53 TInt TClientRequest::Int0() const
55 return iMessage.Int0();
58 TInt TClientRequest::Int1() const
60 return iMessage.Int1();
63 TInt TClientRequest::Int2() const
65 return iMessage.Int2();
68 TInt TClientRequest::Int3() const
70 return iMessage.Int3();
73 TInt TClientRequest::GetDesLength(TInt aParam) const
75 return iMessage.GetDesLength(aParam);
78 TInt TClientRequest::GetDesMaxLength(TInt aParam) const
80 return iMessage.GetDesMaxLength(aParam);
83 void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
85 iMessage.ReadL(aParam, aDes, aOffset);
88 void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
90 iMessage.ReadL(aParam, aDes, aOffset);
93 TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
95 return iMessage.Write(aParam, aDes, aOffset);
98 void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
100 iMessage.WriteL(aParam, aDes);
103 void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
105 iMessage.WriteL(aParam, aDes, aOffset);
109 // TCapabilitySet is the low level API used by all other capability APIs.
110 // It relies on the caller to observe the PlatSecEnforcement settings.
112 TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
114 return aCapabilities.HasCapabilities(iSecurityInfo.iCaps);
117 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
119 // This method relies on PlatSec::CapabilityCheckFail
120 // to observe the PlatSecDiagnostics flag.
122 void TClientRequest::EmitDiagnostic(const TCapabilitySet& aCapabilities, const CImplementationInformation& aImplInfo) const
124 TCapabilitySet capsMissing(iSecurityInfo.iCaps);
125 capsMissing.Remove(aCapabilities);
126 _LIT8(KErrorFormat, "ECOM: Client (%x) may not access plugin implementation (%x_v%d)");
128 errorMsg.Format(KErrorFormat, iSecurityInfo.iSecureId.iId, aImplInfo.ImplementationUid(), aImplInfo.Version());
129 errorMsg.ZeroTerminate();
130 PlatSec::CapabilityCheckFail(
133 __PLATSEC_DIAGNOSTIC_STRING(reinterpret_cast<const char*>(errorMsg.Ptr())));
138 // This method serves three purposes:
139 // 1. Perform capability check.
140 // 2. Emit diagnostic message (if capability check failed and __REMOVE_PLATSEC_DIAGNOSTICS__ is *not* defined.)
141 // 3. Observe the PlatSecEnforcement flag and return if capability check has failed.
143 // If enforcement is not enabled then the caller should proceed as though the original capability check in fact passed.
144 // If enforcement is enabled then the appropriate action for a failed capability check should happen.
146 // Two possible return values:
147 // 1. ETrue - if capability check passed OR PlatSecEnforcement is Off.
148 // 2. EFalse - if capability check failed AND PlatSecEnforcement is On.
150 TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation&
151 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
156 TBool hasCapabilities = HasCapabilities(aCapabilities);
157 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
158 if (!hasCapabilities)
159 EmitDiagnostic(aCapabilities, aImplInfo);
161 return !hasCapabilities && PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ? EFalse : ETrue;
165 #else //IF _UNIT_TESTING_
167 TClientRequest::TClientRequest()
168 : iFunction(KMinTInt), iCapability(0U), iCompletion(KRequestPending),
169 iStatusActive(EFalse), iIdentity(KNullUid)
171 Mem::FillZ(&iParams, sizeof(TInt) * KMaxMessageArguments);
174 TBool TClientRequest::IsNull() const
176 return iFunction == KMinTInt;
179 TInt TClientRequest::Function() const
184 TUid TClientRequest::Identity() const
189 void TClientRequest::Complete(TInt aReason) const
191 iCompletion = aReason;
194 TRequestStatus* stat = iStatus;
195 User::RequestComplete(stat, aReason);
199 void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
201 User::Panic(aCategory, aReason);
204 TInt TClientRequest::Int0() const
209 TInt TClientRequest::Int1() const
214 TInt TClientRequest::Int2() const
219 TInt TClientRequest::Int3() const
224 TInt TClientRequest::GetDesLength(TInt aParam) const
226 const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
227 return desPtr->Length();
230 TInt TClientRequest::GetDesMaxLength(TInt aParam) const
232 const TDes8* desPtr = (const TDes8*)iParams[aParam];
233 return desPtr->MaxLength();
236 void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
238 const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
239 aDes.Copy(desPtr->Mid(aOffset));
242 void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
244 const TDesC* desPtr = (const TDesC*)iParams[aParam];
245 aDes.Copy(desPtr->Mid(aOffset));
248 TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
250 TDes8* desPtr = (TDes8*)iParams[aParam];
251 desPtr->Copy(aDes.Mid(aOffset));
255 void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
257 User::LeaveIfError(Write(aParam, aDes));
260 void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
262 TDes* desPtr = (TDes*)iParams[aParam];
263 desPtr->Copy(aDes.Mid(aOffset));
266 TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
267 //dummy function here for testing purpose
269 TCapabilitySet dummycaps;
270 dummycaps.SetEmpty();
271 return aCapabilities.HasCapabilities(dummycaps);
274 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
275 void TClientRequest::EmitDiagnostic(const TCapabilitySet& /*aCapabilities*/, const CImplementationInformation& /*aImplInfo*/) const
281 TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation& /*aImplInfo*/) const
283 return HasCapabilities(aCapabilities);
285 #endif //__ECOMSERVER_TESTING__