1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/ClientMessageSchema.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,338 @@
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 <bsul/bsul.h>
1.20 +#include "CSCHCODE.H"
1.21 +#include "SCHINFO.H"
1.22 +
1.23 +using namespace BSUL;
1.24 +
1.25 +/**
1.26 +Intended Usage : This Enum lists the currently supported Custom Parameter types.
1.27 +The lower 16 bits of these enum values are used as indices to the
1.28 +Parameter Factory Function which instantiates the appropriate
1.29 +CMessageParammeterBase derived object to represent a given message parameter.
1.30 +The upper 16 bits of these values are used as the index in the array
1.31 +of custom validation functions. If the upper 16bits are set to 0, the default
1.32 +validation is used.
1.33 +*/
1.34 +enum TCustomParamType
1.35 + {
1.36 + EParamTScheduleSettings2 = (0x10000 | EParamPckg),
1.37 + EParamTTsTime = (0x20000 | EParamPckg),
1.38 + EParamTTaskInfo = (0x30000 | EParamPckg),
1.39 + EParamTScheduleInfo = (0x40000 | EParamPckg),
1.40 + EParamTSchedulerItemRef = (0x50000 | EParamPckg)
1.41 + };
1.42 +
1.43 +/* These are the parameter description sets for each message to be handled by the
1.44 + * server. These descriptions provide the type of the parameter and constraints
1.45 + * used to validate messages recieved from the client. The particular validation
1.46 + * requirements are defined in the appropriate CMessageParameterBase derived class
1.47 + * and parameter objects are instantiated via the Parameter factory Lookup table.
1.48 + */
1.49 +const TInt KMaxInt32 = 0x7FFFFFFF;
1.50 +const TInt KMinInt32 = 0x80000000;
1.51 +const TInt KMaxTDes8 = 0x0FFFFFFF;
1.52 +const TInt KMaxSchedules = 25000;//Max of 25000 schedules
1.53 +const TInt KMaxScheduleId = (10000 * (KMaxSchedules - 1));//Schedule IDs have an offset of 10000
1.54 +const TInt KMaxTasks = 9999;//Max of 9999 tasks per schedule
1.55 +const TInt KMaxTaskId = (KMaxScheduleId + KMaxTasks);
1.56 +
1.57 +const TParameterDetails KIntParam[] = {EParamInt,KMinInt32,KMaxInt32};
1.58 +
1.59 +
1.60 +const TParameterDetails KRegisterClientParam[] = {{EParamDes16Read,0,KMaxFileName},
1.61 + {EParamInt,0,KMaxInt32}};
1.62 +
1.63 +const TParameterDetails KCreateTimeSchedParam[] = {{EParamTScheduleSettings2,sizeof(TScheduleSettings2),sizeof(TScheduleSettings2)},
1.64 + {EParamDes8Read,0,KMaxTDes8},
1.65 + {EParamPckg,sizeof(TInt),sizeof(TInt)}};
1.66 +
1.67 +const TParameterDetails KCreateCondSchedParam[] = {{EParamTScheduleSettings2,sizeof(TScheduleSettings2),sizeof(TScheduleSettings2)},
1.68 + {EParamDes8Read,0,KMaxTDes8},
1.69 + {EParamTTsTime, sizeof(TTsTime), sizeof(TTsTime)},
1.70 + {EParamPckg,sizeof(TInt),sizeof(TInt)}};
1.71 +
1.72 +const TParameterDetails KScheduleTaskParam[] = {{EParamTTaskInfo,sizeof(TTaskInfo),sizeof(TTaskInfo)},
1.73 + {EParamInt,0,KMaxScheduleId},
1.74 + {EParamPckg,sizeof(TInt),sizeof(TInt)},
1.75 + {EParamDes16,0,KMaxTDes8}};
1.76 +
1.77 +const TParameterDetails KScheduleIdParam[] = {EParamInt,0,KMaxScheduleId};
1.78 +
1.79 +const TParameterDetails KEditTimeSchedParam[] = {{EParamInt,0,KMaxTasks},
1.80 + {EParamInt,0,KMaxScheduleId},
1.81 + {EParamDes8Read,0,KMaxTDes8}};
1.82 +
1.83 +const TParameterDetails KEditCondSchedParam[] = {{EParamInt,0,KMaxTasks},
1.84 + {EParamInt,0,KMaxScheduleId},
1.85 + {EParamDes8Read,0,KMaxTDes8},
1.86 + {EParamTTsTime, sizeof(TTsTime), sizeof(TTsTime)}};
1.87 +
1.88 +const TParameterDetails KGetSchedRefsParam[] = {{EParamInt,0,KMaxSchedules},
1.89 + {EParamInt,EAllSchedules,EPendingSchedules},
1.90 + {EParamDes8,0,KMaxTDes8}};
1.91 +
1.92 +const TParameterDetails KCountSchedulesParam[] = {{EParamPckg,sizeof(TInt),sizeof(TInt)},
1.93 + {EParamInt,EAllSchedules,EPendingSchedules}};
1.94 +
1.95 +const TParameterDetails KGetSchedInfoParam[] = {{EParamInt,0,KMaxScheduleId},
1.96 + {EParamDes8,sizeof(TScheduleInfo), sizeof(TScheduleInfo)},
1.97 + {EParamDes8, 0, sizeof(TTsTime)}};
1.98 +
1.99 +const TParameterDetails KGetTimeSchedDataParam[] = {{EParamInt,0,KMaxScheduleId},
1.100 + {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)},
1.101 + {EParamDes8,0,KMaxTDes8}};
1.102 +
1.103 +const TParameterDetails KGetCondSchedDataParam[] = {{EParamInt,0,KMaxScheduleId},
1.104 + {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)},
1.105 + {EParamDes8,0,KMaxTDes8},
1.106 + {EParamDes8, 0, sizeof(TTsTime)}};
1.107 +
1.108 +const TParameterDetails KGetTaskDataParam[] = {{EParamInt,0,KMaxScheduleId},
1.109 + {EParamTScheduleInfo,sizeof(TScheduleInfo), sizeof(TScheduleInfo)},
1.110 + {EParamDes8,0,KMaxTDes8}};
1.111 +
1.112 +const TParameterDetails KGetTaskRefsParam[] = {{EParamInt,0,KMaxTasks},
1.113 + {EParamInt,EAllSchedules,EPendingSchedules},
1.114 + {EParamInt,EAllTasks,EMyTasks},
1.115 + {EParamDes8,0,KMaxTDes8}};
1.116 +
1.117 +const TParameterDetails KCountTasksParam[] = {{EParamPckg,sizeof(TInt),sizeof(TInt)},
1.118 + {EParamInt,EAllSchedules,EPendingSchedules},
1.119 + {EParamInt,EAllTasks,EMyTasks}};
1.120 +
1.121 +const TParameterDetails KGetTaskParam[] = {{EParamInt,KMinInt32,KMaxInt32},
1.122 + {EParamDes8,0,sizeof(TTaskInfo)},
1.123 + {EParamInt,KMinInt32,KMaxInt32},
1.124 + {EParamDes16,0,KMaxTDes8}};
1.125 +
1.126 +const TParameterDetails KGetScheduledItemRefParam[] = {{EParamInt,0,KMaxTaskId},
1.127 + {EParamDes8,0, sizeof(TSchedulerItemRef)},
1.128 + {EParamDes8,0, sizeof(TTsTime)}};
1.129 +
1.130 +const TParameterDetails KDeleteTaskParam[] = {EParamInt,KMinInt32,KMaxInt32};
1.131 +
1.132 +const TParameterDetails KGetTaskDataSizeParam[] = {{EParamInt,KMinInt32,KMaxInt32},
1.133 + {EParamPckg,sizeof(TInt),sizeof(TInt)}};
1.134 +
1.135 +const TParameterDetails KGetScheduleTypeParam[] = {{EParamInt,0,KMaxScheduleId},
1.136 + {EParamPckg,sizeof(TInt),sizeof(TInt)}};
1.137 +
1.138 +
1.139 +/* This Security Policy defines the requirements for a client to interact
1.140 + * with the server. If a client sends a request to the server and doesnt
1.141 + * meet the security policy, the request is denied with KErrAccessDenied.
1.142 + * For the bakup server no policy is required so a default always pass
1.143 + * policy is used.
1.144 + */
1.145 +_LIT_SECURITY_POLICY_PASS(KDefaultPolicy);
1.146 +
1.147 +/* This is the array of messages that will be accepted by the server.
1.148 + * The messages are defined as follows:
1.149 + * {Function Number, Security Policy, Number of Parameters, Parameter Descriptions}
1.150 + * A Binary search is used to locate the messages in the table therefore
1.151 + * the messages MUST appear in the list below sorted by function number.
1.152 + */
1.153 +const TClientMessageSchema KClientMessages[] =
1.154 + {
1.155 + MESSAGE_SCHEMA(ERegisterClient,KDefaultPolicy,KRegisterClientParam),
1.156 + MESSAGE_SCHEMA(ECreateTimeSchedule,KDefaultPolicy,KCreateTimeSchedParam),
1.157 + MESSAGE_SCHEMA(ECreateConditionSchedule,KDefaultPolicy,KCreateCondSchedParam),
1.158 + MESSAGE_SCHEMA(EScheduleTask,KDefaultPolicy,KScheduleTaskParam),
1.159 + MESSAGE_SCHEMA(EDisableSchedule,KDefaultPolicy,KScheduleIdParam),
1.160 + MESSAGE_SCHEMA(EEnableSchedule,KDefaultPolicy,KScheduleIdParam),
1.161 + MESSAGE_SCHEMA(EDeleteSchedule,KDefaultPolicy,KScheduleIdParam),
1.162 + MESSAGE_SCHEMA(EEditTimeSchedule,KDefaultPolicy,KEditTimeSchedParam),
1.163 + MESSAGE_SCHEMA(EEditConditionSchedule,KDefaultPolicy,KEditCondSchedParam),
1.164 + MESSAGE_SCHEMA(EGetScheduleInfo,KDefaultPolicy,KGetSchedInfoParam),
1.165 + MESSAGE_SCHEMA(EGetTimeScheduleData,KDefaultPolicy,KGetTimeSchedDataParam),
1.166 + MESSAGE_SCHEMA(EGetConditionScheduleData,KDefaultPolicy,KGetCondSchedDataParam),
1.167 + MESSAGE_SCHEMA(EGetTaskData,KDefaultPolicy,KGetTaskDataParam),
1.168 + MESSAGE_SCHEMA(ECountSchedules,KDefaultPolicy,KCountSchedulesParam),
1.169 + MESSAGE_SCHEMA(ECountTasks,KDefaultPolicy,KCountTasksParam),
1.170 + MESSAGE_SCHEMA(EGetTaskRefs,KDefaultPolicy,KGetTaskRefsParam),
1.171 + MESSAGE_SCHEMA(EGetTask,KDefaultPolicy,KGetTaskParam),
1.172 + MESSAGE_SCHEMA(EGetTaskDataSize,KDefaultPolicy,KGetTaskDataSizeParam),
1.173 + MESSAGE_SCHEMA(EGetScheduleRefs,KDefaultPolicy,KGetSchedRefsParam),
1.174 + MESSAGE_SCHEMA(EDeleteTask,KDefaultPolicy,KDeleteTaskParam),
1.175 + MESSAGE_SCHEMA(EGetSchedulerItemRefAndNextDueTime,KDefaultPolicy,KGetScheduledItemRefParam),
1.176 + MESSAGE_SCHEMA(EGetScheduleType,KDefaultPolicy,KGetScheduleTypeParam),
1.177 + MESSAGE_SCHEMA_NO_PARAMS(ESchDbgMarkHeap,KDefaultPolicy),
1.178 + MESSAGE_SCHEMA(ESchDbgCheckHeap,KDefaultPolicy,KIntParam),
1.179 + MESSAGE_SCHEMA(ESchDbgMarkEnd,KDefaultPolicy,KIntParam),
1.180 + MESSAGE_SCHEMA(ESchDbgFailNext,KDefaultPolicy,KIntParam),
1.181 + MESSAGE_SCHEMA_NO_PARAMS(ESchDbgResetHeap,KDefaultPolicy),
1.182 + MESSAGE_SCHEMA_NO_PARAMS(ESchFaultServer,KDefaultPolicy)
1.183 + };
1.184 +
1.185 +
1.186 +static void ValidateTTsTimeL(CMessageParameterBase* aParameter);
1.187 +static void ValidateTTaskInfoL(CMessageParameterBase* aParameter);
1.188 +static void ValidateTScheduleInfoL(CMessageParameterBase* aParameter);
1.189 +static void ValidateTSchedulerItemRefL(CMessageParameterBase* aParameter);
1.190 +static void ValidateTScheduleSettingsL(CMessageParameterBase* aParameter);
1.191 +
1.192 +/* This is the array of custom validation functions that are used to validate
1.193 + * parameters based on CPckgParameter parameter types
1.194 + */
1.195 +const TCustomValidationFn KCustomValidationFunctions[] = {NULL,
1.196 + &ValidateTScheduleSettingsL,
1.197 + &ValidateTTsTimeL,
1.198 + &ValidateTTaskInfoL,
1.199 + &ValidateTScheduleInfoL,
1.200 + &ValidateTSchedulerItemRefL
1.201 + };
1.202 +
1.203 +/*This struct defines the server data to be passed to the message framework on
1.204 + * initialisation
1.205 + */
1.206 +extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages,
1.207 + KCustomValidationFunctions,
1.208 + "Task Scheduler",
1.209 + ESrvFlagLogBadMessages);
1.210 +
1.211 +/*
1.212 +Custom validation function for EParamTTsTime parameters.
1.213 +Checks that the TPckg passed in to the server is exactly the size
1.214 +defined in the schema. Reads the value from the clients message to
1.215 +ensure the data is valid.
1.216 +@param aParameter The parameter object to be validated
1.217 +@leave KErrBadDescriptor if the TPckg passed in to the server is not
1.218 + the expected size
1.219 +@leave Any other system-wide error code.
1.220 +*/
1.221 +void ValidateTTsTimeL(CMessageParameterBase* aParameter)
1.222 + {
1.223 + TTsTime time;
1.224 + TPckg<TTsTime> pTime(time);
1.225 +
1.226 + TInt length = aParameter->GetDesLengthL();
1.227 +
1.228 + if((length < aParameter->Min())||(length > aParameter->Max()))
1.229 + {
1.230 + User::Leave(KErrBadDescriptor);
1.231 + }
1.232 +
1.233 + aParameter->ReadL(pTime,0);
1.234 +
1.235 + }
1.236 +
1.237 +/*
1.238 +Custom validation function for EParamTTaskInfo parameters.
1.239 +Checks that the TPckg passed in to the server is exactly the size
1.240 +defined in the schema. Reads the value from the clients message to
1.241 +ensure the data is valid.
1.242 +@param aParameter The parameter object to be validated
1.243 +@leave KErrBadDescriptor if the TPckg passed in to the server is not
1.244 + the expected size
1.245 +@leave Any other system-wide error code.
1.246 +*/
1.247 +void ValidateTTaskInfoL(CMessageParameterBase* aParameter)
1.248 + {
1.249 + TTaskInfo taskInfo;
1.250 + TPckg<TTaskInfo> pTaskInfo(taskInfo);
1.251 +
1.252 + TInt length = aParameter->GetDesLengthL();
1.253 +
1.254 + if((length < aParameter->Min())||(length > aParameter->Max()))
1.255 + {
1.256 + User::Leave(KErrBadDescriptor);
1.257 + }
1.258 +
1.259 + aParameter->ReadL(pTaskInfo,0);
1.260 + }
1.261 +
1.262 +/*
1.263 +Custom validation function for EParamTScheduleInfo parameters.
1.264 +Checks that the TPckg passed in to the server is exactly the size
1.265 +defined in the schema. Reads the value from the clients message to
1.266 +ensure the data is valid.
1.267 +@param aParameter The parameter object to be validated
1.268 +@leave KErrBadDescriptor if the TPckg passed in to the server is not
1.269 + the expected size
1.270 +@leave Any other system-wide error code.
1.271 +*/
1.272 +void ValidateTScheduleInfoL(CMessageParameterBase* aParameter)
1.273 + {
1.274 + TScheduleInfo scheduleInfo;
1.275 + TPckg<TScheduleInfo> pScheduleInfo(scheduleInfo);
1.276 +
1.277 + TInt length = aParameter->GetDesLengthL();
1.278 +
1.279 + if((length < aParameter->Min())||(length > aParameter->Max()))
1.280 + {
1.281 + User::Leave(KErrBadDescriptor);
1.282 + }
1.283 +
1.284 + aParameter->ReadL(pScheduleInfo,0);
1.285 + }
1.286 +
1.287 +/*
1.288 +Custom validation function for EParamTSchedulerItemRef parameters.
1.289 +Checks that the TPckg passed in to the server is exactly the size
1.290 +defined in the schema. Reads the value from the clients message to
1.291 +ensure the data is valid.
1.292 +@param aParameter The parameter object to be validated
1.293 +@leave KErrBadDescriptor if the TPckg passed in to the server is not
1.294 + the expected size
1.295 +@leave Any other system-wide error code.
1.296 +*/
1.297 +void ValidateTSchedulerItemRefL(CMessageParameterBase* aParameter)
1.298 + {
1.299 + TSchedulerItemRef itemRef;
1.300 + TPckg<TSchedulerItemRef> pItemRef(itemRef);
1.301 +
1.302 + TInt length = aParameter->GetDesLengthL();
1.303 +
1.304 + if((length < aParameter->Min())||(length > aParameter->Max()))
1.305 + {
1.306 + User::Leave(KErrBadDescriptor);
1.307 + }
1.308 +
1.309 + aParameter->ReadL(pItemRef,0);
1.310 + }
1.311 +
1.312 +/*
1.313 +Custom validation function for EParamTScheduleSettings2 parameters.
1.314 +Checks that the TPckg passed in to the server is exactly the size
1.315 +defined in the schema. Reads the value from the clients message to
1.316 +ensure the data is valid. Checks iEntryCount is > 0.
1.317 +@param aParameter The parameter object to be validated
1.318 +@leave KErrBadDescriptor if the TPckg passed in to the server is not
1.319 + the expected size
1.320 +@leave Any other system-wide error code.
1.321 +*/
1.322 +void ValidateTScheduleSettingsL(CMessageParameterBase* aParameter)
1.323 + {
1.324 + TScheduleSettings2 settings;
1.325 + TPckg<TScheduleSettings2> pSettings(settings);
1.326 +
1.327 + TInt length = aParameter->GetDesLengthL();
1.328 +
1.329 + if((length < aParameter->Min())||(length > aParameter->Max()))
1.330 + {
1.331 + User::Leave(KErrBadDescriptor);
1.332 + }
1.333 +
1.334 + aParameter->ReadL(pSettings,0);
1.335 +
1.336 + if(settings.iEntryCount < 0)
1.337 + {
1.338 + User::Leave(KErrBadParameter);
1.339 + }
1.340 +
1.341 + }