lowlevellibsandfws/pluginfw/Framework/frame/clientrequest.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 //system includes
       
    17 #include <e32std.h>
       
    18 #include <u32std.h>
       
    19 
       
    20 //class signature
       
    21 #include "clientrequest.h"
       
    22 
       
    23 #ifndef __ECOMSERVER_TESTING__
       
    24 
       
    25 //
       
    26 // TClientRequest
       
    27 //
       
    28 TClientRequest::TClientRequest(const RMessage2& aMessage)
       
    29 : iMessage(aMessage), iSecurityInfo(aMessage)
       
    30 	{
       
    31 	}
       
    32 	
       
    33 TBool TClientRequest::IsNull() const
       
    34 	{
       
    35 	return iMessage.IsNull();
       
    36 	}
       
    37 
       
    38 TInt TClientRequest::Function() const
       
    39 	{
       
    40 	return iMessage.Function();
       
    41 	}
       
    42 
       
    43 void TClientRequest::Complete(TInt aReason) const
       
    44 	{
       
    45 	iMessage.Complete(aReason);
       
    46 	}
       
    47 
       
    48 void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
       
    49 	{
       
    50 	iMessage.Panic(aCategory, aReason);
       
    51 	}
       
    52 
       
    53 TInt TClientRequest::Int0() const
       
    54 	{
       
    55 	return iMessage.Int0();
       
    56 	}
       
    57 
       
    58 TInt TClientRequest::Int1() const
       
    59 	{
       
    60 	return iMessage.Int1();
       
    61 	}
       
    62 
       
    63 TInt TClientRequest::Int2() const
       
    64 	{
       
    65 	return iMessage.Int2();
       
    66 	}
       
    67 
       
    68 TInt TClientRequest::Int3() const
       
    69 	{
       
    70 	return iMessage.Int3();
       
    71 	}
       
    72 
       
    73 TInt TClientRequest::GetDesLength(TInt aParam) const
       
    74 	{
       
    75 	return iMessage.GetDesLength(aParam);
       
    76 	}
       
    77 
       
    78 TInt TClientRequest::GetDesMaxLength(TInt aParam) const
       
    79 	{
       
    80 	return iMessage.GetDesMaxLength(aParam);
       
    81 	}
       
    82 
       
    83 void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
       
    84 	{
       
    85 	iMessage.ReadL(aParam, aDes, aOffset);
       
    86 	}
       
    87 
       
    88 void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
       
    89 	{
       
    90 	iMessage.ReadL(aParam, aDes, aOffset);
       
    91 	}
       
    92 
       
    93 TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
       
    94 	{
       
    95 	return iMessage.Write(aParam, aDes, aOffset);
       
    96 	}
       
    97 
       
    98 void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
       
    99 	{
       
   100 	iMessage.WriteL(aParam, aDes); 
       
   101 	}
       
   102 
       
   103 void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
       
   104 	{
       
   105 	iMessage.WriteL(aParam, aDes, aOffset);
       
   106 	}
       
   107 	
       
   108 //
       
   109 // TCapabilitySet is the low level API used by all other capability APIs.
       
   110 // It relies on the caller to observe the PlatSecEnforcement settings.
       
   111 //
       
   112 TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
       
   113 	{
       
   114 	return aCapabilities.HasCapabilities(iSecurityInfo.iCaps);
       
   115 	}
       
   116 
       
   117 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   118 //
       
   119 // This method relies on PlatSec::CapabilityCheckFail
       
   120 // to observe the PlatSecDiagnostics flag.
       
   121 //
       
   122 void TClientRequest::EmitDiagnostic(const TCapabilitySet& aCapabilities, const CImplementationInformation& aImplInfo) const
       
   123 	{
       
   124 	TCapabilitySet capsMissing(iSecurityInfo.iCaps);
       
   125 	capsMissing.Remove(aCapabilities);
       
   126 	_LIT8(KErrorFormat, "ECOM: Client (%x) may not access plugin implementation (%x_v%d)");
       
   127 	TBuf8<128> errorMsg;
       
   128 	errorMsg.Format(KErrorFormat, iSecurityInfo.iSecureId.iId, aImplInfo.ImplementationUid(), aImplInfo.Version());
       
   129 	errorMsg.ZeroTerminate();
       
   130 	PlatSec::CapabilityCheckFail(
       
   131 		iMessage,
       
   132 		capsMissing,
       
   133 		__PLATSEC_DIAGNOSTIC_STRING(reinterpret_cast<const char*>(errorMsg.Ptr())));
       
   134 	}
       
   135 #endif
       
   136 
       
   137 //
       
   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.
       
   142 //
       
   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.
       
   145 //
       
   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.
       
   149 //
       
   150 TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation&
       
   151 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   152 	aImplInfo
       
   153 #endif
       
   154 	) const
       
   155 	{
       
   156 	TBool hasCapabilities = HasCapabilities(aCapabilities);
       
   157 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   158 	if (!hasCapabilities) 
       
   159 		EmitDiagnostic(aCapabilities, aImplInfo);
       
   160 #endif
       
   161 	return !hasCapabilities && PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ? EFalse : ETrue;
       
   162 	}
       
   163 //
       
   164 //
       
   165 #else //IF _UNIT_TESTING_
       
   166 
       
   167 TClientRequest::TClientRequest()
       
   168 : iFunction(KMinTInt), iCapability(0U), iCompletion(KRequestPending),
       
   169 iStatusActive(EFalse), iIdentity(KNullUid)
       
   170 	{
       
   171 	Mem::FillZ(&iParams, sizeof(TInt) * KMaxMessageArguments);
       
   172 	}
       
   173 
       
   174 TBool TClientRequest::IsNull() const
       
   175 	{
       
   176 	return iFunction == KMinTInt;
       
   177 	}
       
   178 
       
   179 TInt TClientRequest::Function() const
       
   180 	{
       
   181 	return iFunction;
       
   182 	}
       
   183 
       
   184 TUid TClientRequest::Identity() const
       
   185 	{
       
   186 	return iIdentity;
       
   187 	}
       
   188 
       
   189 void TClientRequest::Complete(TInt aReason) const
       
   190 	{
       
   191 	iCompletion = aReason;
       
   192 	if(iStatusActive)
       
   193 		{
       
   194 		TRequestStatus* stat = iStatus;
       
   195 		User::RequestComplete(stat, aReason);
       
   196 		}
       
   197 	}
       
   198 
       
   199 void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
       
   200 	{
       
   201 	User::Panic(aCategory, aReason);
       
   202 	}
       
   203 
       
   204 TInt TClientRequest::Int0() const
       
   205 	{
       
   206 	return iParams[0];
       
   207 	}
       
   208 
       
   209 TInt TClientRequest::Int1() const
       
   210 	{
       
   211 	return iParams[1];
       
   212 	}
       
   213 
       
   214 TInt TClientRequest::Int2() const
       
   215 	{
       
   216 	return iParams[2];
       
   217 	}
       
   218 
       
   219 TInt TClientRequest::Int3() const
       
   220 	{
       
   221 	return iParams[3];
       
   222 	}
       
   223 
       
   224 TInt TClientRequest::GetDesLength(TInt aParam) const
       
   225 	{
       
   226 	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
       
   227 	return desPtr->Length();
       
   228 	}
       
   229 
       
   230 TInt TClientRequest::GetDesMaxLength(TInt aParam) const
       
   231 	{
       
   232 	const TDes8* desPtr = (const TDes8*)iParams[aParam];
       
   233 	return desPtr->MaxLength();
       
   234 	}
       
   235 
       
   236 void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
       
   237 	{
       
   238 	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
       
   239 	aDes.Copy(desPtr->Mid(aOffset));
       
   240 	}
       
   241 
       
   242 void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
       
   243 	{
       
   244 	const TDesC* desPtr = (const TDesC*)iParams[aParam];
       
   245 	aDes.Copy(desPtr->Mid(aOffset));
       
   246 	}
       
   247 
       
   248 TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
       
   249 	{
       
   250 	TDes8* desPtr = (TDes8*)iParams[aParam];
       
   251 	desPtr->Copy(aDes.Mid(aOffset));
       
   252 	return KErrNone;
       
   253 	}
       
   254 
       
   255 void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
       
   256 	{
       
   257 	User::LeaveIfError(Write(aParam, aDes));
       
   258 	}
       
   259 
       
   260 void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
       
   261 	{
       
   262 	TDes* desPtr = (TDes*)iParams[aParam];
       
   263 	desPtr->Copy(aDes.Mid(aOffset));
       
   264 	}
       
   265 
       
   266 TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
       
   267 //dummy function here for testing purpose
       
   268 	{
       
   269 	TCapabilitySet dummycaps;
       
   270 	dummycaps.SetEmpty();
       
   271 	return aCapabilities.HasCapabilities(dummycaps);
       
   272 	}
       
   273 
       
   274 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   275 void TClientRequest::EmitDiagnostic(const TCapabilitySet& /*aCapabilities*/, const CImplementationInformation& /*aImplInfo*/) const
       
   276 // do nothing
       
   277 	{
       
   278 	}
       
   279 #endif
       
   280 
       
   281 TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation& /*aImplInfo*/) const
       
   282 	{
       
   283 	return HasCapabilities(aCapabilities);
       
   284 	}
       
   285 #endif //__ECOMSERVER_TESTING__