os/ossrv/lowlevellibsandfws/apputils/bsul/inc/clientmessagecmn.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/bsul/inc/clientmessagecmn.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,273 @@
     1.4 +// Copyright (c) 2008-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 +// Wrapper around RMessage2 that provides message validation and error handling
    1.18 +// to improve robustness of system servers under IPC attack
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#if !defined(CLIENTMESSAGECMN_H)
    1.23 +#define CLIENTMESSAGECMN_H
    1.24 +
    1.25 +#include <e32std.h>
    1.26 +#include <e32base.h>
    1.27 +#include <e32debug.h>
    1.28 +#include <babitflags.h>
    1.29 +#include "clientmessage.h"
    1.30 +
    1.31 +namespace BSUL
    1.32 +	{
    1.33 +
    1.34 +	
    1.35 +	/**
    1.36 +	This defines the maximum number of parameters that can be stored in a  
    1.37 +	TClientMessageSchema structure.  This corresponds to the maximum number
    1.38 +	of arguments in an RMessage2
    1.39 +	@internalComponent
    1.40 +	*/
    1.41 +	const TInt KMaxParameters = 4;
    1.42 +	
    1.43 +	/**
    1.44 +	This mask is used to select the parameter type from TParameterDetails.iType
    1.45 +	@internalComponent
    1.46 +	*/	
    1.47 +	const TInt KParamTypeMask = 0xFFFF;
    1.48 +	
    1.49 +	/**
    1.50 +	This mask is used to select the validation function index from 
    1.51 +	TParameterDetails.iType
    1.52 +	@internalComponent
    1.53 +	*/	
    1.54 +	const TInt KValidationFnIndexMask = 0xFFFF0000;
    1.55 +	
    1.56 +	/**
    1.57 +	This is used to shift down the value masked using KValidationFnIndexMask 
    1.58 +	@internalComponent
    1.59 +	*/	
    1.60 +	const TInt KShift16Bit = 16;
    1.61 +	
    1.62 +	
    1.63 +	/**
    1.64 +	This enum lists the flags currently represented by the TBitFlags32
    1.65 +	CClientMessage::iFlags
    1.66 +	@internalComponent 
    1.67 +	**/
    1.68 +	enum TFlagValues
    1.69 +		{
    1.70 +		EFlagParam0Validated = 0,
    1.71 +		EFlagParam1Validated,
    1.72 +		EFlagParam2Validated,
    1.73 +		EFlagParam3Validated,
    1.74 +		/** Informs CompleteRequestL() that message not valid as client has already been panicked. */
    1.75 +		EFlagPanicClient,
    1.76 +		/** Setting this flag indicates that for bad message errors, request 
    1.77 +		should be completed with error code rather than panicking the client */
    1.78 +		EFlagDoNotPanicClientOnBadMessageErrors = 30,
    1.79 +		EFlagLogBadMessages = 31
    1.80 +		};
    1.81 +	
    1.82 +	/**
    1.83 +	This class implements the behaviour for a TInt parameter type.
    1.84 +	The ValidateL function reads the Int value from the clients message and checks 
    1.85 +	that the value read is between the iMax and iMin constraints defined in the 
    1.86 +	message schema.
    1.87 +	@internalComponent
    1.88 +	*/
    1.89 +	NONSHARABLE_CLASS(CIntParameter) : public CMessageParameterBase
    1.90 +	{
    1.91 +	public:
    1.92 +		
    1.93 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
    1.94 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
    1.95 +		virtual ~CIntParameter();
    1.96 +		virtual void ValidateL();
    1.97 +		virtual TInt GetIntL();
    1.98 +		
    1.99 +	private:
   1.100 +		CIntParameter(const TParameterDetails& aParam,TInt aParamIndex, 
   1.101 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.102 +	
   1.103 +	private:	
   1.104 +		//This stores the TInt value read from the client message during validation
   1.105 +		TInt iValue;
   1.106 +	};
   1.107 +	
   1.108 +	/**
   1.109 +	This class implements the behaviour for a read only 8 bit
   1.110 +	descriptor parameter type.  The ValidateL function checks that the length 
   1.111 +	of the descriptor argument in the client’s process does not exceed iMax 
   1.112 +	defined in the message schema.
   1.113 +	@internalComponent
   1.114 +	*/
   1.115 +	NONSHARABLE_CLASS(CDes8ReadParameter) : public CMessageParameterBase
   1.116 +	{
   1.117 +	public:
   1.118 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.119 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.120 +		virtual ~CDes8ReadParameter();
   1.121 +		virtual void ValidateL();
   1.122 +		virtual const TDesC8& GetDes8L();
   1.123 +		virtual TInt GetDesLengthL();
   1.124 +		virtual void ReadL(TDes8& aDes, TInt aOffset);	
   1.125 +		
   1.126 +	private:
   1.127 +		CDes8ReadParameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.128 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.129 +		
   1.130 +	private:	
   1.131 +		//On validation this descriptor is instantiated and the contents or the client 
   1.132 +		//descriptor are read into the local descriptor 
   1.133 +		HBufC8* iValue;
   1.134 +	};
   1.135 +	
   1.136 +	/**
   1.137 +	This class implements the behaviour for a read\write 8 bit
   1.138 +	descriptor parameter type.  The ValidateL function checks that the MaxLength 
   1.139 +	of the descriptor in the client’s process is not less than iMin and that the 
   1.140 +	length of the descriptor does not exceed iMax defined in the message schema. 
   1.141 +	@internalComponent
   1.142 +	*/
   1.143 +	NONSHARABLE_CLASS(CDes8Parameter) : public CMessageParameterBase
   1.144 +	{
   1.145 +	public:
   1.146 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.147 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.148 +		virtual ~CDes8Parameter();
   1.149 +		virtual void ValidateL();
   1.150 +		virtual void WriteL(const TDesC8& aDes, TInt aOffset);
   1.151 +		virtual void ReadL(TDes8& aDes, TInt aOffset);
   1.152 +		virtual TInt GetDesLengthL();
   1.153 +		virtual TInt GetDesMaxLengthL();
   1.154 +		
   1.155 +	protected:
   1.156 +		CDes8Parameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.157 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.158 +	};
   1.159 +	
   1.160 +	/**
   1.161 +	This class implements the behaviour for a read only 16 bit
   1.162 +	descriptor parameter type.  The ValidateL function checks that the length 
   1.163 +	of the descriptor argument in the client’s process does not exceed iMax 
   1.164 +	defined in the message schema.
   1.165 +	@internalComponent
   1.166 +	*/
   1.167 +	NONSHARABLE_CLASS(CDes16ReadParameter) : public CMessageParameterBase
   1.168 +	{
   1.169 +	public:
   1.170 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.171 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);	
   1.172 +		virtual ~CDes16ReadParameter();
   1.173 +		virtual void ValidateL();
   1.174 +		virtual const TDesC& GetDes16L();
   1.175 +		virtual TInt GetDesLengthL();
   1.176 +		virtual void ReadL(TDes& aDes, TInt aOffset);
   1.177 +		
   1.178 +		
   1.179 +	private:
   1.180 +		CDes16ReadParameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.181 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.182 +		
   1.183 +	private:
   1.184 +		//On validation this descriptor is instantiated and the contents or the client 
   1.185 +		//descriptor are read into the local descriptor 
   1.186 +		HBufC* iValue;
   1.187 +	};
   1.188 +	
   1.189 +	/**
   1.190 +	This class implements the behaviour for a read\write 16 bit
   1.191 +	descriptor parameter type.  The ValidateL function checks that the MaxLength 
   1.192 +	of the descriptor in the client’s process is not less than iMin and that the 
   1.193 +	length of the descriptor does not exceed iMax defined in the message schema. 
   1.194 +	@internalComponent
   1.195 +	*/
   1.196 +	NONSHARABLE_CLASS(CDes16Parameter) : public CMessageParameterBase
   1.197 +	{
   1.198 +	public:
   1.199 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.200 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.201 +		virtual ~CDes16Parameter();
   1.202 +		virtual void ValidateL();
   1.203 +		virtual void WriteL(const TDesC& aDes, TInt aOffset);
   1.204 +		virtual void ReadL(TDes& aDes, TInt aOffset);
   1.205 +		virtual TInt GetDesLengthL();
   1.206 +		virtual TInt GetDesMaxLengthL();
   1.207 +		
   1.208 +	private:
   1.209 +		CDes16Parameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.210 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.211 +	};
   1.212 +	
   1.213 +	
   1.214 +	/**
   1.215 +	This class implements the behaviour for a generic TPckg<>
   1.216 +	parameter type.  The ValidateL function calls the custom validation function 
   1.217 +	passed in to the object on creation.
   1.218 +	@internalComponent
   1.219 +	*/
   1.220 +	NONSHARABLE_CLASS(CPckgParameter) : public CDes8Parameter
   1.221 +	{
   1.222 +	public:
   1.223 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.224 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.225 +		virtual ~CPckgParameter();
   1.226 +		virtual void ValidateL();
   1.227 +		
   1.228 +	private:
   1.229 +		CPckgParameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.230 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn );
   1.231 +	};
   1.232 +	
   1.233 +	
   1.234 +	/**
   1.235 +	This class implements the behaviour for a Ptr parameter type.
   1.236 +	The ValidateL function reads the TAny* from the clients message and stores it for
   1.237 +	retrieval.
   1.238 +	@internalComponent
   1.239 +	*/
   1.240 +	NONSHARABLE_CLASS(CPtrParameter) : public CMessageParameterBase
   1.241 +	{
   1.242 +	public:
   1.243 +		static CMessageParameterBase* NewL(const TParameterDetails& aParam, TInt aParamIndex, 
   1.244 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.245 +		
   1.246 +		/**
   1.247 +		Destructor for CPtrParameter class.
   1.248 +		*/
   1.249 +		virtual ~CPtrParameter(){};
   1.250 +		virtual void ValidateL();
   1.251 +		virtual const TAny* GetPtrL();
   1.252 +		
   1.253 +	private:
   1.254 +	
   1.255 +		/**
   1.256 +		Constructor for CPtrParameter class.
   1.257 +		*/
   1.258 +		CPtrParameter(const TParameterDetails& aParam, TInt aParamIndex, 
   1.259 +				const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.260 +		
   1.261 +	private:
   1.262 +		//This stores the TAny* value read from the client message during validation
   1.263 +		const TAny* iValue;
   1.264 +	};
   1.265 +	
   1.266 +	/**
   1.267 +	This typedef is used to simplify the declaration of the message schema
   1.268 +	table defined by the server.
   1.269 +	@internalComponent
   1.270 +	*/
   1.271 +	typedef CMessageParameterBase* (*TMessageParameterFactoryFn)(const TParameterDetails& aParam, 
   1.272 +				TInt aParamIndex, const RMessage2& aMessage, TCustomValidationFn aValidationFn);
   1.273 +		
   1.274 +	}//namespace
   1.275 +
   1.276 +#endif