os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/clientrequest.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
//system includes
sl@0
    17
#include <e32std.h>
sl@0
    18
#include <u32std.h>
sl@0
    19
sl@0
    20
//class signature
sl@0
    21
#include "clientrequest.h"
sl@0
    22
sl@0
    23
#ifndef __ECOMSERVER_TESTING__
sl@0
    24
sl@0
    25
//
sl@0
    26
// TClientRequest
sl@0
    27
//
sl@0
    28
TClientRequest::TClientRequest(const RMessage2& aMessage)
sl@0
    29
: iMessage(aMessage), iSecurityInfo(aMessage)
sl@0
    30
	{
sl@0
    31
	}
sl@0
    32
	
sl@0
    33
TBool TClientRequest::IsNull() const
sl@0
    34
	{
sl@0
    35
	return iMessage.IsNull();
sl@0
    36
	}
sl@0
    37
sl@0
    38
TInt TClientRequest::Function() const
sl@0
    39
	{
sl@0
    40
	return iMessage.Function();
sl@0
    41
	}
sl@0
    42
sl@0
    43
void TClientRequest::Complete(TInt aReason) const
sl@0
    44
	{
sl@0
    45
	iMessage.Complete(aReason);
sl@0
    46
	}
sl@0
    47
sl@0
    48
void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
sl@0
    49
	{
sl@0
    50
	iMessage.Panic(aCategory, aReason);
sl@0
    51
	}
sl@0
    52
sl@0
    53
TInt TClientRequest::Int0() const
sl@0
    54
	{
sl@0
    55
	return iMessage.Int0();
sl@0
    56
	}
sl@0
    57
sl@0
    58
TInt TClientRequest::Int1() const
sl@0
    59
	{
sl@0
    60
	return iMessage.Int1();
sl@0
    61
	}
sl@0
    62
sl@0
    63
TInt TClientRequest::Int2() const
sl@0
    64
	{
sl@0
    65
	return iMessage.Int2();
sl@0
    66
	}
sl@0
    67
sl@0
    68
TInt TClientRequest::Int3() const
sl@0
    69
	{
sl@0
    70
	return iMessage.Int3();
sl@0
    71
	}
sl@0
    72
sl@0
    73
TInt TClientRequest::GetDesLength(TInt aParam) const
sl@0
    74
	{
sl@0
    75
	return iMessage.GetDesLength(aParam);
sl@0
    76
	}
sl@0
    77
sl@0
    78
TInt TClientRequest::GetDesMaxLength(TInt aParam) const
sl@0
    79
	{
sl@0
    80
	return iMessage.GetDesMaxLength(aParam);
sl@0
    81
	}
sl@0
    82
sl@0
    83
void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
sl@0
    84
	{
sl@0
    85
	iMessage.ReadL(aParam, aDes, aOffset);
sl@0
    86
	}
sl@0
    87
sl@0
    88
void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
sl@0
    89
	{
sl@0
    90
	iMessage.ReadL(aParam, aDes, aOffset);
sl@0
    91
	}
sl@0
    92
sl@0
    93
TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
sl@0
    94
	{
sl@0
    95
	return iMessage.Write(aParam, aDes, aOffset);
sl@0
    96
	}
sl@0
    97
sl@0
    98
void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
sl@0
    99
	{
sl@0
   100
	iMessage.WriteL(aParam, aDes); 
sl@0
   101
	}
sl@0
   102
sl@0
   103
void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
sl@0
   104
	{
sl@0
   105
	iMessage.WriteL(aParam, aDes, aOffset);
sl@0
   106
	}
sl@0
   107
	
sl@0
   108
//
sl@0
   109
// TCapabilitySet is the low level API used by all other capability APIs.
sl@0
   110
// It relies on the caller to observe the PlatSecEnforcement settings.
sl@0
   111
//
sl@0
   112
TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
sl@0
   113
	{
sl@0
   114
	return aCapabilities.HasCapabilities(iSecurityInfo.iCaps);
sl@0
   115
	}
sl@0
   116
sl@0
   117
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
sl@0
   118
//
sl@0
   119
// This method relies on PlatSec::CapabilityCheckFail
sl@0
   120
// to observe the PlatSecDiagnostics flag.
sl@0
   121
//
sl@0
   122
void TClientRequest::EmitDiagnostic(const TCapabilitySet& aCapabilities, const CImplementationInformation& aImplInfo) const
sl@0
   123
	{
sl@0
   124
	TCapabilitySet capsMissing(iSecurityInfo.iCaps);
sl@0
   125
	capsMissing.Remove(aCapabilities);
sl@0
   126
	_LIT8(KErrorFormat, "ECOM: Client (%x) may not access plugin implementation (%x_v%d)");
sl@0
   127
	TBuf8<128> errorMsg;
sl@0
   128
	errorMsg.Format(KErrorFormat, iSecurityInfo.iSecureId.iId, aImplInfo.ImplementationUid(), aImplInfo.Version());
sl@0
   129
	errorMsg.ZeroTerminate();
sl@0
   130
	PlatSec::CapabilityCheckFail(
sl@0
   131
		iMessage,
sl@0
   132
		capsMissing,
sl@0
   133
		__PLATSEC_DIAGNOSTIC_STRING(reinterpret_cast<const char*>(errorMsg.Ptr())));
sl@0
   134
	}
sl@0
   135
#endif
sl@0
   136
sl@0
   137
//
sl@0
   138
// This method serves three purposes:
sl@0
   139
// 1. Perform capability check.
sl@0
   140
// 2. Emit diagnostic message (if capability check failed and __REMOVE_PLATSEC_DIAGNOSTICS__ is *not* defined.)
sl@0
   141
// 3. Observe the PlatSecEnforcement flag and return if capability check has failed.
sl@0
   142
//
sl@0
   143
// If enforcement is not enabled then the caller should proceed as though the original capability check in fact passed.
sl@0
   144
// If enforcement is enabled then the appropriate action for a failed capability check should happen.
sl@0
   145
//
sl@0
   146
// Two possible return values:
sl@0
   147
// 1. ETrue  - if capability check passed OR PlatSecEnforcement is Off.
sl@0
   148
// 2. EFalse - if capability check failed AND PlatSecEnforcement is On.
sl@0
   149
//
sl@0
   150
TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation&
sl@0
   151
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
sl@0
   152
	aImplInfo
sl@0
   153
#endif
sl@0
   154
	) const
sl@0
   155
	{
sl@0
   156
	TBool hasCapabilities = HasCapabilities(aCapabilities);
sl@0
   157
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
sl@0
   158
	if (!hasCapabilities) 
sl@0
   159
		EmitDiagnostic(aCapabilities, aImplInfo);
sl@0
   160
#endif
sl@0
   161
	return !hasCapabilities && PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ? EFalse : ETrue;
sl@0
   162
	}
sl@0
   163
//
sl@0
   164
//
sl@0
   165
#else //IF _UNIT_TESTING_
sl@0
   166
sl@0
   167
TClientRequest::TClientRequest()
sl@0
   168
: iFunction(KMinTInt), iCapability(0U), iCompletion(KRequestPending),
sl@0
   169
iStatusActive(EFalse), iIdentity(KNullUid)
sl@0
   170
	{
sl@0
   171
	Mem::FillZ(&iParams, sizeof(TInt) * KMaxMessageArguments);
sl@0
   172
	}
sl@0
   173
sl@0
   174
TBool TClientRequest::IsNull() const
sl@0
   175
	{
sl@0
   176
	return iFunction == KMinTInt;
sl@0
   177
	}
sl@0
   178
sl@0
   179
TInt TClientRequest::Function() const
sl@0
   180
	{
sl@0
   181
	return iFunction;
sl@0
   182
	}
sl@0
   183
sl@0
   184
TUid TClientRequest::Identity() const
sl@0
   185
	{
sl@0
   186
	return iIdentity;
sl@0
   187
	}
sl@0
   188
sl@0
   189
void TClientRequest::Complete(TInt aReason) const
sl@0
   190
	{
sl@0
   191
	iCompletion = aReason;
sl@0
   192
	if(iStatusActive)
sl@0
   193
		{
sl@0
   194
		TRequestStatus* stat = iStatus;
sl@0
   195
		User::RequestComplete(stat, aReason);
sl@0
   196
		}
sl@0
   197
	}
sl@0
   198
sl@0
   199
void TClientRequest::Panic(const TDesC& aCategory, TInt aReason) const
sl@0
   200
	{
sl@0
   201
	User::Panic(aCategory, aReason);
sl@0
   202
	}
sl@0
   203
sl@0
   204
TInt TClientRequest::Int0() const
sl@0
   205
	{
sl@0
   206
	return iParams[0];
sl@0
   207
	}
sl@0
   208
sl@0
   209
TInt TClientRequest::Int1() const
sl@0
   210
	{
sl@0
   211
	return iParams[1];
sl@0
   212
	}
sl@0
   213
sl@0
   214
TInt TClientRequest::Int2() const
sl@0
   215
	{
sl@0
   216
	return iParams[2];
sl@0
   217
	}
sl@0
   218
sl@0
   219
TInt TClientRequest::Int3() const
sl@0
   220
	{
sl@0
   221
	return iParams[3];
sl@0
   222
	}
sl@0
   223
sl@0
   224
TInt TClientRequest::GetDesLength(TInt aParam) const
sl@0
   225
	{
sl@0
   226
	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
sl@0
   227
	return desPtr->Length();
sl@0
   228
	}
sl@0
   229
sl@0
   230
TInt TClientRequest::GetDesMaxLength(TInt aParam) const
sl@0
   231
	{
sl@0
   232
	const TDes8* desPtr = (const TDes8*)iParams[aParam];
sl@0
   233
	return desPtr->MaxLength();
sl@0
   234
	}
sl@0
   235
sl@0
   236
void TClientRequest::ReadL(TInt aParam, TDes8& aDes, TInt aOffset) const
sl@0
   237
	{
sl@0
   238
	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
sl@0
   239
	aDes.Copy(desPtr->Mid(aOffset));
sl@0
   240
	}
sl@0
   241
sl@0
   242
void TClientRequest::ReadL(TInt aParam, TDes& aDes, TInt aOffset) const
sl@0
   243
	{
sl@0
   244
	const TDesC* desPtr = (const TDesC*)iParams[aParam];
sl@0
   245
	aDes.Copy(desPtr->Mid(aOffset));
sl@0
   246
	}
sl@0
   247
sl@0
   248
TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
sl@0
   249
	{
sl@0
   250
	TDes8* desPtr = (TDes8*)iParams[aParam];
sl@0
   251
	desPtr->Copy(aDes.Mid(aOffset));
sl@0
   252
	return KErrNone;
sl@0
   253
	}
sl@0
   254
sl@0
   255
void TClientRequest::WriteL(TInt aParam, const TDesC8& aDes) const
sl@0
   256
	{
sl@0
   257
	User::LeaveIfError(Write(aParam, aDes));
sl@0
   258
	}
sl@0
   259
sl@0
   260
void TClientRequest::WriteL(TInt aParam, const TDesC& aDes, TInt aOffset) const
sl@0
   261
	{
sl@0
   262
	TDes* desPtr = (TDes*)iParams[aParam];
sl@0
   263
	desPtr->Copy(aDes.Mid(aOffset));
sl@0
   264
	}
sl@0
   265
sl@0
   266
TBool TClientRequest::HasCapabilities(const TCapabilitySet& aCapabilities) const
sl@0
   267
//dummy function here for testing purpose
sl@0
   268
	{
sl@0
   269
	TCapabilitySet dummycaps;
sl@0
   270
	dummycaps.SetEmpty();
sl@0
   271
	return aCapabilities.HasCapabilities(dummycaps);
sl@0
   272
	}
sl@0
   273
sl@0
   274
#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
sl@0
   275
void TClientRequest::EmitDiagnostic(const TCapabilitySet& /*aCapabilities*/, const CImplementationInformation& /*aImplInfo*/) const
sl@0
   276
// do nothing
sl@0
   277
	{
sl@0
   278
	}
sl@0
   279
#endif
sl@0
   280
sl@0
   281
TBool TClientRequest::CheckCapability(const TCapabilitySet& aCapabilities, const CImplementationInformation& /*aImplInfo*/) const
sl@0
   282
	{
sl@0
   283
	return HasCapabilities(aCapabilities);
sl@0
   284
	}
sl@0
   285
#endif //__ECOMSERVER_TESTING__