os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_clientmessage/testclientmessageschema.cpp
Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <e32capability.h>
17 #include "t_clientmessagetestserver.h"
23 EParamCustom1 = (0x10000 | EParamPckg),
24 EParamCustom2 = (0x20000 | EParamPckg),
25 EParamCustom3 = (0x30000 | EParamInt),
26 EParamCustom4 = (0x40000 | EParamDes16Read),
27 EParamCustom5 = (0x90000 | EParamPckg)
31 /* These are the parameter description sets for each message to be handled by the
32 * server. These descriptions provide the type of the parameter and constraints
33 * used to validate messages recieved from the client. The particular validation
34 * requirements are defined in the appropriate CMessageParameterBase derived class
35 * and parameter objects are instantiated via the Parameter factory Lookup table.
37 //Integer parameter set
38 const TParameterDetails KMessage0Params[2] = {{EParamInt,-10,100},{EParamInt,0,200}};
40 //These parameter sets are incorrectly defined. Attempts to call this message should
42 const TParameterDetails KMessage2Params[1] = {{EParamInt,100,10}};
43 const TParameterDetails KMessage3Params[1] = {{EParamInt,-10,-20}};
45 //Des*Read parameter sets
46 const TParameterDetails KMessage4Params[2] = {{EParamDes8Read,2,16},{EParamDes16Read,0,32}};
48 //These parameter sets are incorrectly defined. Attempts to call this message should
50 const TParameterDetails KMessage8Params[1] = {{EParamDes8Read,0,-16}};
53 const TParameterDetails KMessage9Params[4] = {{EParamDes8,64,64},
55 {EParamDes16,128,128},
58 const TParameterDetails KMessage11Params[4] = {{EParamDes8,64,64},
60 {EParamDes16,128,128},
63 //These parameter sets are incorrectly defined. Attempts to call this message should
65 const TParameterDetails KMessage12Params[1] = {{EParamDes8,-64,64}};
66 const TParameterDetails KMessage13Params[1] = {{EParamDes8,64,-64}};
69 const TParameterDetails KMessage14Params[3] = {{EParamDes8Read,0,16},
73 const TParameterDetails KMessage15Params[3] = {{EParamDes16Read,0,64},
78 const TParameterDetails KMessage16Params[1] = {{EParamPtr,0,0}};
81 //Custom parameter sets
82 const TParameterDetails KMessage18Params[1] = {{EParamCustom1,sizeof(CMTestStruct2),sizeof(CMTestStruct2)}};
83 const TParameterDetails KMessage19Params[1] = {{EParamCustom2,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
85 //Invalid parameter type
86 const TParameterDetails KMessage27Params[1] = {{453,0,0}};
88 //standard param types with custom validation functions
89 //Custom parameter sets
90 const TParameterDetails KMessage28Params[1] = {{EParamCustom3,0,0}};
91 const TParameterDetails KMessage29Params[1] = {{EParamCustom4,0,32}};
94 const TParameterDetails KMessage30Params[1] = {{EParamPckg,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
96 const TParameterDetails KMessage31Params[2] = {{EParamInt,EGetIntL,EWrite16L},{EParamPtr,0,0}};
98 //Custom parameter type. EParamCustom5 is incorrectly defined as the validation function
99 //index is outside the range of the supplied validation fuction array
100 const TParameterDetails KMessage32Params[1] = {{EParamCustom5,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
104 /* This Security Policy defines the requirements for a client to interact
105 * with the server. If a client sends a request to the server and doesnt
106 * meet the security policy, the request is denied with KErrAccessDenied.
109 _LIT_SECURITY_POLICY_PASS(KDefaultPolicy);
110 _LIT_SECURITY_POLICY_FAIL(KFailPolicy);
111 _LIT_SECURITY_POLICY_S0(KSidPassPolicy,0x10285B57);
112 _LIT_SECURITY_POLICY_S0(KSidFailPolicy,0x12345678);
113 _LIT_SECURITY_POLICY_C2(KCapFailPolicy,ECapabilityReadUserData,ECapabilityPowerMgmt);
114 _LIT_SECURITY_POLICY_C2(KCapPassPolicy,ECapabilityReadUserData,ECapabilityWriteUserData);
116 /* This is the array of messages that will be accepted by the server.
117 * The messages are defined as follows:
118 * {Function Number, Number of Parameters, Parameter Descriptions}
119 * When loading the message objects, this table is traversed and so the most
120 * frequently called messages should be first in the list to ensure the most
121 * efficient operation
123 const TClientMessageSchema KClientMessages[] =
125 MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params),
126 MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage0Params),
127 MESSAGE_SCHEMA(ETestMessage2,KDefaultPolicy,KMessage2Params),
128 MESSAGE_SCHEMA(ETestMessage3,KDefaultPolicy,KMessage3Params),
129 MESSAGE_SCHEMA(ETestMessage4,KDefaultPolicy,KMessage4Params),
130 MESSAGE_SCHEMA(ETestMessage5,KDefaultPolicy,KMessage4Params),
131 MESSAGE_SCHEMA(ETestMessage6,KDefaultPolicy,KMessage4Params),
132 MESSAGE_SCHEMA(ETestMessage7,KDefaultPolicy,KMessage4Params),
133 MESSAGE_SCHEMA(ETestMessage8,KDefaultPolicy,KMessage8Params),
134 MESSAGE_SCHEMA(ETestMessage9,KDefaultPolicy,KMessage9Params),
135 MESSAGE_SCHEMA(ETestMessage10,KDefaultPolicy,KMessage9Params),
136 MESSAGE_SCHEMA(ETestMessage11,KDefaultPolicy,KMessage11Params),
137 MESSAGE_SCHEMA(ETestMessage12,KDefaultPolicy,KMessage12Params),
138 MESSAGE_SCHEMA(ETestMessage13,KDefaultPolicy,KMessage13Params),
139 MESSAGE_SCHEMA(ETestMessage14,KDefaultPolicy,KMessage14Params),
140 MESSAGE_SCHEMA(ETestMessage15,KDefaultPolicy,KMessage15Params),
141 MESSAGE_SCHEMA(ETestMessage16,KDefaultPolicy,KMessage16Params),
142 MESSAGE_SCHEMA(ETestMessage17,KDefaultPolicy,KMessage16Params),
143 MESSAGE_SCHEMA(ETestMessage18,KDefaultPolicy,KMessage18Params),
144 MESSAGE_SCHEMA(ETestMessage19,KDefaultPolicy,KMessage19Params),
145 MESSAGE_SCHEMA(ETestMessage20,KFailPolicy,KMessage0Params),
146 MESSAGE_SCHEMA(ETestMessage21,KSidPassPolicy,KMessage0Params),
147 MESSAGE_SCHEMA(ETestMessage22,KSidFailPolicy,KMessage0Params),
148 MESSAGE_SCHEMA(ETestMessage23,KCapPassPolicy,KMessage0Params),
149 MESSAGE_SCHEMA(ETestMessage24,KCapFailPolicy,KMessage0Params),
150 MESSAGE_SCHEMA_NO_PARAMS(ETestMessage25,KDefaultPolicy),
151 MESSAGE_SCHEMA(ETestMessage26,KDefaultPolicy,KNoParams),
152 MESSAGE_SCHEMA(ETestMessage27,KDefaultPolicy,KMessage27Params),
153 MESSAGE_SCHEMA(ETestMessage28,KDefaultPolicy,KMessage28Params),
154 MESSAGE_SCHEMA(ETestMessage29,KDefaultPolicy,KMessage29Params),
155 MESSAGE_SCHEMA(ETestMessage30,KDefaultPolicy,KMessage30Params),
156 MESSAGE_SCHEMA(ETestMessage31,KDefaultPolicy,KMessage31Params),
157 MESSAGE_SCHEMA(ETestMessage32,KDefaultPolicy,KMessage32Params)
160 static void ValidationFn1L(CMessageParameterBase* aParameter);
161 static void ValidationFn2L(CMessageParameterBase* aParameter);
162 static void ValidationFn3L(CMessageParameterBase* aParameter);
163 static void ValidationFn4L(CMessageParameterBase* aParameter);
165 const TCustomValidationFn KCustomValidationFunctions[] = {NULL,
171 extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages,
172 KCustomValidationFunctions,
174 ESrvFlagLogBadMessages);
176 void ValidationFn1L(CMessageParameterBase* aParameter)
178 CMTestStruct2 struct1;
180 TPckg<CMTestStruct2> pData(struct1);
182 if(aParameter->GetDesLengthL() != sizeof(CMTestStruct2))
184 User::Leave(KErrBadDescriptor);
187 aParameter->ReadL(pData,0);
189 if((struct1.iEnum < ETestVal0)||(struct1.iEnum > ETestVal3))
191 User::Leave(KErrBadParameter);
194 if(struct1.iDes.Length() <= 0)
196 User::Leave(KErrBadParameter);
199 if(struct1.iCount < 0)
201 User::Leave(KErrBadParameter);
205 void ValidationFn2L(CMessageParameterBase* aParameter)
207 CMTestStruct1 struct1;
208 TPckg<CMTestStruct1> pData(struct1);
210 aParameter->ReadL(pData,0);
212 if(struct1.iInt <= 0)
214 User::Leave(KErrBadParameter);
218 void ValidationFn3L(CMessageParameterBase* aParameter)
221 TInt value = aParameter->GetIntL();
225 User::Leave(KErrBadParameter);
230 void ValidationFn4L(CMessageParameterBase* aParameter)
234 aParameter->ReadL(data,0);
236 if(data != _L("Expected Data"))
238 User::Leave(KErrBadParameter);
243 //parameter sets for server2
244 const TParameterDetails KMessage0Params2[2] = {{EParamInt,0,10},{EParamInt,-100,100}};
246 /* Descriptor parameter for server2 */
247 const TParameterDetails KMessage1Params2[1] = {{EParamDes8Read,0,16}};
249 /* This is the array of messages that will be accepted by the server.
250 * The messages are defined as follows:
251 * {Function Number, Number of Parameters, Parameter Descriptions}
253 const TClientMessageSchema KClientMessages2[] = {MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params2),
254 MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage1Params2)};
256 const TCustomValidationFn KCustomValidationFunctions2[] = {NULL};
258 extern const TClientMessageServerData KServer2Data = SERVER_DATA(KClientMessages2,
259 KCustomValidationFunctions2,
261 (ESrvFlagLogBadMessages | ESrvFlagDoNotPanicClientOnBadMessageErrors));