sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "t_clientmessagetestserver.h" sl@0: sl@0: using namespace BSUL; sl@0: sl@0: enum TCustomParamType sl@0: { sl@0: EParamCustom1 = (0x10000 | EParamPckg), sl@0: EParamCustom2 = (0x20000 | EParamPckg), sl@0: EParamCustom3 = (0x30000 | EParamInt), sl@0: EParamCustom4 = (0x40000 | EParamDes16Read), sl@0: EParamCustom5 = (0x90000 | EParamPckg) sl@0: }; sl@0: sl@0: sl@0: /* These are the parameter description sets for each message to be handled by the sl@0: * server. These descriptions provide the type of the parameter and constraints sl@0: * used to validate messages recieved from the client. The particular validation sl@0: * requirements are defined in the appropriate CMessageParameterBase derived class sl@0: * and parameter objects are instantiated via the Parameter factory Lookup table. sl@0: */ sl@0: //Integer parameter set sl@0: const TParameterDetails KMessage0Params[2] = {{EParamInt,-10,100},{EParamInt,0,200}}; sl@0: sl@0: //These parameter sets are incorrectly defined. Attempts to call this message should sl@0: //panic the server. sl@0: const TParameterDetails KMessage2Params[1] = {{EParamInt,100,10}}; sl@0: const TParameterDetails KMessage3Params[1] = {{EParamInt,-10,-20}}; sl@0: sl@0: //Des*Read parameter sets sl@0: const TParameterDetails KMessage4Params[2] = {{EParamDes8Read,2,16},{EParamDes16Read,0,32}}; sl@0: sl@0: //These parameter sets are incorrectly defined. Attempts to call this message should sl@0: //panic the server. sl@0: const TParameterDetails KMessage8Params[1] = {{EParamDes8Read,0,-16}}; sl@0: sl@0: //Des* parameter sets sl@0: const TParameterDetails KMessage9Params[4] = {{EParamDes8,64,64}, sl@0: {EParamInt,0,64}, sl@0: {EParamDes16,128,128}, sl@0: {EParamInt,0,128}}; sl@0: sl@0: const TParameterDetails KMessage11Params[4] = {{EParamDes8,64,64}, sl@0: {EParamInt,0,64}, sl@0: {EParamDes16,128,128}, sl@0: {EParamInt,0,128}}; sl@0: sl@0: //These parameter sets are incorrectly defined. Attempts to call this message should sl@0: //panic the server. sl@0: const TParameterDetails KMessage12Params[1] = {{EParamDes8,-64,64}}; sl@0: const TParameterDetails KMessage13Params[1] = {{EParamDes8,64,-64}}; sl@0: sl@0: //Des parameter sets sl@0: const TParameterDetails KMessage14Params[3] = {{EParamDes8Read,0,16}, sl@0: {EParamInt,0,16}, sl@0: {EParamDes8,16,16}}; sl@0: sl@0: const TParameterDetails KMessage15Params[3] = {{EParamDes16Read,0,64}, sl@0: {EParamInt,0,64}, sl@0: {EParamDes16,64,64}}; sl@0: sl@0: //Ptr parameter sets sl@0: const TParameterDetails KMessage16Params[1] = {{EParamPtr,0,0}}; sl@0: sl@0: sl@0: //Custom parameter sets sl@0: const TParameterDetails KMessage18Params[1] = {{EParamCustom1,sizeof(CMTestStruct2),sizeof(CMTestStruct2)}}; sl@0: const TParameterDetails KMessage19Params[1] = {{EParamCustom2,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}}; sl@0: sl@0: //Invalid parameter type sl@0: const TParameterDetails KMessage27Params[1] = {{453,0,0}}; sl@0: sl@0: //standard param types with custom validation functions sl@0: //Custom parameter sets sl@0: const TParameterDetails KMessage28Params[1] = {{EParamCustom3,0,0}}; sl@0: const TParameterDetails KMessage29Params[1] = {{EParamCustom4,0,32}}; sl@0: sl@0: //Pkg parameter sl@0: const TParameterDetails KMessage30Params[1] = {{EParamPckg,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}}; sl@0: sl@0: const TParameterDetails KMessage31Params[2] = {{EParamInt,EGetIntL,EWrite16L},{EParamPtr,0,0}}; sl@0: sl@0: //Custom parameter type. EParamCustom5 is incorrectly defined as the validation function sl@0: //index is outside the range of the supplied validation fuction array sl@0: const TParameterDetails KMessage32Params[1] = {{EParamCustom5,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}}; sl@0: sl@0: sl@0: sl@0: /* This Security Policy defines the requirements for a client to interact sl@0: * with the server. If a client sends a request to the server and doesnt sl@0: * meet the security policy, the request is denied with KErrAccessDenied. sl@0: * sl@0: */ sl@0: _LIT_SECURITY_POLICY_PASS(KDefaultPolicy); sl@0: _LIT_SECURITY_POLICY_FAIL(KFailPolicy); sl@0: _LIT_SECURITY_POLICY_S0(KSidPassPolicy,0x10285B57); sl@0: _LIT_SECURITY_POLICY_S0(KSidFailPolicy,0x12345678); sl@0: _LIT_SECURITY_POLICY_C2(KCapFailPolicy,ECapabilityReadUserData,ECapabilityPowerMgmt); sl@0: _LIT_SECURITY_POLICY_C2(KCapPassPolicy,ECapabilityReadUserData,ECapabilityWriteUserData); sl@0: sl@0: /* This is the array of messages that will be accepted by the server. sl@0: * The messages are defined as follows: sl@0: * {Function Number, Number of Parameters, Parameter Descriptions} sl@0: * When loading the message objects, this table is traversed and so the most sl@0: * frequently called messages should be first in the list to ensure the most sl@0: * efficient operation sl@0: */ sl@0: const TClientMessageSchema KClientMessages[] = sl@0: { sl@0: MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage2,KDefaultPolicy,KMessage2Params), sl@0: MESSAGE_SCHEMA(ETestMessage3,KDefaultPolicy,KMessage3Params), sl@0: MESSAGE_SCHEMA(ETestMessage4,KDefaultPolicy,KMessage4Params), sl@0: MESSAGE_SCHEMA(ETestMessage5,KDefaultPolicy,KMessage4Params), sl@0: MESSAGE_SCHEMA(ETestMessage6,KDefaultPolicy,KMessage4Params), sl@0: MESSAGE_SCHEMA(ETestMessage7,KDefaultPolicy,KMessage4Params), sl@0: MESSAGE_SCHEMA(ETestMessage8,KDefaultPolicy,KMessage8Params), sl@0: MESSAGE_SCHEMA(ETestMessage9,KDefaultPolicy,KMessage9Params), sl@0: MESSAGE_SCHEMA(ETestMessage10,KDefaultPolicy,KMessage9Params), sl@0: MESSAGE_SCHEMA(ETestMessage11,KDefaultPolicy,KMessage11Params), sl@0: MESSAGE_SCHEMA(ETestMessage12,KDefaultPolicy,KMessage12Params), sl@0: MESSAGE_SCHEMA(ETestMessage13,KDefaultPolicy,KMessage13Params), sl@0: MESSAGE_SCHEMA(ETestMessage14,KDefaultPolicy,KMessage14Params), sl@0: MESSAGE_SCHEMA(ETestMessage15,KDefaultPolicy,KMessage15Params), sl@0: MESSAGE_SCHEMA(ETestMessage16,KDefaultPolicy,KMessage16Params), sl@0: MESSAGE_SCHEMA(ETestMessage17,KDefaultPolicy,KMessage16Params), sl@0: MESSAGE_SCHEMA(ETestMessage18,KDefaultPolicy,KMessage18Params), sl@0: MESSAGE_SCHEMA(ETestMessage19,KDefaultPolicy,KMessage19Params), sl@0: MESSAGE_SCHEMA(ETestMessage20,KFailPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage21,KSidPassPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage22,KSidFailPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage23,KCapPassPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA(ETestMessage24,KCapFailPolicy,KMessage0Params), sl@0: MESSAGE_SCHEMA_NO_PARAMS(ETestMessage25,KDefaultPolicy), sl@0: MESSAGE_SCHEMA(ETestMessage26,KDefaultPolicy,KNoParams), sl@0: MESSAGE_SCHEMA(ETestMessage27,KDefaultPolicy,KMessage27Params), sl@0: MESSAGE_SCHEMA(ETestMessage28,KDefaultPolicy,KMessage28Params), sl@0: MESSAGE_SCHEMA(ETestMessage29,KDefaultPolicy,KMessage29Params), sl@0: MESSAGE_SCHEMA(ETestMessage30,KDefaultPolicy,KMessage30Params), sl@0: MESSAGE_SCHEMA(ETestMessage31,KDefaultPolicy,KMessage31Params), sl@0: MESSAGE_SCHEMA(ETestMessage32,KDefaultPolicy,KMessage32Params) sl@0: }; sl@0: sl@0: static void ValidationFn1L(CMessageParameterBase* aParameter); sl@0: static void ValidationFn2L(CMessageParameterBase* aParameter); sl@0: static void ValidationFn3L(CMessageParameterBase* aParameter); sl@0: static void ValidationFn4L(CMessageParameterBase* aParameter); sl@0: sl@0: const TCustomValidationFn KCustomValidationFunctions[] = {NULL, sl@0: &ValidationFn1L, sl@0: &ValidationFn2L, sl@0: &ValidationFn3L, sl@0: &ValidationFn4L}; sl@0: sl@0: extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages, sl@0: KCustomValidationFunctions, sl@0: "CMTestServer", sl@0: ESrvFlagLogBadMessages); sl@0: sl@0: void ValidationFn1L(CMessageParameterBase* aParameter) sl@0: { sl@0: CMTestStruct2 struct1; sl@0: sl@0: TPckg pData(struct1); sl@0: sl@0: if(aParameter->GetDesLengthL() != sizeof(CMTestStruct2)) sl@0: { sl@0: User::Leave(KErrBadDescriptor); sl@0: } sl@0: sl@0: aParameter->ReadL(pData,0); sl@0: sl@0: if((struct1.iEnum < ETestVal0)||(struct1.iEnum > ETestVal3)) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: sl@0: if(struct1.iDes.Length() <= 0) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: sl@0: if(struct1.iCount < 0) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: } sl@0: sl@0: void ValidationFn2L(CMessageParameterBase* aParameter) sl@0: { sl@0: CMTestStruct1 struct1; sl@0: TPckg pData(struct1); sl@0: sl@0: aParameter->ReadL(pData,0); sl@0: sl@0: if(struct1.iInt <= 0) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: } sl@0: sl@0: void ValidationFn3L(CMessageParameterBase* aParameter) sl@0: { sl@0: sl@0: TInt value = aParameter->GetIntL(); sl@0: sl@0: if(value%4 != 0) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: sl@0: } sl@0: sl@0: void ValidationFn4L(CMessageParameterBase* aParameter) sl@0: { sl@0: TBuf<32> data; sl@0: sl@0: aParameter->ReadL(data,0); sl@0: sl@0: if(data != _L("Expected Data")) sl@0: { sl@0: User::Leave(KErrBadParameter); sl@0: } sl@0: } sl@0: sl@0: sl@0: //parameter sets for server2 sl@0: const TParameterDetails KMessage0Params2[2] = {{EParamInt,0,10},{EParamInt,-100,100}}; sl@0: sl@0: /* Descriptor parameter for server2 */ sl@0: const TParameterDetails KMessage1Params2[1] = {{EParamDes8Read,0,16}}; sl@0: sl@0: /* This is the array of messages that will be accepted by the server. sl@0: * The messages are defined as follows: sl@0: * {Function Number, Number of Parameters, Parameter Descriptions} sl@0: */ sl@0: const TClientMessageSchema KClientMessages2[] = {MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params2), sl@0: MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage1Params2)}; sl@0: sl@0: const TCustomValidationFn KCustomValidationFunctions2[] = {NULL}; sl@0: sl@0: extern const TClientMessageServerData KServer2Data = SERVER_DATA(KClientMessages2, sl@0: KCustomValidationFunctions2, sl@0: "CMTestServer2", sl@0: (ESrvFlagLogBadMessages | ESrvFlagDoNotPanicClientOnBadMessageErrors));