sl@0
|
1 |
// Copyright (c) 2008-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 |
#include <e32capability.h>
|
sl@0
|
17 |
#include "t_clientmessagetestserver.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
using namespace BSUL;
|
sl@0
|
20 |
|
sl@0
|
21 |
enum TCustomParamType
|
sl@0
|
22 |
{
|
sl@0
|
23 |
EParamCustom1 = (0x10000 | EParamPckg),
|
sl@0
|
24 |
EParamCustom2 = (0x20000 | EParamPckg),
|
sl@0
|
25 |
EParamCustom3 = (0x30000 | EParamInt),
|
sl@0
|
26 |
EParamCustom4 = (0x40000 | EParamDes16Read),
|
sl@0
|
27 |
EParamCustom5 = (0x90000 | EParamPckg)
|
sl@0
|
28 |
};
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
/* These are the parameter description sets for each message to be handled by the
|
sl@0
|
32 |
* server. These descriptions provide the type of the parameter and constraints
|
sl@0
|
33 |
* used to validate messages recieved from the client. The particular validation
|
sl@0
|
34 |
* requirements are defined in the appropriate CMessageParameterBase derived class
|
sl@0
|
35 |
* and parameter objects are instantiated via the Parameter factory Lookup table.
|
sl@0
|
36 |
*/
|
sl@0
|
37 |
//Integer parameter set
|
sl@0
|
38 |
const TParameterDetails KMessage0Params[2] = {{EParamInt,-10,100},{EParamInt,0,200}};
|
sl@0
|
39 |
|
sl@0
|
40 |
//These parameter sets are incorrectly defined. Attempts to call this message should
|
sl@0
|
41 |
//panic the server.
|
sl@0
|
42 |
const TParameterDetails KMessage2Params[1] = {{EParamInt,100,10}};
|
sl@0
|
43 |
const TParameterDetails KMessage3Params[1] = {{EParamInt,-10,-20}};
|
sl@0
|
44 |
|
sl@0
|
45 |
//Des*Read parameter sets
|
sl@0
|
46 |
const TParameterDetails KMessage4Params[2] = {{EParamDes8Read,2,16},{EParamDes16Read,0,32}};
|
sl@0
|
47 |
|
sl@0
|
48 |
//These parameter sets are incorrectly defined. Attempts to call this message should
|
sl@0
|
49 |
//panic the server.
|
sl@0
|
50 |
const TParameterDetails KMessage8Params[1] = {{EParamDes8Read,0,-16}};
|
sl@0
|
51 |
|
sl@0
|
52 |
//Des* parameter sets
|
sl@0
|
53 |
const TParameterDetails KMessage9Params[4] = {{EParamDes8,64,64},
|
sl@0
|
54 |
{EParamInt,0,64},
|
sl@0
|
55 |
{EParamDes16,128,128},
|
sl@0
|
56 |
{EParamInt,0,128}};
|
sl@0
|
57 |
|
sl@0
|
58 |
const TParameterDetails KMessage11Params[4] = {{EParamDes8,64,64},
|
sl@0
|
59 |
{EParamInt,0,64},
|
sl@0
|
60 |
{EParamDes16,128,128},
|
sl@0
|
61 |
{EParamInt,0,128}};
|
sl@0
|
62 |
|
sl@0
|
63 |
//These parameter sets are incorrectly defined. Attempts to call this message should
|
sl@0
|
64 |
//panic the server.
|
sl@0
|
65 |
const TParameterDetails KMessage12Params[1] = {{EParamDes8,-64,64}};
|
sl@0
|
66 |
const TParameterDetails KMessage13Params[1] = {{EParamDes8,64,-64}};
|
sl@0
|
67 |
|
sl@0
|
68 |
//Des parameter sets
|
sl@0
|
69 |
const TParameterDetails KMessage14Params[3] = {{EParamDes8Read,0,16},
|
sl@0
|
70 |
{EParamInt,0,16},
|
sl@0
|
71 |
{EParamDes8,16,16}};
|
sl@0
|
72 |
|
sl@0
|
73 |
const TParameterDetails KMessage15Params[3] = {{EParamDes16Read,0,64},
|
sl@0
|
74 |
{EParamInt,0,64},
|
sl@0
|
75 |
{EParamDes16,64,64}};
|
sl@0
|
76 |
|
sl@0
|
77 |
//Ptr parameter sets
|
sl@0
|
78 |
const TParameterDetails KMessage16Params[1] = {{EParamPtr,0,0}};
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
//Custom parameter sets
|
sl@0
|
82 |
const TParameterDetails KMessage18Params[1] = {{EParamCustom1,sizeof(CMTestStruct2),sizeof(CMTestStruct2)}};
|
sl@0
|
83 |
const TParameterDetails KMessage19Params[1] = {{EParamCustom2,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
|
sl@0
|
84 |
|
sl@0
|
85 |
//Invalid parameter type
|
sl@0
|
86 |
const TParameterDetails KMessage27Params[1] = {{453,0,0}};
|
sl@0
|
87 |
|
sl@0
|
88 |
//standard param types with custom validation functions
|
sl@0
|
89 |
//Custom parameter sets
|
sl@0
|
90 |
const TParameterDetails KMessage28Params[1] = {{EParamCustom3,0,0}};
|
sl@0
|
91 |
const TParameterDetails KMessage29Params[1] = {{EParamCustom4,0,32}};
|
sl@0
|
92 |
|
sl@0
|
93 |
//Pkg parameter
|
sl@0
|
94 |
const TParameterDetails KMessage30Params[1] = {{EParamPckg,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
|
sl@0
|
95 |
|
sl@0
|
96 |
const TParameterDetails KMessage31Params[2] = {{EParamInt,EGetIntL,EWrite16L},{EParamPtr,0,0}};
|
sl@0
|
97 |
|
sl@0
|
98 |
//Custom parameter type. EParamCustom5 is incorrectly defined as the validation function
|
sl@0
|
99 |
//index is outside the range of the supplied validation fuction array
|
sl@0
|
100 |
const TParameterDetails KMessage32Params[1] = {{EParamCustom5,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
|
sl@0
|
104 |
/* This Security Policy defines the requirements for a client to interact
|
sl@0
|
105 |
* with the server. If a client sends a request to the server and doesnt
|
sl@0
|
106 |
* meet the security policy, the request is denied with KErrAccessDenied.
|
sl@0
|
107 |
*
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
_LIT_SECURITY_POLICY_PASS(KDefaultPolicy);
|
sl@0
|
110 |
_LIT_SECURITY_POLICY_FAIL(KFailPolicy);
|
sl@0
|
111 |
_LIT_SECURITY_POLICY_S0(KSidPassPolicy,0x10285B57);
|
sl@0
|
112 |
_LIT_SECURITY_POLICY_S0(KSidFailPolicy,0x12345678);
|
sl@0
|
113 |
_LIT_SECURITY_POLICY_C2(KCapFailPolicy,ECapabilityReadUserData,ECapabilityPowerMgmt);
|
sl@0
|
114 |
_LIT_SECURITY_POLICY_C2(KCapPassPolicy,ECapabilityReadUserData,ECapabilityWriteUserData);
|
sl@0
|
115 |
|
sl@0
|
116 |
/* This is the array of messages that will be accepted by the server.
|
sl@0
|
117 |
* The messages are defined as follows:
|
sl@0
|
118 |
* {Function Number, Number of Parameters, Parameter Descriptions}
|
sl@0
|
119 |
* When loading the message objects, this table is traversed and so the most
|
sl@0
|
120 |
* frequently called messages should be first in the list to ensure the most
|
sl@0
|
121 |
* efficient operation
|
sl@0
|
122 |
*/
|
sl@0
|
123 |
const TClientMessageSchema KClientMessages[] =
|
sl@0
|
124 |
{
|
sl@0
|
125 |
MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params),
|
sl@0
|
126 |
MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage0Params),
|
sl@0
|
127 |
MESSAGE_SCHEMA(ETestMessage2,KDefaultPolicy,KMessage2Params),
|
sl@0
|
128 |
MESSAGE_SCHEMA(ETestMessage3,KDefaultPolicy,KMessage3Params),
|
sl@0
|
129 |
MESSAGE_SCHEMA(ETestMessage4,KDefaultPolicy,KMessage4Params),
|
sl@0
|
130 |
MESSAGE_SCHEMA(ETestMessage5,KDefaultPolicy,KMessage4Params),
|
sl@0
|
131 |
MESSAGE_SCHEMA(ETestMessage6,KDefaultPolicy,KMessage4Params),
|
sl@0
|
132 |
MESSAGE_SCHEMA(ETestMessage7,KDefaultPolicy,KMessage4Params),
|
sl@0
|
133 |
MESSAGE_SCHEMA(ETestMessage8,KDefaultPolicy,KMessage8Params),
|
sl@0
|
134 |
MESSAGE_SCHEMA(ETestMessage9,KDefaultPolicy,KMessage9Params),
|
sl@0
|
135 |
MESSAGE_SCHEMA(ETestMessage10,KDefaultPolicy,KMessage9Params),
|
sl@0
|
136 |
MESSAGE_SCHEMA(ETestMessage11,KDefaultPolicy,KMessage11Params),
|
sl@0
|
137 |
MESSAGE_SCHEMA(ETestMessage12,KDefaultPolicy,KMessage12Params),
|
sl@0
|
138 |
MESSAGE_SCHEMA(ETestMessage13,KDefaultPolicy,KMessage13Params),
|
sl@0
|
139 |
MESSAGE_SCHEMA(ETestMessage14,KDefaultPolicy,KMessage14Params),
|
sl@0
|
140 |
MESSAGE_SCHEMA(ETestMessage15,KDefaultPolicy,KMessage15Params),
|
sl@0
|
141 |
MESSAGE_SCHEMA(ETestMessage16,KDefaultPolicy,KMessage16Params),
|
sl@0
|
142 |
MESSAGE_SCHEMA(ETestMessage17,KDefaultPolicy,KMessage16Params),
|
sl@0
|
143 |
MESSAGE_SCHEMA(ETestMessage18,KDefaultPolicy,KMessage18Params),
|
sl@0
|
144 |
MESSAGE_SCHEMA(ETestMessage19,KDefaultPolicy,KMessage19Params),
|
sl@0
|
145 |
MESSAGE_SCHEMA(ETestMessage20,KFailPolicy,KMessage0Params),
|
sl@0
|
146 |
MESSAGE_SCHEMA(ETestMessage21,KSidPassPolicy,KMessage0Params),
|
sl@0
|
147 |
MESSAGE_SCHEMA(ETestMessage22,KSidFailPolicy,KMessage0Params),
|
sl@0
|
148 |
MESSAGE_SCHEMA(ETestMessage23,KCapPassPolicy,KMessage0Params),
|
sl@0
|
149 |
MESSAGE_SCHEMA(ETestMessage24,KCapFailPolicy,KMessage0Params),
|
sl@0
|
150 |
MESSAGE_SCHEMA_NO_PARAMS(ETestMessage25,KDefaultPolicy),
|
sl@0
|
151 |
MESSAGE_SCHEMA(ETestMessage26,KDefaultPolicy,KNoParams),
|
sl@0
|
152 |
MESSAGE_SCHEMA(ETestMessage27,KDefaultPolicy,KMessage27Params),
|
sl@0
|
153 |
MESSAGE_SCHEMA(ETestMessage28,KDefaultPolicy,KMessage28Params),
|
sl@0
|
154 |
MESSAGE_SCHEMA(ETestMessage29,KDefaultPolicy,KMessage29Params),
|
sl@0
|
155 |
MESSAGE_SCHEMA(ETestMessage30,KDefaultPolicy,KMessage30Params),
|
sl@0
|
156 |
MESSAGE_SCHEMA(ETestMessage31,KDefaultPolicy,KMessage31Params),
|
sl@0
|
157 |
MESSAGE_SCHEMA(ETestMessage32,KDefaultPolicy,KMessage32Params)
|
sl@0
|
158 |
};
|
sl@0
|
159 |
|
sl@0
|
160 |
static void ValidationFn1L(CMessageParameterBase* aParameter);
|
sl@0
|
161 |
static void ValidationFn2L(CMessageParameterBase* aParameter);
|
sl@0
|
162 |
static void ValidationFn3L(CMessageParameterBase* aParameter);
|
sl@0
|
163 |
static void ValidationFn4L(CMessageParameterBase* aParameter);
|
sl@0
|
164 |
|
sl@0
|
165 |
const TCustomValidationFn KCustomValidationFunctions[] = {NULL,
|
sl@0
|
166 |
&ValidationFn1L,
|
sl@0
|
167 |
&ValidationFn2L,
|
sl@0
|
168 |
&ValidationFn3L,
|
sl@0
|
169 |
&ValidationFn4L};
|
sl@0
|
170 |
|
sl@0
|
171 |
extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages,
|
sl@0
|
172 |
KCustomValidationFunctions,
|
sl@0
|
173 |
"CMTestServer",
|
sl@0
|
174 |
ESrvFlagLogBadMessages);
|
sl@0
|
175 |
|
sl@0
|
176 |
void ValidationFn1L(CMessageParameterBase* aParameter)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
CMTestStruct2 struct1;
|
sl@0
|
179 |
|
sl@0
|
180 |
TPckg<CMTestStruct2> pData(struct1);
|
sl@0
|
181 |
|
sl@0
|
182 |
if(aParameter->GetDesLengthL() != sizeof(CMTestStruct2))
|
sl@0
|
183 |
{
|
sl@0
|
184 |
User::Leave(KErrBadDescriptor);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
aParameter->ReadL(pData,0);
|
sl@0
|
188 |
|
sl@0
|
189 |
if((struct1.iEnum < ETestVal0)||(struct1.iEnum > ETestVal3))
|
sl@0
|
190 |
{
|
sl@0
|
191 |
User::Leave(KErrBadParameter);
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
if(struct1.iDes.Length() <= 0)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
User::Leave(KErrBadParameter);
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
if(struct1.iCount < 0)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
User::Leave(KErrBadParameter);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
void ValidationFn2L(CMessageParameterBase* aParameter)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
CMTestStruct1 struct1;
|
sl@0
|
208 |
TPckg<CMTestStruct1> pData(struct1);
|
sl@0
|
209 |
|
sl@0
|
210 |
aParameter->ReadL(pData,0);
|
sl@0
|
211 |
|
sl@0
|
212 |
if(struct1.iInt <= 0)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
User::Leave(KErrBadParameter);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
void ValidationFn3L(CMessageParameterBase* aParameter)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
|
sl@0
|
221 |
TInt value = aParameter->GetIntL();
|
sl@0
|
222 |
|
sl@0
|
223 |
if(value%4 != 0)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
User::Leave(KErrBadParameter);
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
void ValidationFn4L(CMessageParameterBase* aParameter)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
TBuf<32> data;
|
sl@0
|
233 |
|
sl@0
|
234 |
aParameter->ReadL(data,0);
|
sl@0
|
235 |
|
sl@0
|
236 |
if(data != _L("Expected Data"))
|
sl@0
|
237 |
{
|
sl@0
|
238 |
User::Leave(KErrBadParameter);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
|
sl@0
|
243 |
//parameter sets for server2
|
sl@0
|
244 |
const TParameterDetails KMessage0Params2[2] = {{EParamInt,0,10},{EParamInt,-100,100}};
|
sl@0
|
245 |
|
sl@0
|
246 |
/* Descriptor parameter for server2 */
|
sl@0
|
247 |
const TParameterDetails KMessage1Params2[1] = {{EParamDes8Read,0,16}};
|
sl@0
|
248 |
|
sl@0
|
249 |
/* This is the array of messages that will be accepted by the server.
|
sl@0
|
250 |
* The messages are defined as follows:
|
sl@0
|
251 |
* {Function Number, Number of Parameters, Parameter Descriptions}
|
sl@0
|
252 |
*/
|
sl@0
|
253 |
const TClientMessageSchema KClientMessages2[] = {MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params2),
|
sl@0
|
254 |
MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage1Params2)};
|
sl@0
|
255 |
|
sl@0
|
256 |
const TCustomValidationFn KCustomValidationFunctions2[] = {NULL};
|
sl@0
|
257 |
|
sl@0
|
258 |
extern const TClientMessageServerData KServer2Data = SERVER_DATA(KClientMessages2,
|
sl@0
|
259 |
KCustomValidationFunctions2,
|
sl@0
|
260 |
"CMTestServer2",
|
sl@0
|
261 |
(ESrvFlagLogBadMessages | ESrvFlagDoNotPanicClientOnBadMessageErrors));
|