|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <bsul/bsul.h> |
|
17 #include "CSCHCODE.H" |
|
18 #include "SCHINFO.H" |
|
19 |
|
20 using namespace BSUL; |
|
21 |
|
22 /** |
|
23 Intended Usage : This Enum lists the currently supported Custom Parameter types. |
|
24 The lower 16 bits of these enum values are used as indices to the |
|
25 Parameter Factory Function which instantiates the appropriate |
|
26 CMessageParammeterBase derived object to represent a given message parameter. |
|
27 The upper 16 bits of these values are used as the index in the array |
|
28 of custom validation functions. If the upper 16bits are set to 0, the default |
|
29 validation is used. |
|
30 */ |
|
31 enum TCustomParamType |
|
32 { |
|
33 EParamTScheduleSettings2 = (0x10000 | EParamPckg), |
|
34 EParamTTsTime = (0x20000 | EParamPckg), |
|
35 EParamTTaskInfo = (0x30000 | EParamPckg), |
|
36 EParamTScheduleInfo = (0x40000 | EParamPckg), |
|
37 EParamTSchedulerItemRef = (0x50000 | EParamPckg) |
|
38 }; |
|
39 |
|
40 /* These are the parameter description sets for each message to be handled by the |
|
41 * server. These descriptions provide the type of the parameter and constraints |
|
42 * used to validate messages recieved from the client. The particular validation |
|
43 * requirements are defined in the appropriate CMessageParameterBase derived class |
|
44 * and parameter objects are instantiated via the Parameter factory Lookup table. |
|
45 */ |
|
46 const TInt KMaxInt32 = 0x7FFFFFFF; |
|
47 const TInt KMinInt32 = 0x80000000; |
|
48 const TInt KMaxTDes8 = 0x0FFFFFFF; |
|
49 const TInt KMaxSchedules = 25000;//Max of 25000 schedules |
|
50 const TInt KMaxScheduleId = (10000 * (KMaxSchedules - 1));//Schedule IDs have an offset of 10000 |
|
51 const TInt KMaxTasks = 9999;//Max of 9999 tasks per schedule |
|
52 const TInt KMaxTaskId = (KMaxScheduleId + KMaxTasks); |
|
53 |
|
54 const TParameterDetails KIntParam[] = {EParamInt,KMinInt32,KMaxInt32}; |
|
55 |
|
56 |
|
57 const TParameterDetails KRegisterClientParam[] = {{EParamDes16Read,0,KMaxFileName}, |
|
58 {EParamInt,0,KMaxInt32}}; |
|
59 |
|
60 const TParameterDetails KCreateTimeSchedParam[] = {{EParamTScheduleSettings2,sizeof(TScheduleSettings2),sizeof(TScheduleSettings2)}, |
|
61 {EParamDes8Read,0,KMaxTDes8}, |
|
62 {EParamPckg,sizeof(TInt),sizeof(TInt)}}; |
|
63 |
|
64 const TParameterDetails KCreateCondSchedParam[] = {{EParamTScheduleSettings2,sizeof(TScheduleSettings2),sizeof(TScheduleSettings2)}, |
|
65 {EParamDes8Read,0,KMaxTDes8}, |
|
66 {EParamTTsTime, sizeof(TTsTime), sizeof(TTsTime)}, |
|
67 {EParamPckg,sizeof(TInt),sizeof(TInt)}}; |
|
68 |
|
69 const TParameterDetails KScheduleTaskParam[] = {{EParamTTaskInfo,sizeof(TTaskInfo),sizeof(TTaskInfo)}, |
|
70 {EParamInt,0,KMaxScheduleId}, |
|
71 {EParamPckg,sizeof(TInt),sizeof(TInt)}, |
|
72 {EParamDes16,0,KMaxTDes8}}; |
|
73 |
|
74 const TParameterDetails KScheduleIdParam[] = {EParamInt,0,KMaxScheduleId}; |
|
75 |
|
76 const TParameterDetails KEditTimeSchedParam[] = {{EParamInt,0,KMaxTasks}, |
|
77 {EParamInt,0,KMaxScheduleId}, |
|
78 {EParamDes8Read,0,KMaxTDes8}}; |
|
79 |
|
80 const TParameterDetails KEditCondSchedParam[] = {{EParamInt,0,KMaxTasks}, |
|
81 {EParamInt,0,KMaxScheduleId}, |
|
82 {EParamDes8Read,0,KMaxTDes8}, |
|
83 {EParamTTsTime, sizeof(TTsTime), sizeof(TTsTime)}}; |
|
84 |
|
85 const TParameterDetails KGetSchedRefsParam[] = {{EParamInt,0,KMaxSchedules}, |
|
86 {EParamInt,EAllSchedules,EPendingSchedules}, |
|
87 {EParamDes8,0,KMaxTDes8}}; |
|
88 |
|
89 const TParameterDetails KCountSchedulesParam[] = {{EParamPckg,sizeof(TInt),sizeof(TInt)}, |
|
90 {EParamInt,EAllSchedules,EPendingSchedules}}; |
|
91 |
|
92 const TParameterDetails KGetSchedInfoParam[] = {{EParamInt,0,KMaxScheduleId}, |
|
93 {EParamDes8,sizeof(TScheduleInfo), sizeof(TScheduleInfo)}, |
|
94 {EParamDes8, 0, sizeof(TTsTime)}}; |
|
95 |
|
96 const TParameterDetails KGetTimeSchedDataParam[] = {{EParamInt,0,KMaxScheduleId}, |
|
97 {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)}, |
|
98 {EParamDes8,0,KMaxTDes8}}; |
|
99 |
|
100 const TParameterDetails KGetCondSchedDataParam[] = {{EParamInt,0,KMaxScheduleId}, |
|
101 {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)}, |
|
102 {EParamDes8,0,KMaxTDes8}, |
|
103 {EParamDes8, 0, sizeof(TTsTime)}}; |
|
104 |
|
105 const TParameterDetails KGetTaskDataParam[] = {{EParamInt,0,KMaxScheduleId}, |
|
106 {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)}, |
|
107 {EParamDes8,0,KMaxTDes8}}; |
|
108 |
|
109 const TParameterDetails KGetTaskRefsParam[] = {{EParamInt,0,KMaxTasks}, |
|
110 {EParamInt,EAllSchedules,EPendingSchedules}, |
|
111 {EParamInt,EAllTasks,EMyTasks}, |
|
112 {EParamDes8,0,KMaxTDes8}}; |
|
113 |
|
114 const TParameterDetails KCountTasksParam[] = {{EParamPckg,sizeof(TInt),sizeof(TInt)}, |
|
115 {EParamInt,EAllSchedules,EPendingSchedules}, |
|
116 {EParamInt,EAllTasks,EMyTasks}}; |
|
117 |
|
118 const TParameterDetails KGetTaskParam[] = {{EParamInt,KMinInt32,KMaxInt32}, |
|
119 {EParamDes8,0,sizeof(TTaskInfo)}, |
|
120 {EParamInt,KMinInt32,KMaxInt32}, |
|
121 {EParamDes16,0,KMaxTDes8}}; |
|
122 |
|
123 const TParameterDetails KGetScheduledItemRefParam[] = {{EParamInt,0,KMaxTaskId}, |
|
124 {EParamDes8,0, sizeof(TSchedulerItemRef)}, |
|
125 {EParamDes8,0, sizeof(TTsTime)}}; |
|
126 |
|
127 const TParameterDetails KDeleteTaskParam[] = {EParamInt,KMinInt32,KMaxInt32}; |
|
128 |
|
129 const TParameterDetails KGetTaskDataSizeParam[] = {{EParamInt,KMinInt32,KMaxInt32}, |
|
130 {EParamPckg,sizeof(TInt),sizeof(TInt)}}; |
|
131 |
|
132 const TParameterDetails KGetScheduleTypeParam[] = {{EParamInt,0,KMaxScheduleId}, |
|
133 {EParamPckg,sizeof(TInt),sizeof(TInt)}}; |
|
134 |
|
135 |
|
136 /* This Security Policy defines the requirements for a client to interact |
|
137 * with the server. If a client sends a request to the server and doesnt |
|
138 * meet the security policy, the request is denied with KErrAccessDenied. |
|
139 * For the bakup server no policy is required so a default always pass |
|
140 * policy is used. |
|
141 */ |
|
142 _LIT_SECURITY_POLICY_PASS(KDefaultPolicy); |
|
143 |
|
144 /* This is the array of messages that will be accepted by the server. |
|
145 * The messages are defined as follows: |
|
146 * {Function Number, Security Policy, Number of Parameters, Parameter Descriptions} |
|
147 * A Binary search is used to locate the messages in the table therefore |
|
148 * the messages MUST appear in the list below sorted by function number. |
|
149 */ |
|
150 const TClientMessageSchema KClientMessages[] = |
|
151 { |
|
152 MESSAGE_SCHEMA(ERegisterClient,KDefaultPolicy,KRegisterClientParam), |
|
153 MESSAGE_SCHEMA(ECreateTimeSchedule,KDefaultPolicy,KCreateTimeSchedParam), |
|
154 MESSAGE_SCHEMA(ECreateConditionSchedule,KDefaultPolicy,KCreateCondSchedParam), |
|
155 MESSAGE_SCHEMA(EScheduleTask,KDefaultPolicy,KScheduleTaskParam), |
|
156 MESSAGE_SCHEMA(EDisableSchedule,KDefaultPolicy,KScheduleIdParam), |
|
157 MESSAGE_SCHEMA(EEnableSchedule,KDefaultPolicy,KScheduleIdParam), |
|
158 MESSAGE_SCHEMA(EDeleteSchedule,KDefaultPolicy,KScheduleIdParam), |
|
159 MESSAGE_SCHEMA(EEditTimeSchedule,KDefaultPolicy,KEditTimeSchedParam), |
|
160 MESSAGE_SCHEMA(EEditConditionSchedule,KDefaultPolicy,KEditCondSchedParam), |
|
161 MESSAGE_SCHEMA(EGetScheduleInfo,KDefaultPolicy,KGetSchedInfoParam), |
|
162 MESSAGE_SCHEMA(EGetTimeScheduleData,KDefaultPolicy,KGetTimeSchedDataParam), |
|
163 MESSAGE_SCHEMA(EGetConditionScheduleData,KDefaultPolicy,KGetCondSchedDataParam), |
|
164 MESSAGE_SCHEMA(EGetTaskData,KDefaultPolicy,KGetTaskDataParam), |
|
165 MESSAGE_SCHEMA(ECountSchedules,KDefaultPolicy,KCountSchedulesParam), |
|
166 MESSAGE_SCHEMA(ECountTasks,KDefaultPolicy,KCountTasksParam), |
|
167 MESSAGE_SCHEMA(EGetTaskRefs,KDefaultPolicy,KGetTaskRefsParam), |
|
168 MESSAGE_SCHEMA(EGetTask,KDefaultPolicy,KGetTaskParam), |
|
169 MESSAGE_SCHEMA(EGetTaskDataSize,KDefaultPolicy,KGetTaskDataSizeParam), |
|
170 MESSAGE_SCHEMA(EGetScheduleRefs,KDefaultPolicy,KGetSchedRefsParam), |
|
171 MESSAGE_SCHEMA(EDeleteTask,KDefaultPolicy,KDeleteTaskParam), |
|
172 MESSAGE_SCHEMA(EGetSchedulerItemRefAndNextDueTime,KDefaultPolicy,KGetScheduledItemRefParam), |
|
173 MESSAGE_SCHEMA(EGetScheduleType,KDefaultPolicy,KGetScheduleTypeParam), |
|
174 MESSAGE_SCHEMA_NO_PARAMS(ESchDbgMarkHeap,KDefaultPolicy), |
|
175 MESSAGE_SCHEMA(ESchDbgCheckHeap,KDefaultPolicy,KIntParam), |
|
176 MESSAGE_SCHEMA(ESchDbgMarkEnd,KDefaultPolicy,KIntParam), |
|
177 MESSAGE_SCHEMA(ESchDbgFailNext,KDefaultPolicy,KIntParam), |
|
178 MESSAGE_SCHEMA_NO_PARAMS(ESchDbgResetHeap,KDefaultPolicy), |
|
179 MESSAGE_SCHEMA_NO_PARAMS(ESchFaultServer,KDefaultPolicy) |
|
180 }; |
|
181 |
|
182 |
|
183 static void ValidateTTsTimeL(CMessageParameterBase* aParameter); |
|
184 static void ValidateTTaskInfoL(CMessageParameterBase* aParameter); |
|
185 static void ValidateTScheduleInfoL(CMessageParameterBase* aParameter); |
|
186 static void ValidateTSchedulerItemRefL(CMessageParameterBase* aParameter); |
|
187 static void ValidateTScheduleSettingsL(CMessageParameterBase* aParameter); |
|
188 |
|
189 /* This is the array of custom validation functions that are used to validate |
|
190 * parameters based on CPckgParameter parameter types |
|
191 */ |
|
192 const TCustomValidationFn KCustomValidationFunctions[] = {NULL, |
|
193 &ValidateTScheduleSettingsL, |
|
194 &ValidateTTsTimeL, |
|
195 &ValidateTTaskInfoL, |
|
196 &ValidateTScheduleInfoL, |
|
197 &ValidateTSchedulerItemRefL |
|
198 }; |
|
199 |
|
200 /*This struct defines the server data to be passed to the message framework on |
|
201 * initialisation |
|
202 */ |
|
203 extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages, |
|
204 KCustomValidationFunctions, |
|
205 "Task Scheduler", |
|
206 ESrvFlagLogBadMessages); |
|
207 |
|
208 /* |
|
209 Custom validation function for EParamTTsTime parameters. |
|
210 Checks that the TPckg passed in to the server is exactly the size |
|
211 defined in the schema. Reads the value from the clients message to |
|
212 ensure the data is valid. |
|
213 @param aParameter The parameter object to be validated |
|
214 @leave KErrBadDescriptor if the TPckg passed in to the server is not |
|
215 the expected size |
|
216 @leave Any other system-wide error code. |
|
217 */ |
|
218 void ValidateTTsTimeL(CMessageParameterBase* aParameter) |
|
219 { |
|
220 TTsTime time; |
|
221 TPckg<TTsTime> pTime(time); |
|
222 |
|
223 TInt length = aParameter->GetDesLengthL(); |
|
224 |
|
225 if((length < aParameter->Min())||(length > aParameter->Max())) |
|
226 { |
|
227 User::Leave(KErrBadDescriptor); |
|
228 } |
|
229 |
|
230 aParameter->ReadL(pTime,0); |
|
231 |
|
232 } |
|
233 |
|
234 /* |
|
235 Custom validation function for EParamTTaskInfo parameters. |
|
236 Checks that the TPckg passed in to the server is exactly the size |
|
237 defined in the schema. Reads the value from the clients message to |
|
238 ensure the data is valid. |
|
239 @param aParameter The parameter object to be validated |
|
240 @leave KErrBadDescriptor if the TPckg passed in to the server is not |
|
241 the expected size |
|
242 @leave Any other system-wide error code. |
|
243 */ |
|
244 void ValidateTTaskInfoL(CMessageParameterBase* aParameter) |
|
245 { |
|
246 TTaskInfo taskInfo; |
|
247 TPckg<TTaskInfo> pTaskInfo(taskInfo); |
|
248 |
|
249 TInt length = aParameter->GetDesLengthL(); |
|
250 |
|
251 if((length < aParameter->Min())||(length > aParameter->Max())) |
|
252 { |
|
253 User::Leave(KErrBadDescriptor); |
|
254 } |
|
255 |
|
256 aParameter->ReadL(pTaskInfo,0); |
|
257 } |
|
258 |
|
259 /* |
|
260 Custom validation function for EParamTScheduleInfo parameters. |
|
261 Checks that the TPckg passed in to the server is exactly the size |
|
262 defined in the schema. Reads the value from the clients message to |
|
263 ensure the data is valid. |
|
264 @param aParameter The parameter object to be validated |
|
265 @leave KErrBadDescriptor if the TPckg passed in to the server is not |
|
266 the expected size |
|
267 @leave Any other system-wide error code. |
|
268 */ |
|
269 void ValidateTScheduleInfoL(CMessageParameterBase* aParameter) |
|
270 { |
|
271 TScheduleInfo scheduleInfo; |
|
272 TPckg<TScheduleInfo> pScheduleInfo(scheduleInfo); |
|
273 |
|
274 TInt length = aParameter->GetDesLengthL(); |
|
275 |
|
276 if((length < aParameter->Min())||(length > aParameter->Max())) |
|
277 { |
|
278 User::Leave(KErrBadDescriptor); |
|
279 } |
|
280 |
|
281 aParameter->ReadL(pScheduleInfo,0); |
|
282 } |
|
283 |
|
284 /* |
|
285 Custom validation function for EParamTSchedulerItemRef parameters. |
|
286 Checks that the TPckg passed in to the server is exactly the size |
|
287 defined in the schema. Reads the value from the clients message to |
|
288 ensure the data is valid. |
|
289 @param aParameter The parameter object to be validated |
|
290 @leave KErrBadDescriptor if the TPckg passed in to the server is not |
|
291 the expected size |
|
292 @leave Any other system-wide error code. |
|
293 */ |
|
294 void ValidateTSchedulerItemRefL(CMessageParameterBase* aParameter) |
|
295 { |
|
296 TSchedulerItemRef itemRef; |
|
297 TPckg<TSchedulerItemRef> pItemRef(itemRef); |
|
298 |
|
299 TInt length = aParameter->GetDesLengthL(); |
|
300 |
|
301 if((length < aParameter->Min())||(length > aParameter->Max())) |
|
302 { |
|
303 User::Leave(KErrBadDescriptor); |
|
304 } |
|
305 |
|
306 aParameter->ReadL(pItemRef,0); |
|
307 } |
|
308 |
|
309 /* |
|
310 Custom validation function for EParamTScheduleSettings2 parameters. |
|
311 Checks that the TPckg passed in to the server is exactly the size |
|
312 defined in the schema. Reads the value from the clients message to |
|
313 ensure the data is valid. Checks iEntryCount is > 0. |
|
314 @param aParameter The parameter object to be validated |
|
315 @leave KErrBadDescriptor if the TPckg passed in to the server is not |
|
316 the expected size |
|
317 @leave Any other system-wide error code. |
|
318 */ |
|
319 void ValidateTScheduleSettingsL(CMessageParameterBase* aParameter) |
|
320 { |
|
321 TScheduleSettings2 settings; |
|
322 TPckg<TScheduleSettings2> pSettings(settings); |
|
323 |
|
324 TInt length = aParameter->GetDesLengthL(); |
|
325 |
|
326 if((length < aParameter->Min())||(length > aParameter->Max())) |
|
327 { |
|
328 User::Leave(KErrBadDescriptor); |
|
329 } |
|
330 |
|
331 aParameter->ReadL(pSettings,0); |
|
332 |
|
333 if(settings.iEntryCount < 0) |
|
334 { |
|
335 User::Leave(KErrBadParameter); |
|
336 } |
|
337 |
|
338 } |