os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_clientmessage/testclientmessageschema.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_clientmessage/testclientmessageschema.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,261 @@
     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 +//
    1.18 +
    1.19 +#include <e32capability.h>
    1.20 +#include "t_clientmessagetestserver.h"
    1.21 +
    1.22 +using namespace BSUL;
    1.23 +
    1.24 +enum TCustomParamType
    1.25 +	{
    1.26 +	EParamCustom1 = (0x10000 | EParamPckg),
    1.27 +	EParamCustom2 = (0x20000 | EParamPckg),
    1.28 +	EParamCustom3 = (0x30000 | EParamInt),
    1.29 +	EParamCustom4 = (0x40000 | EParamDes16Read),
    1.30 +	EParamCustom5 = (0x90000 | EParamPckg)
    1.31 +	};
    1.32 +
    1.33 +
    1.34 +/* These are the parameter description sets for each message to be handled by the
    1.35 + * server. These descriptions provide the type of the parameter and constraints
    1.36 + * used to validate messages recieved from the client.  The particular validation
    1.37 + * requirements are defined in the appropriate CMessageParameterBase derived class
    1.38 + * and parameter objects are instantiated via the Parameter factory Lookup table.
    1.39 + */
    1.40 +//Integer parameter set
    1.41 +const TParameterDetails KMessage0Params[2] = {{EParamInt,-10,100},{EParamInt,0,200}};
    1.42 +
    1.43 +//These parameter sets are incorrectly defined. Attempts to call this message should
    1.44 +//panic the server.
    1.45 +const TParameterDetails KMessage2Params[1] = {{EParamInt,100,10}};
    1.46 +const TParameterDetails KMessage3Params[1] = {{EParamInt,-10,-20}};
    1.47 +
    1.48 +//Des*Read parameter sets
    1.49 +const TParameterDetails KMessage4Params[2] = {{EParamDes8Read,2,16},{EParamDes16Read,0,32}};
    1.50 +
    1.51 +//These parameter sets are incorrectly defined. Attempts to call this message should
    1.52 +//panic the server.
    1.53 +const TParameterDetails KMessage8Params[1] = {{EParamDes8Read,0,-16}};
    1.54 +
    1.55 +//Des* parameter sets
    1.56 +const TParameterDetails KMessage9Params[4] = {{EParamDes8,64,64},
    1.57 +												{EParamInt,0,64},
    1.58 +												{EParamDes16,128,128},
    1.59 +												{EParamInt,0,128}};
    1.60 +
    1.61 +const TParameterDetails KMessage11Params[4] = {{EParamDes8,64,64},
    1.62 +												{EParamInt,0,64},
    1.63 +												{EParamDes16,128,128},
    1.64 +												{EParamInt,0,128}};
    1.65 +
    1.66 +//These parameter sets are incorrectly defined. Attempts to call this message should
    1.67 +//panic the server.
    1.68 +const TParameterDetails KMessage12Params[1] = {{EParamDes8,-64,64}};
    1.69 +const TParameterDetails KMessage13Params[1] = {{EParamDes8,64,-64}};
    1.70 +
    1.71 +//Des parameter sets
    1.72 +const TParameterDetails KMessage14Params[3] = {{EParamDes8Read,0,16},
    1.73 +												{EParamInt,0,16},
    1.74 +												{EParamDes8,16,16}};
    1.75 +
    1.76 +const TParameterDetails KMessage15Params[3] = {{EParamDes16Read,0,64},
    1.77 +												{EParamInt,0,64},
    1.78 +												{EParamDes16,64,64}};
    1.79 +
    1.80 +//Ptr parameter sets
    1.81 +const TParameterDetails KMessage16Params[1] = {{EParamPtr,0,0}};
    1.82 +
    1.83 +
    1.84 +//Custom parameter sets
    1.85 +const TParameterDetails KMessage18Params[1] = {{EParamCustom1,sizeof(CMTestStruct2),sizeof(CMTestStruct2)}};
    1.86 +const TParameterDetails KMessage19Params[1] = {{EParamCustom2,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
    1.87 +
    1.88 +//Invalid parameter type
    1.89 +const TParameterDetails KMessage27Params[1] = {{453,0,0}};
    1.90 +
    1.91 +//standard param types with custom validation functions
    1.92 +//Custom parameter sets
    1.93 +const TParameterDetails KMessage28Params[1] = {{EParamCustom3,0,0}};
    1.94 +const TParameterDetails KMessage29Params[1] = {{EParamCustom4,0,32}};
    1.95 +
    1.96 +//Pkg parameter
    1.97 +const TParameterDetails KMessage30Params[1] = {{EParamPckg,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
    1.98 +
    1.99 +const TParameterDetails KMessage31Params[2] = {{EParamInt,EGetIntL,EWrite16L},{EParamPtr,0,0}};
   1.100 +
   1.101 +//Custom parameter type. EParamCustom5 is incorrectly defined as the validation function
   1.102 +//index is outside the range of the supplied validation fuction array
   1.103 +const TParameterDetails KMessage32Params[1] = {{EParamCustom5,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
   1.104 +
   1.105 +
   1.106 +
   1.107 +/* This Security Policy defines the requirements for a client to interact
   1.108 + * with the server. If a client sends a request to the server and doesnt
   1.109 + * meet the security policy, the request is denied with KErrAccessDenied.
   1.110 + * 
   1.111 + */
   1.112 +_LIT_SECURITY_POLICY_PASS(KDefaultPolicy);
   1.113 +_LIT_SECURITY_POLICY_FAIL(KFailPolicy);
   1.114 +_LIT_SECURITY_POLICY_S0(KSidPassPolicy,0x10285B57);
   1.115 +_LIT_SECURITY_POLICY_S0(KSidFailPolicy,0x12345678);
   1.116 +_LIT_SECURITY_POLICY_C2(KCapFailPolicy,ECapabilityReadUserData,ECapabilityPowerMgmt);
   1.117 +_LIT_SECURITY_POLICY_C2(KCapPassPolicy,ECapabilityReadUserData,ECapabilityWriteUserData);
   1.118 +
   1.119 +/* This is the array of messages that will be accepted by the server.  
   1.120 + * The messages are defined as follows:
   1.121 + *  	{Function Number, Number of Parameters, Parameter Descriptions}
   1.122 + * When loading the message objects, this table is traversed and so the most 
   1.123 + * frequently called messages should be first in the list to ensure the most
   1.124 + * efficient operation
   1.125 + */
   1.126 +const TClientMessageSchema KClientMessages[] = 
   1.127 +	{
   1.128 +	MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params),
   1.129 +	MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage0Params),
   1.130 +	MESSAGE_SCHEMA(ETestMessage2,KDefaultPolicy,KMessage2Params),
   1.131 +	MESSAGE_SCHEMA(ETestMessage3,KDefaultPolicy,KMessage3Params),
   1.132 +	MESSAGE_SCHEMA(ETestMessage4,KDefaultPolicy,KMessage4Params),
   1.133 +	MESSAGE_SCHEMA(ETestMessage5,KDefaultPolicy,KMessage4Params),
   1.134 +	MESSAGE_SCHEMA(ETestMessage6,KDefaultPolicy,KMessage4Params),
   1.135 +	MESSAGE_SCHEMA(ETestMessage7,KDefaultPolicy,KMessage4Params),
   1.136 +	MESSAGE_SCHEMA(ETestMessage8,KDefaultPolicy,KMessage8Params),											 
   1.137 +	MESSAGE_SCHEMA(ETestMessage9,KDefaultPolicy,KMessage9Params),
   1.138 +	MESSAGE_SCHEMA(ETestMessage10,KDefaultPolicy,KMessage9Params),
   1.139 +	MESSAGE_SCHEMA(ETestMessage11,KDefaultPolicy,KMessage11Params),
   1.140 +	MESSAGE_SCHEMA(ETestMessage12,KDefaultPolicy,KMessage12Params),
   1.141 +	MESSAGE_SCHEMA(ETestMessage13,KDefaultPolicy,KMessage13Params),
   1.142 +	MESSAGE_SCHEMA(ETestMessage14,KDefaultPolicy,KMessage14Params),
   1.143 +	MESSAGE_SCHEMA(ETestMessage15,KDefaultPolicy,KMessage15Params),
   1.144 +	MESSAGE_SCHEMA(ETestMessage16,KDefaultPolicy,KMessage16Params),
   1.145 +	MESSAGE_SCHEMA(ETestMessage17,KDefaultPolicy,KMessage16Params),
   1.146 +	MESSAGE_SCHEMA(ETestMessage18,KDefaultPolicy,KMessage18Params),
   1.147 +	MESSAGE_SCHEMA(ETestMessage19,KDefaultPolicy,KMessage19Params),
   1.148 +	MESSAGE_SCHEMA(ETestMessage20,KFailPolicy,KMessage0Params),
   1.149 +	MESSAGE_SCHEMA(ETestMessage21,KSidPassPolicy,KMessage0Params),
   1.150 +	MESSAGE_SCHEMA(ETestMessage22,KSidFailPolicy,KMessage0Params),
   1.151 +	MESSAGE_SCHEMA(ETestMessage23,KCapPassPolicy,KMessage0Params),
   1.152 +	MESSAGE_SCHEMA(ETestMessage24,KCapFailPolicy,KMessage0Params),
   1.153 +	MESSAGE_SCHEMA_NO_PARAMS(ETestMessage25,KDefaultPolicy),
   1.154 +	MESSAGE_SCHEMA(ETestMessage26,KDefaultPolicy,KNoParams),
   1.155 +	MESSAGE_SCHEMA(ETestMessage27,KDefaultPolicy,KMessage27Params),
   1.156 +	MESSAGE_SCHEMA(ETestMessage28,KDefaultPolicy,KMessage28Params),
   1.157 +	MESSAGE_SCHEMA(ETestMessage29,KDefaultPolicy,KMessage29Params),
   1.158 +	MESSAGE_SCHEMA(ETestMessage30,KDefaultPolicy,KMessage30Params),
   1.159 +	MESSAGE_SCHEMA(ETestMessage31,KDefaultPolicy,KMessage31Params),
   1.160 +	MESSAGE_SCHEMA(ETestMessage32,KDefaultPolicy,KMessage32Params)
   1.161 +	};
   1.162 +														 
   1.163 +static void ValidationFn1L(CMessageParameterBase* aParameter);
   1.164 +static void ValidationFn2L(CMessageParameterBase* aParameter);
   1.165 +static void ValidationFn3L(CMessageParameterBase* aParameter);
   1.166 +static void ValidationFn4L(CMessageParameterBase* aParameter);
   1.167 +
   1.168 +const TCustomValidationFn KCustomValidationFunctions[] = {NULL,
   1.169 +														&ValidationFn1L,
   1.170 +														&ValidationFn2L,
   1.171 +														&ValidationFn3L,
   1.172 +														&ValidationFn4L};
   1.173 +
   1.174 +extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages,
   1.175 +																KCustomValidationFunctions,
   1.176 +																"CMTestServer",
   1.177 +																ESrvFlagLogBadMessages);
   1.178 +
   1.179 +void ValidationFn1L(CMessageParameterBase* aParameter)
   1.180 +	{
   1.181 +	CMTestStruct2 struct1;
   1.182 +
   1.183 +	TPckg<CMTestStruct2> pData(struct1);
   1.184 +	
   1.185 +	if(aParameter->GetDesLengthL() != sizeof(CMTestStruct2))
   1.186 +		{
   1.187 +		User::Leave(KErrBadDescriptor);
   1.188 +		}
   1.189 +	
   1.190 +	aParameter->ReadL(pData,0);
   1.191 +	
   1.192 +	if((struct1.iEnum < ETestVal0)||(struct1.iEnum > ETestVal3))
   1.193 +		{
   1.194 +		User::Leave(KErrBadParameter);
   1.195 +		}
   1.196 +	
   1.197 +	if(struct1.iDes.Length() <= 0)
   1.198 +		{
   1.199 +		User::Leave(KErrBadParameter);
   1.200 +		}
   1.201 +	
   1.202 +	if(struct1.iCount < 0)
   1.203 +		{
   1.204 +		User::Leave(KErrBadParameter);
   1.205 +		}	
   1.206 +	}
   1.207 +
   1.208 +void ValidationFn2L(CMessageParameterBase* aParameter)
   1.209 +	{
   1.210 +	CMTestStruct1 struct1;
   1.211 +	TPckg<CMTestStruct1> pData(struct1);
   1.212 +	
   1.213 +	aParameter->ReadL(pData,0);
   1.214 +	
   1.215 +	if(struct1.iInt <= 0)
   1.216 +		{
   1.217 +		User::Leave(KErrBadParameter);
   1.218 +		}
   1.219 +	}
   1.220 +
   1.221 +void ValidationFn3L(CMessageParameterBase* aParameter)
   1.222 +	{
   1.223 +	
   1.224 +	TInt value = aParameter->GetIntL();
   1.225 +	
   1.226 +	if(value%4 != 0)
   1.227 +		{
   1.228 +		User::Leave(KErrBadParameter);
   1.229 +		}
   1.230 +
   1.231 +	}
   1.232 +
   1.233 +void ValidationFn4L(CMessageParameterBase* aParameter)
   1.234 +	{
   1.235 +	TBuf<32> data;
   1.236 +	
   1.237 +	aParameter->ReadL(data,0);
   1.238 +	
   1.239 +	if(data != _L("Expected Data"))
   1.240 +		{
   1.241 +		User::Leave(KErrBadParameter);
   1.242 +		}
   1.243 +	}
   1.244 +
   1.245 +
   1.246 +//parameter sets for server2
   1.247 +const TParameterDetails KMessage0Params2[2] = {{EParamInt,0,10},{EParamInt,-100,100}};
   1.248 +
   1.249 +/* Descriptor parameter for server2 */
   1.250 +const TParameterDetails KMessage1Params2[1] = {{EParamDes8Read,0,16}};
   1.251 +
   1.252 +/* This is the array of messages that will be accepted by the server.  
   1.253 + * The messages are defined as follows:
   1.254 + *  	{Function Number, Number of Parameters, Parameter Descriptions}
   1.255 + */
   1.256 +const TClientMessageSchema KClientMessages2[] = {MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params2),
   1.257 +												MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage1Params2)};
   1.258 +
   1.259 +const TCustomValidationFn KCustomValidationFunctions2[] = {NULL};
   1.260 +
   1.261 +extern const TClientMessageServerData KServer2Data = SERVER_DATA(KClientMessages2,
   1.262 +																KCustomValidationFunctions2,
   1.263 +																"CMTestServer2",
   1.264 +																(ESrvFlagLogBadMessages | ESrvFlagDoNotPanicClientOnBadMessageErrors));