os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/clientrequest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/clientrequest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,285 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +//system includes
    1.20 +#include <e32std.h>
    1.21 +#include <u32std.h>
    1.22 +
    1.23 +//class signature
    1.24 +#include "clientrequest.h"
    1.25 +
    1.26 +#ifndef __ECOMSERVER_TESTING__
    1.27 +
    1.28 +//
    1.29 +// TClientRequest
    1.30 +//
    1.31 +TClientRequest::TClientRequest(const RMessage2& aMessage)
    1.32 +: iMessage(aMessage), iSecurityInfo(aMessage)
    1.33 +	{
    1.34 +	}
    1.35 +	
    1.36 +TBool TClientRequest::IsNull() const
    1.37 +	{
    1.38 +	return iMessage.IsNull();
    1.39 +	}
    1.40 +
    1.41 +TInt TClientRequest::Function() const
    1.42 +	{
    1.43 +	return iMessage.Function();
    1.44 +	}
    1.45 +
    1.46 +void TClientRequest::Complete(TInt aReason) const
    1.47 +	{
    1.48 +	iMessage.Complete(aReason);
    1.49 +	}
    1.50 +
    1.51 +void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
    1.52 +	{
    1.53 +	iMessage.Panic(aCategory, aReason);
    1.54 +	}
    1.55 +
    1.56 +TInt TClientRequest::Int0() const
    1.57 +	{
    1.58 +	return iMessage.Int0();
    1.59 +	}
    1.60 +
    1.61 +TInt TClientRequest::Int1() const
    1.62 +	{
    1.63 +	return iMessage.Int1();
    1.64 +	}
    1.65 +
    1.66 +TInt TClientRequest::Int2() const
    1.67 +	{
    1.68 +	return iMessage.Int2();
    1.69 +	}
    1.70 +
    1.71 +TInt TClientRequest::Int3() const
    1.72 +	{
    1.73 +	return iMessage.Int3();
    1.74 +	}
    1.75 +
    1.76 +TInt TClientRequest::GetDesLength(TInt aParam) const
    1.77 +	{
    1.78 +	return iMessage.GetDesLength(aParam);
    1.79 +	}
    1.80 +
    1.81 +TInt TClientRequest::GetDesMaxLength(TInt aParam) const
    1.82 +	{
    1.83 +	return iMessage.GetDesMaxLength(aParam);
    1.84 +	}
    1.85 +
    1.86 +void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
    1.87 +	{
    1.88 +	iMessage.ReadL(aParam, aDes, aOffset);
    1.89 +	}
    1.90 +
    1.91 +void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
    1.92 +	{
    1.93 +	iMessage.ReadL(aParam, aDes, aOffset);
    1.94 +	}
    1.95 +
    1.96 +TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
    1.97 +	{
    1.98 +	return iMessage.Write(aParam, aDes, aOffset);
    1.99 +	}
   1.100 +
   1.101 +void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
   1.102 +	{
   1.103 +	iMessage.WriteL(aParam, aDes); 
   1.104 +	}
   1.105 +
   1.106 +void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
   1.107 +	{
   1.108 +	iMessage.WriteL(aParam, aDes, aOffset);
   1.109 +	}
   1.110 +	
   1.111 +//
   1.112 +// TCapabilitySet is the low level API used by all other capability APIs.
   1.113 +// It relies on the caller to observe the PlatSecEnforcement settings.
   1.114 +//
   1.115 +TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
   1.116 +	{
   1.117 +	return aCapabilities.HasCapabilities(iSecurityInfo.iCaps);
   1.118 +	}
   1.119 +
   1.120 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   1.121 +//
   1.122 +// This method relies on PlatSec::CapabilityCheckFail
   1.123 +// to observe the PlatSecDiagnostics flag.
   1.124 +//
   1.125 +void TClientRequest::EmitDiagnostic(const TCapabilitySet& aCapabilities, const CImplementationInformation& aImplInfo) const
   1.126 +	{
   1.127 +	TCapabilitySet capsMissing(iSecurityInfo.iCaps);
   1.128 +	capsMissing.Remove(aCapabilities);
   1.129 +	_LIT8(KErrorFormat, "ECOM: Client (%x) may not access plugin implementation (%x_v%d)");
   1.130 +	TBuf8<128> errorMsg;
   1.131 +	errorMsg.Format(KErrorFormat, iSecurityInfo.iSecureId.iId, aImplInfo.ImplementationUid(), aImplInfo.Version());
   1.132 +	errorMsg.ZeroTerminate();
   1.133 +	PlatSec::CapabilityCheckFail(
   1.134 +		iMessage,
   1.135 +		capsMissing,
   1.136 +		__PLATSEC_DIAGNOSTIC_STRING(reinterpret_cast<const char*>(errorMsg.Ptr())));
   1.137 +	}
   1.138 +#endif
   1.139 +
   1.140 +//
   1.141 +// This method serves three purposes:
   1.142 +// 1. Perform capability check.
   1.143 +// 2. Emit diagnostic message (if capability check failed and __REMOVE_PLATSEC_DIAGNOSTICS__ is *not* defined.)
   1.144 +// 3. Observe the PlatSecEnforcement flag and return if capability check has failed.
   1.145 +//
   1.146 +// If enforcement is not enabled then the caller should proceed as though the original capability check in fact passed.
   1.147 +// If enforcement is enabled then the appropriate action for a failed capability check should happen.
   1.148 +//
   1.149 +// Two possible return values:
   1.150 +// 1. ETrue  - if capability check passed OR PlatSecEnforcement is Off.
   1.151 +// 2. EFalse - if capability check failed AND PlatSecEnforcement is On.
   1.152 +//
   1.153 +TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation&
   1.154 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   1.155 +	aImplInfo
   1.156 +#endif
   1.157 +	) const
   1.158 +	{
   1.159 +	TBool hasCapabilities = HasCapabilities(aCapabilities);
   1.160 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   1.161 +	if (!hasCapabilities) 
   1.162 +		EmitDiagnostic(aCapabilities, aImplInfo);
   1.163 +#endif
   1.164 +	return !hasCapabilities && PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ? EFalse : ETrue;
   1.165 +	}
   1.166 +//
   1.167 +//
   1.168 +#else //IF _UNIT_TESTING_
   1.169 +
   1.170 +TClientRequest::TClientRequest()
   1.171 +: iFunction(KMinTInt), iCapability(0U), iCompletion(KRequestPending),
   1.172 +iStatusActive(EFalse), iIdentity(KNullUid)
   1.173 +	{
   1.174 +	Mem::FillZ(&iParams, sizeof(TInt) * KMaxMessageArguments);
   1.175 +	}
   1.176 +
   1.177 +TBool TClientRequest::IsNull() const
   1.178 +	{
   1.179 +	return iFunction == KMinTInt;
   1.180 +	}
   1.181 +
   1.182 +TInt TClientRequest::Function() const
   1.183 +	{
   1.184 +	return iFunction;
   1.185 +	}
   1.186 +
   1.187 +TUid TClientRequest::Identity() const
   1.188 +	{
   1.189 +	return iIdentity;
   1.190 +	}
   1.191 +
   1.192 +void TClientRequest::Complete(TInt aReason) const
   1.193 +	{
   1.194 +	iCompletion = aReason;
   1.195 +	if(iStatusActive)
   1.196 +		{
   1.197 +		TRequestStatus* stat = iStatus;
   1.198 +		User::RequestComplete(stat, aReason);
   1.199 +		}
   1.200 +	}
   1.201 +
   1.202 +void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
   1.203 +	{
   1.204 +	User::Panic(aCategory, aReason);
   1.205 +	}
   1.206 +
   1.207 +TInt TClientRequest::Int0() const
   1.208 +	{
   1.209 +	return iParams[0];
   1.210 +	}
   1.211 +
   1.212 +TInt TClientRequest::Int1() const
   1.213 +	{
   1.214 +	return iParams[1];
   1.215 +	}
   1.216 +
   1.217 +TInt TClientRequest::Int2() const
   1.218 +	{
   1.219 +	return iParams[2];
   1.220 +	}
   1.221 +
   1.222 +TInt TClientRequest::Int3() const
   1.223 +	{
   1.224 +	return iParams[3];
   1.225 +	}
   1.226 +
   1.227 +TInt TClientRequest::GetDesLength(TInt aParam) const
   1.228 +	{
   1.229 +	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
   1.230 +	return desPtr->Length();
   1.231 +	}
   1.232 +
   1.233 +TInt TClientRequest::GetDesMaxLength(TInt aParam) const
   1.234 +	{
   1.235 +	const TDes8* desPtr = (const TDes8*)iParams[aParam];
   1.236 +	return desPtr->MaxLength();
   1.237 +	}
   1.238 +
   1.239 +void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
   1.240 +	{
   1.241 +	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
   1.242 +	aDes.Copy(desPtr->Mid(aOffset));
   1.243 +	}
   1.244 +
   1.245 +void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
   1.246 +	{
   1.247 +	const TDesC* desPtr = (const TDesC*)iParams[aParam];
   1.248 +	aDes.Copy(desPtr->Mid(aOffset));
   1.249 +	}
   1.250 +
   1.251 +TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
   1.252 +	{
   1.253 +	TDes8* desPtr = (TDes8*)iParams[aParam];
   1.254 +	desPtr->Copy(aDes.Mid(aOffset));
   1.255 +	return KErrNone;
   1.256 +	}
   1.257 +
   1.258 +void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
   1.259 +	{
   1.260 +	User::LeaveIfError(Write(aParam, aDes));
   1.261 +	}
   1.262 +
   1.263 +void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
   1.264 +	{
   1.265 +	TDes* desPtr = (TDes*)iParams[aParam];
   1.266 +	desPtr->Copy(aDes.Mid(aOffset));
   1.267 +	}
   1.268 +
   1.269 +TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
   1.270 +//dummy function here for testing purpose
   1.271 +	{
   1.272 +	TCapabilitySet dummycaps;
   1.273 +	dummycaps.SetEmpty();
   1.274 +	return aCapabilities.HasCapabilities(dummycaps);
   1.275 +	}
   1.276 +
   1.277 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   1.278 +void TClientRequest::EmitDiagnostic(const TCapabilitySet& /*aCapabilities*/, const CImplementationInformation& /*aImplInfo*/) const
   1.279 +// do nothing
   1.280 +	{
   1.281 +	}
   1.282 +#endif
   1.283 +
   1.284 +TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation& /*aImplInfo*/) const
   1.285 +	{
   1.286 +	return HasCapabilities(aCapabilities);
   1.287 +	}
   1.288 +#endif //__ECOMSERVER_TESTING__