Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2478 lines
78 KiB

  1. /******************************************************************************
  2. Copyright(c) Microsoft Corporation
  3. Module Name:
  4. CreateValidations.cpp
  5. Abstract:
  6. This module validates the various -create sub options specified by the user
  7. Author:
  8. B.Raghu babu 20-Sept-2000 : Created
  9. Revision History:
  10. G.Surender Reddy 25-sep-2000 : Modified it
  11. [ Added error checking ]
  12. G.Surender Reddy 10-Oct-2000 : Modified it
  13. [ made changes in validatemodifierval(),
  14. ValidateDayAndMonth() functions ]
  15. G.Surender Reddy 15-oct-2000 : Modified it
  16. [ Moved the strings to Resource table ]
  17. Venu Gopal S 26-Feb-2001 : Modified it
  18. [ Added GetDateFormatString(),
  19. GetDateFieldFormat() functions to
  20. gets the date format according to
  21. regional options]
  22. ******************************************************************************/
  23. //common header files needed for this file
  24. #include "pch.h"
  25. #include "CommonHeaderFiles.h"
  26. /******************************************************************************
  27. Routine Description:
  28. This routine validates the sub options specified by the user reg.create option
  29. & determines the type of a scheduled task.
  30. Arguments:
  31. [ out ] tcresubops : Structure containing the task's properties
  32. [ out ] tcreoptvals : Structure containing optional values to set
  33. [ in ] cmdOptions[] : Array of type TCMDPARSER
  34. [ in ] dwScheduleType : Type of schedule[Daily,once,weekly etc]
  35. Return Value :
  36. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  37. on failure
  38. ******************************************************************************/
  39. DWORD
  40. ValidateSuboptVal(
  41. OUT TCREATESUBOPTS& tcresubops,
  42. OUT TCREATEOPVALS &tcreoptvals,
  43. IN TCMDPARSER2 cmdOptions[],
  44. IN DWORD dwScheduleType
  45. )
  46. {
  47. DWORD dwRetval = RETVAL_SUCCESS;
  48. BOOL bIsStDtCurDt = FALSE;
  49. BOOL bIsStTimeCurTime = FALSE;
  50. BOOL bIsDefltValMod = FALSE;
  51. // Validate whether -s, -u, -p options specified correctly or not.
  52. //Accept password if -p not specified.
  53. dwRetval = ValidateRemoteSysInfo( cmdOptions, tcresubops, tcreoptvals);
  54. if(RETVAL_FAIL == dwRetval )
  55. {
  56. return dwRetval; // Error.
  57. }
  58. // Validate Modifier value.
  59. dwRetval = ValidateModifierVal( tcresubops.szModifier, dwScheduleType,
  60. cmdOptions[OI_CREATE_MODIFIER].dwActuals,
  61. cmdOptions[OI_CREATE_DAY].dwActuals,
  62. cmdOptions[OI_CREATE_MONTHS].dwActuals,
  63. bIsDefltValMod);
  64. if(RETVAL_FAIL == dwRetval )
  65. {
  66. return dwRetval; // error in modifier value
  67. }
  68. else
  69. {
  70. if(bIsDefltValMod)
  71. {
  72. StringCopy(tcresubops.szModifier,DEFAULT_MODIFIER_SZ, SIZE_OF_ARRAY(tcresubops.szModifier));
  73. }
  74. }
  75. // Validate Day and Month strings
  76. dwRetval = ValidateDayAndMonth( tcresubops.szDays, tcresubops.szMonths,
  77. dwScheduleType,
  78. cmdOptions[OI_CREATE_DAY].dwActuals,
  79. cmdOptions[OI_CREATE_MONTHS].dwActuals,
  80. cmdOptions[OI_CREATE_MODIFIER].dwActuals,
  81. tcresubops.szModifier);
  82. if(RETVAL_FAIL == dwRetval )
  83. {
  84. return dwRetval; // Error found in Day/Month string.
  85. }
  86. // Validate Start Date value.
  87. dwRetval = ValidateStartDate( tcresubops.szStartDate, dwScheduleType,
  88. cmdOptions[OI_CREATE_STARTDATE].dwActuals,
  89. bIsStDtCurDt);
  90. if(RETVAL_FAIL == dwRetval )
  91. {
  92. return dwRetval; // Error in Day/Month string.
  93. }
  94. else
  95. {
  96. if(bIsStDtCurDt) // Set start date to current date.
  97. {
  98. tcreoptvals.bSetStartDateToCurDate = TRUE;
  99. }
  100. }
  101. // Validate End Date value.
  102. dwRetval = ValidateEndDate( tcresubops.szEndDate, dwScheduleType,
  103. cmdOptions[OI_CREATE_ENDDATE].dwActuals);
  104. if(RETVAL_FAIL == dwRetval )
  105. {
  106. return dwRetval; // Error in Day/Month string.
  107. }
  108. //Check Whether end date should be greater than startdate
  109. WORD wEndDay = 0;
  110. WORD wEndMonth = 0;
  111. WORD wEndYear = 0;
  112. WORD wStartDay = 0;
  113. WORD wStartMonth = 0;
  114. WORD wStartYear = 0;
  115. if( cmdOptions[OI_CREATE_ENDDATE].dwActuals != 0 )
  116. {
  117. if( RETVAL_FAIL == GetDateFieldEntities( tcresubops.szEndDate,&wEndDay,
  118. &wEndMonth,&wEndYear))
  119. {
  120. return RETVAL_FAIL;
  121. }
  122. }
  123. SYSTEMTIME systime = {0,0,0,0,0,0,0,0};
  124. if(bIsStDtCurDt)
  125. {
  126. GetLocalTime(&systime);
  127. wStartDay = systime.wDay;
  128. wStartMonth = systime.wMonth;
  129. wStartYear = systime.wYear;
  130. }
  131. else if( ( cmdOptions[OI_CREATE_STARTDATE].dwActuals != 0 ) &&
  132. (RETVAL_FAIL == GetDateFieldEntities(tcresubops.szStartDate,
  133. &wStartDay,&wStartMonth,
  134. &wStartYear)))
  135. {
  136. return RETVAL_FAIL;
  137. }
  138. if( (cmdOptions[OI_CREATE_ENDDATE].dwActuals != 0) )
  139. {
  140. if( ( wEndYear == wStartYear ) )
  141. {
  142. // For same years if the end month is less than start month or for same years and same months
  143. // if the endday is less than the startday.
  144. if ( ( wEndMonth < wStartMonth ) || ( ( wEndMonth == wStartMonth ) && ( wEndDay < wStartDay ) ) )
  145. {
  146. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  147. return RETVAL_FAIL;
  148. }
  149. }
  150. else if ( wEndYear < wStartYear )
  151. {
  152. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  153. return RETVAL_FAIL;
  154. }
  155. }
  156. // Validate Start Time value.
  157. dwRetval = ValidateStartTime( tcresubops.szStartTime, dwScheduleType,
  158. cmdOptions[OI_CREATE_STARTTIME].dwActuals,
  159. bIsStTimeCurTime);
  160. if ( RETVAL_FAIL == dwRetval )
  161. {
  162. return dwRetval; // Error found in starttime.
  163. }
  164. else
  165. {
  166. if(bIsStTimeCurTime)
  167. {
  168. tcreoptvals.bSetStartTimeToCurTime = TRUE;
  169. }
  170. }
  171. // Validate End Time value.
  172. dwRetval = ValidateEndTime( tcresubops.szEndTime, dwScheduleType,
  173. cmdOptions[OI_CREATE_ENDTIME].dwActuals);
  174. if ( RETVAL_FAIL == dwRetval )
  175. {
  176. return dwRetval; // Error found in endtime.
  177. }
  178. // Validate Idle Time value.
  179. dwRetval = ValidateIdleTimeVal( tcresubops.szIdleTime, dwScheduleType,
  180. cmdOptions[OI_CREATE_IDLETIME].dwActuals);
  181. if ( RETVAL_FAIL == dwRetval )
  182. {
  183. return dwRetval;
  184. }
  185. return RETVAL_SUCCESS;
  186. }
  187. /******************************************************************************
  188. Routine Description:
  189. Checks whether password to be prompted for remote system or not.
  190. Arguments:
  191. [ in ] szServer : Server name
  192. [ in ] szUser : User name
  193. [ in ] szPassword : Password
  194. [ in ] cmdOptions : TCMDPARSER Array containg the options given by the user
  195. [ in ] tcreoptvals: Structure containing optional values to set
  196. Return Value :
  197. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  198. on failure
  199. ******************************************************************************/
  200. DWORD
  201. ValidateRemoteSysInfo(
  202. IN TCMDPARSER2 cmdOptions[],
  203. IN TCREATESUBOPTS& tcresubops,
  204. IN TCREATEOPVALS& tcreoptvals
  205. )
  206. {
  207. BOOL bIsLocalSystem = FALSE;
  208. // "-rp" should not be specified without "-ru"
  209. if ( ( ( cmdOptions[ OI_CREATE_RUNASUSERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].dwActuals == 1 ) ) ||
  210. ( ( cmdOptions[ OI_CREATE_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_CREATE_PASSWORD ].dwActuals == 1 ) ) ||
  211. ( ( cmdOptions[ OI_CREATE_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_CREATE_PASSWORD ].dwActuals == 1 ) ) ||
  212. ( ( cmdOptions[ OI_CREATE_RUNASUSERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_CREATE_PASSWORD ].dwActuals == 1 ) ) ||
  213. ( ( cmdOptions[ OI_CREATE_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_CREATE_RUNASUSERNAME ].dwActuals == 0 ) &&
  214. ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_CREATE_PASSWORD ].dwActuals == 1 ) ) )
  215. {
  216. // invalid syntax
  217. ShowMessage(stderr, GetResString(IDS_CPASSWORD_BUT_NOUSERNAME));
  218. return RETVAL_FAIL; // indicate failure
  219. }
  220. tcreoptvals.bPassword = FALSE;
  221. bIsLocalSystem = IsLocalSystem( tcresubops.szServer );
  222. if ( TRUE == bIsLocalSystem )
  223. {
  224. tcreoptvals.bPassword = FALSE;
  225. }
  226. // check whether the password (-p) specified in the command line or not
  227. // and also check whether '*' or empty is given for -p or not
  228. // check whether the password (-p) specified in the command line or not
  229. // and also check whether '*' or empty is given for -p or not
  230. // check whether the password (-p) specified in the command line or not
  231. // and also check whether '*' or empty is given for -p or not
  232. // check the remote connectivity information
  233. if ( tcresubops.szServer != NULL )
  234. {
  235. //
  236. // if -u is not specified, we need to allocate memory
  237. // in order to be able to retrive the current user name
  238. //
  239. // case 1: -p is not at all specified
  240. // as the value for this switch is optional, we have to rely
  241. // on the dwActuals to determine whether the switch is specified or not
  242. // in this case utility needs to try to connect first and if it fails
  243. // then prompt for the password -- in fact, we need not check for this
  244. // condition explicitly except for noting that we need to prompt for the
  245. // password
  246. //
  247. // case 2: -p is specified
  248. // but we need to check whether the value is specified or not
  249. // in this case user wants the utility to prompt for the password
  250. // before trying to connect
  251. //
  252. // case 3: -p * is specified
  253. // user name
  254. if ( tcresubops.szUser == NULL )
  255. {
  256. tcresubops.szUser = (LPWSTR) AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  257. if ( tcresubops.szUser == NULL )
  258. {
  259. SaveLastError();
  260. return RETVAL_FAIL;
  261. }
  262. }
  263. // password
  264. if ( tcresubops.szPassword == NULL )
  265. {
  266. tcreoptvals.bPassword = TRUE;
  267. tcresubops.szPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  268. if ( tcresubops.szPassword == NULL )
  269. {
  270. SaveLastError();
  271. return RETVAL_FAIL;
  272. }
  273. }
  274. // case 1
  275. if ( cmdOptions[ OI_CREATE_PASSWORD ].dwActuals == 0 )
  276. {
  277. // we need not do anything special here
  278. }
  279. // case 2
  280. else if ( cmdOptions[ OI_CREATE_PASSWORD ].pValue == NULL )
  281. {
  282. StringCopy( tcresubops.szPassword, L"*", GetBufferSize(tcresubops.szPassword)/sizeof(WCHAR));
  283. }
  284. // case 3
  285. else if ( StringCompareEx( tcresubops.szPassword, L"*", TRUE, 0 ) == 0 )
  286. {
  287. if ( ReallocateMemory( (LPVOID*)&tcresubops.szPassword,
  288. MAX_STRING_LENGTH * sizeof( WCHAR ) ) == FALSE )
  289. {
  290. SaveLastError();
  291. return RETVAL_FAIL;
  292. }
  293. // ...
  294. tcreoptvals.bPassword = TRUE;
  295. }
  296. }
  297. if( ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].dwActuals == 1 ) )
  298. {
  299. tcreoptvals.bRunAsPassword = TRUE;
  300. if ( cmdOptions[ OI_CREATE_RUNASPASSWORD ].pValue == NULL )
  301. {
  302. tcresubops.szRunAsPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  303. if ( NULL == tcresubops.szRunAsPassword)
  304. {
  305. SaveLastError();
  306. return RETVAL_FAIL;
  307. }
  308. StringCopy( tcresubops.szRunAsPassword, L"*", GetBufferSize(tcresubops.szRunAsPassword)/sizeof(WCHAR));
  309. }
  310. }
  311. return RETVAL_SUCCESS;
  312. }
  313. /******************************************************************************
  314. Routine Description:
  315. This routine validates & determines the modifier value .
  316. Arguments:
  317. [ in ] szModifier : Modifer value
  318. [ in ] dwScheduleType : Type of schedule[Daily,once,weekly etc]
  319. [ in ] dwModOptActCnt : Modifier optional value
  320. [ in ] dwDayOptCnt : Days value
  321. [ in ] dwMonOptCnt : Months value
  322. [ out ] bIsDefltValMod : Whether default value should be given for modifier
  323. Return Value :
  324. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  325. on failure
  326. ******************************************************************************/
  327. DWORD
  328. ValidateModifierVal(
  329. IN LPCTSTR szModifier,
  330. IN DWORD dwScheduleType,
  331. IN DWORD dwModOptActCnt,
  332. IN DWORD dwDayOptCnt,
  333. IN DWORD dwMonOptCnt,
  334. OUT BOOL& bIsDefltValMod
  335. )
  336. {
  337. WCHAR szDayType[MAX_RES_STRING] = L"\0";
  338. ULONG dwModifier = 0;
  339. StringCopy(szDayType,GetResString(IDS_TASK_FIRSTWEEK), SIZE_OF_ARRAY(szDayType));
  340. StringConcat(szDayType,_T("|"), SIZE_OF_ARRAY(szDayType));
  341. StringConcat(szDayType,GetResString(IDS_TASK_SECONDWEEK), SIZE_OF_ARRAY(szDayType));
  342. StringConcat(szDayType,_T("|"), SIZE_OF_ARRAY(szDayType));
  343. StringConcat(szDayType,GetResString(IDS_TASK_THIRDWEEK), SIZE_OF_ARRAY(szDayType));
  344. StringConcat(szDayType,_T("|"), SIZE_OF_ARRAY(szDayType));
  345. StringConcat(szDayType,GetResString(IDS_TASK_FOURTHWEEK), SIZE_OF_ARRAY(szDayType));
  346. StringConcat(szDayType,_T("|"), SIZE_OF_ARRAY(szDayType));
  347. StringConcat(szDayType,GetResString(IDS_TASK_LASTWEEK), SIZE_OF_ARRAY(szDayType));
  348. bIsDefltValMod = FALSE; // If TRUE : Set modifier to default value, 1.
  349. LPWSTR pszStopString = NULL;
  350. switch( dwScheduleType )
  351. {
  352. case SCHED_TYPE_MINUTE: // Schedule type is Minute
  353. if( (dwModOptActCnt <= 0) || (StringLength(szModifier, 0) <= 0) )
  354. {
  355. bIsDefltValMod = TRUE;
  356. return RETVAL_SUCCESS;
  357. }
  358. dwModifier = wcstoul(szModifier,&pszStopString,BASE_TEN);
  359. // check whether alpha-numneric value specified or not..
  360. // Also, check for underflow/overflow.
  361. if( (errno == ERANGE) ||
  362. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  363. {
  364. break;
  365. }
  366. if( dwModifier > 0 && dwModifier < 1440 ) // Valid Range 1 - 1439
  367. return RETVAL_SUCCESS;
  368. break;
  369. // Schedule type is Hourly
  370. case SCHED_TYPE_HOURLY:
  371. if( (dwModOptActCnt <= 0) || (StringLength(szModifier, 0) <= 0) )
  372. {
  373. bIsDefltValMod = TRUE;
  374. return RETVAL_SUCCESS;
  375. }
  376. dwModifier = wcstoul(szModifier,&pszStopString,BASE_TEN);
  377. // check whether alpha-numneric value specified or not..
  378. // Also, check for underflow/overflow.
  379. if( (errno == ERANGE) ||
  380. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  381. {
  382. break;
  383. }
  384. if( dwModifier > 0 && dwModifier < 24 ) // Valid Range 1 - 23
  385. {
  386. return RETVAL_SUCCESS;
  387. }
  388. break;
  389. // Schedule type is Daily
  390. case SCHED_TYPE_DAILY:
  391. // -days option is NOT APPLICABLE for DAILY type item.
  392. if( (dwDayOptCnt > 0) )
  393. {// Invalid sysntax. Return error
  394. // Modifier option and days options both should not specified same time.
  395. bIsDefltValMod = FALSE;
  396. ShowMessage(stderr, GetResString(IDS_DAYS_NA));
  397. return RETVAL_FAIL;
  398. }
  399. // -months option is NOT APPLICABLE for DAILY type item.
  400. if( dwMonOptCnt > 0 )
  401. {// Invalid sysntax. Return error
  402. // Modifier option and days options both should not specified same time.
  403. bIsDefltValMod = FALSE;
  404. ShowMessage(stderr , GetResString(IDS_MON_NA));
  405. return RETVAL_FAIL;
  406. }
  407. // Check whether the -modifier switch is psecified. If not, then take default value.
  408. if( (dwModOptActCnt <= 0) || (StringLength(szModifier, 0) <= 0) )
  409. {
  410. // Modifier options is not specified. So, set it to default value. (i.e, 1 )
  411. bIsDefltValMod = TRUE;
  412. return RETVAL_SUCCESS;
  413. }
  414. dwModifier = wcstoul(szModifier,&pszStopString,BASE_TEN);
  415. // check whether alpha-numneric value specified or not..
  416. // Also, check for underflow/overflow.
  417. if( (errno == ERANGE) ||
  418. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  419. {
  420. break;
  421. }
  422. // If the -modifier option is specified, then validate the value.
  423. if( dwModifier > 0 && dwModifier < 366 ) // Valid Range 1 - 365
  424. {
  425. return RETVAL_SUCCESS;
  426. }
  427. else
  428. {
  429. ShowMessage(stderr, GetResString(IDS_INVALID_MODIFIER));
  430. return RETVAL_FAIL;
  431. }
  432. break;
  433. // Schedule type is Weekly
  434. case SCHED_TYPE_WEEKLY:
  435. // If -modifier option is not specified, then set it to default value.
  436. if( (dwModOptActCnt <= 0) || (StringLength(szModifier, 0) <= 0) )
  437. {
  438. // Modifier options is not specified. So, set it to default value. (i.e, 1 )
  439. bIsDefltValMod = TRUE;
  440. return RETVAL_SUCCESS;
  441. }
  442. if( dwModOptActCnt > 0)
  443. {
  444. dwModifier = wcstoul(szModifier,&pszStopString,BASE_TEN);
  445. // check whether alpha-numneric value specified or not..
  446. // Also, check for underflow/overflow.
  447. if( (errno == ERANGE) ||
  448. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  449. {
  450. break;
  451. }
  452. if( dwModifier > 0 && dwModifier < 53 ) // Valid Range 1 - 52
  453. return RETVAL_SUCCESS;
  454. break;
  455. }
  456. break;
  457. // Schedule type is Monthly
  458. case SCHED_TYPE_MONTHLY:
  459. // If -modifier option is not specified, then set it to default value.
  460. if( ( dwModOptActCnt > 0) && (StringLength(szModifier, 0) == 0) )
  461. {
  462. // Modifier option is not proper. So display error and return false.
  463. bIsDefltValMod = FALSE;
  464. ShowMessage(stderr, GetResString(IDS_INVALID_MODIFIER));
  465. return RETVAL_FAIL;
  466. }
  467. //check if the modifier is LASTDAY[not case sensitive]
  468. if( StringCompare( szModifier , GetResString( IDS_DAY_MODIFIER_LASTDAY ), TRUE, 0 ) == 0)
  469. return RETVAL_SUCCESS;
  470. //Check if -mo is in between FIRST,SECOND ,THIRD, LAST
  471. //then -days[ MON to SUN ] is applicable , -months is also applicable
  472. if( InString ( szModifier , szDayType , TRUE ) )
  473. {
  474. return RETVAL_SUCCESS;
  475. }
  476. else
  477. {
  478. dwModifier = wcstoul(szModifier,&pszStopString,BASE_TEN);
  479. if( (errno == ERANGE) ||
  480. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  481. {
  482. break;
  483. }
  484. if( ( dwModOptActCnt == 1 ) && ( dwModifier < 1 || dwModifier > 12 ) ) //check whether -mo value is in between 1 - 12
  485. {
  486. //invalid -mo value
  487. ShowMessage(stderr, GetResString(IDS_INVALID_MODIFIER));
  488. return RETVAL_FAIL;
  489. }
  490. return RETVAL_SUCCESS;
  491. }
  492. break;
  493. case SCHED_TYPE_ONETIME:
  494. case SCHED_TYPE_ONSTART:
  495. case SCHED_TYPE_ONLOGON:
  496. case SCHED_TYPE_ONIDLE:
  497. if( dwModOptActCnt <= 0 )
  498. {
  499. // Modifier option is not applicable. So, return success.
  500. bIsDefltValMod = FALSE;
  501. return RETVAL_SUCCESS;
  502. }
  503. else
  504. {
  505. // Modifier option is not applicable. But specified. So, return error.
  506. bIsDefltValMod = FALSE;
  507. ShowMessage(stderr, GetResString(IDS_MODIFIER_NA));
  508. return RETVAL_FAIL;
  509. }
  510. break;
  511. default:
  512. return RETVAL_FAIL;
  513. }
  514. // Modifier option is not proper. So display error and return false.
  515. bIsDefltValMod = FALSE;
  516. ShowMessage(stderr, GetResString(IDS_INVALID_MODIFIER));
  517. return RETVAL_FAIL;
  518. }
  519. /******************************************************************************
  520. Routine Description:
  521. This routine validates & determines the day,month value .
  522. Arguments:
  523. [ in ] szDay : Day value
  524. [ in ] szMonths : Months[Daily,once,weekly etc]
  525. [ in ] dwSchedType : Modifier optional value
  526. [ in ] dwDayOptCnt : Days option value
  527. [ in ] dwMonOptCnt : Months option value
  528. [ in ] dwOptModifier : Modifier option value
  529. [ in ] szModifier : Whether default value for modifier
  530. Return Value :
  531. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  532. on failure
  533. ******************************************************************************/
  534. DWORD
  535. ValidateDayAndMonth(
  536. IN LPWSTR szDay,
  537. IN LPWSTR szMonths,
  538. IN DWORD dwSchedType,
  539. IN DWORD dwDayOptCnt,
  540. IN DWORD dwMonOptCnt,
  541. IN DWORD dwOptModifier,
  542. IN LPWSTR szModifier
  543. )
  544. {
  545. DWORD dwRetval = 0;
  546. DWORD dwModifier = 0;
  547. DWORD dwDays = 0;
  548. WCHAR szDayModifier[MAX_RES_STRING] = L"\0";
  549. //get the valid week day modifiers from the rc file
  550. StringCopy(szDayModifier,GetResString(IDS_TASK_FIRSTWEEK), SIZE_OF_ARRAY(szDayModifier));
  551. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  552. StringConcat(szDayModifier,GetResString(IDS_TASK_SECONDWEEK), SIZE_OF_ARRAY(szDayModifier));
  553. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  554. StringConcat(szDayModifier,GetResString(IDS_TASK_THIRDWEEK), SIZE_OF_ARRAY(szDayModifier));
  555. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  556. StringConcat(szDayModifier,GetResString(IDS_TASK_FOURTHWEEK), SIZE_OF_ARRAY(szDayModifier));
  557. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  558. StringConcat(szDayModifier,GetResString(IDS_TASK_LASTWEEK), SIZE_OF_ARRAY(szDayModifier));
  559. switch (dwSchedType)
  560. {
  561. case SCHED_TYPE_DAILY:
  562. // -days and -months optons is not applicable. SO, check for it.
  563. if( dwDayOptCnt > 0 || dwMonOptCnt > 0)
  564. {
  565. return RETVAL_FAIL;
  566. }
  567. return RETVAL_SUCCESS;
  568. case SCHED_TYPE_MONTHLY:
  569. if( dwMonOptCnt > 0 && StringLength(szMonths, 0) == 0)
  570. {
  571. ShowMessage(stderr, GetResString(IDS_INVALID_MONTH_MODFIER));
  572. return RETVAL_FAIL;
  573. }
  574. //if the modifier is LASTDAY
  575. if( StringCompare( szModifier , GetResString( IDS_DAY_MODIFIER_LASTDAY ), TRUE, 0 ) == 0)
  576. {
  577. //-day is not applicable for this case only -months is applicable
  578. if( dwDayOptCnt > 0 )
  579. {
  580. ShowMessage(stderr, GetResString(IDS_DAYS_NA));
  581. return RETVAL_FAIL;
  582. }
  583. if(StringLength(szMonths, 0))
  584. {
  585. if( ( ValidateMonth( szMonths ) == RETVAL_SUCCESS ) ||
  586. InString( szMonths, ASTERIX, TRUE ) )
  587. {
  588. return RETVAL_SUCCESS;
  589. }
  590. else
  591. {
  592. ShowMessage(stderr , GetResString(IDS_INVALID_VALUE_FOR_MON));
  593. return RETVAL_FAIL;
  594. }
  595. }
  596. else
  597. {
  598. ShowMessage(stderr ,GetResString(IDS_NO_MONTH_VALUE));
  599. return RETVAL_FAIL;
  600. }
  601. }
  602. // If -day is specified then check whether the day value is valid or not.
  603. if( InString( szDay, ASTERIX, TRUE) )
  604. {
  605. ShowMessage(stderr ,GetResString(IDS_INVALID_VALUE_FOR_DAY));
  606. return RETVAL_FAIL;
  607. }
  608. if(( StringLength (szDay, 0 ) == 0 ) && InString(szModifier, szDayModifier, TRUE))
  609. {
  610. ShowMessage(stderr, GetResString(IDS_NO_DAY_VALUE));
  611. return RETVAL_FAIL;
  612. }
  613. if( dwDayOptCnt )
  614. {
  615. dwModifier = (DWORD) AsLong(szModifier, BASE_TEN);
  616. //check for multiples days,if then return error
  617. if ( wcspbrk ( szDay , COMMA_STRING ) )
  618. {
  619. ShowMessage(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  620. return RETVAL_FAIL;
  621. }
  622. if( ValidateDay( szDay ) == RETVAL_SUCCESS )
  623. {
  624. //Check the modifier value should be in FIRST, SECOND, THIRD, FOURTH, LAST OR LASTDAY etc..
  625. if(!( InString(szModifier, szDayModifier, TRUE) ) )
  626. {
  627. ShowMessage(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  628. return RETVAL_FAIL;
  629. }
  630. }
  631. else
  632. {
  633. dwDays = (DWORD) AsLong(szDay, BASE_TEN);
  634. if( ( dwDays < 1 ) || ( dwDays > 31 ) )
  635. {
  636. ShowMessage(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  637. return RETVAL_FAIL;
  638. }
  639. if( ( dwOptModifier == 1 ) && ( ( dwModifier < 1 ) || ( dwModifier > 12 ) ) )
  640. {
  641. ShowMessage(stderr, GetResString(IDS_INVALID_MODIFIER));
  642. return RETVAL_FAIL;
  643. }
  644. if( InString(szModifier, szDayModifier, TRUE) )
  645. {
  646. ShowMessage(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  647. return RETVAL_FAIL;
  648. }
  649. if(dwMonOptCnt && StringLength(szModifier, 0))
  650. {
  651. ShowMessage(stderr ,GetResString(IDS_INVALID_MONTH_MODFIER));
  652. return RETVAL_FAIL;
  653. }
  654. }
  655. } //end of dwDayOptCnt
  656. if(StringLength(szMonths, 0))
  657. {
  658. if( StringLength(szModifier, 0) )
  659. {
  660. dwModifier = (DWORD) AsLong(szModifier, BASE_TEN);
  661. if(dwModifier >= 1 && dwModifier <= 12)
  662. {
  663. ShowMessage( stderr ,GetResString(IDS_MON_NA));
  664. return RETVAL_FAIL;
  665. }
  666. }
  667. if( ( ValidateMonth( szMonths ) == RETVAL_SUCCESS ) ||
  668. InString( szMonths, ASTERIX, TRUE ) )
  669. {
  670. return RETVAL_SUCCESS;
  671. }
  672. else
  673. {
  674. ShowMessage(stderr ,GetResString(IDS_INVALID_VALUE_FOR_MON));
  675. return RETVAL_FAIL;
  676. }
  677. }
  678. // assgin default values for month,day
  679. return RETVAL_SUCCESS;
  680. case SCHED_TYPE_HOURLY:
  681. case SCHED_TYPE_ONETIME:
  682. case SCHED_TYPE_ONSTART:
  683. case SCHED_TYPE_ONLOGON:
  684. case SCHED_TYPE_ONIDLE:
  685. case SCHED_TYPE_MINUTE:
  686. // -months switch is NOT APPLICABLE.
  687. if( dwMonOptCnt > 0 )
  688. {
  689. ShowMessage(stderr ,GetResString(IDS_MON_NA));
  690. return RETVAL_FAIL;
  691. }
  692. // -days switch is NOT APPLICABLE.
  693. if( dwDayOptCnt > 0 )
  694. {
  695. ShowMessage(stderr ,GetResString(IDS_DAYS_NA));
  696. return RETVAL_FAIL;
  697. }
  698. break;
  699. case SCHED_TYPE_WEEKLY:
  700. // -months field is NOT APPLICABLE for WEEKLY item.
  701. if( dwMonOptCnt > 0 )
  702. {
  703. ShowMessage(stderr ,GetResString(IDS_MON_NA));
  704. return RETVAL_FAIL;
  705. }
  706. if(dwDayOptCnt > 0)
  707. {
  708. dwRetval = ValidateDay(szDay);
  709. if( RETVAL_FAIL == dwRetval )
  710. {
  711. ShowMessage(stderr ,GetResString(IDS_INVALID_VALUE_FOR_DAY));
  712. return RETVAL_FAIL;
  713. }
  714. }
  715. return RETVAL_SUCCESS;
  716. default:
  717. break;
  718. }
  719. return RETVAL_SUCCESS;
  720. }
  721. /******************************************************************************
  722. Routine Description:
  723. This routine validates the months values specified by the user
  724. Arguments:
  725. [ in ] szMonths : Months options given by user
  726. Return Value :
  727. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  728. on failure
  729. ******************************************************************************/
  730. DWORD
  731. ValidateMonth(
  732. IN LPWSTR szMonths
  733. )
  734. {
  735. WCHAR* pMonthstoken = NULL; // For getting months.
  736. WCHAR seps[] = _T(", \n");
  737. WCHAR szMonthsList[MAX_STRING_LENGTH] = L"\0";
  738. WCHAR szTmpMonths[MAX_STRING_LENGTH] = L"\0";
  739. WCHAR szPrevTokens[MAX_TOKENS_LENGTH] = L"\0";
  740. LPCTSTR lpsz = NULL;
  741. // If the szMonths string is empty or NULL return error.
  742. if( szMonths == NULL )
  743. {
  744. return RETVAL_FAIL;
  745. }
  746. else
  747. {
  748. lpsz = szMonths;
  749. }
  750. //check for any illegal input like only ,DEC,[comma at the end of month name or before]
  751. if(*lpsz == _T(','))
  752. return RETVAL_FAIL;
  753. lpsz = _wcsdec(lpsz, lpsz + StringLength(lpsz, 0) );
  754. if( lpsz != NULL )
  755. {
  756. if( *lpsz == _T(','))
  757. return RETVAL_FAIL;
  758. }
  759. //get the valid month modifiers from the rc file
  760. StringCopy(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JAN), SIZE_OF_ARRAY(szMonthsList));
  761. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  762. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_FEB), SIZE_OF_ARRAY(szMonthsList));
  763. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  764. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_MAR), SIZE_OF_ARRAY(szMonthsList));
  765. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  766. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_APR), SIZE_OF_ARRAY(szMonthsList));
  767. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  768. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_MAY), SIZE_OF_ARRAY(szMonthsList));
  769. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  770. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JUN), SIZE_OF_ARRAY(szMonthsList));
  771. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  772. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JUL), SIZE_OF_ARRAY(szMonthsList));
  773. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  774. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_AUG), SIZE_OF_ARRAY(szMonthsList));
  775. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  776. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_SEP), SIZE_OF_ARRAY(szMonthsList));
  777. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  778. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_OCT), SIZE_OF_ARRAY(szMonthsList));
  779. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  780. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_NOV), SIZE_OF_ARRAY(szMonthsList));
  781. StringConcat(szMonthsList,_T("|"), SIZE_OF_ARRAY(szMonthsList));
  782. StringConcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_DEC), SIZE_OF_ARRAY(szMonthsList));
  783. if( InString( szMonths , szMonthsList , TRUE ) &&
  784. InString( szMonths , ASTERIX , TRUE ) )
  785. {
  786. return RETVAL_FAIL;
  787. }
  788. if( InString( szMonths , ASTERIX , TRUE ) )
  789. return RETVAL_SUCCESS;
  790. //Check for multiple commas[,] after months like FEB,,,MAR errors
  791. lpsz = szMonths;
  792. while ( StringLength ( lpsz, 0 ) )
  793. {
  794. if(*lpsz == _T(','))
  795. {
  796. lpsz = _wcsinc(lpsz);
  797. while ( ( lpsz != NULL ) && ( _istspace(*lpsz) ) )
  798. lpsz = _wcsinc(lpsz);
  799. if( lpsz != NULL )
  800. {
  801. if(*lpsz == _T(','))
  802. return RETVAL_FAIL;
  803. }
  804. }
  805. else
  806. lpsz = _wcsinc(lpsz);
  807. }
  808. StringCopy(szTmpMonths, szMonths, SIZE_OF_ARRAY(szTmpMonths));
  809. WCHAR* pPrevtoken = NULL;
  810. pMonthstoken = wcstok( szTmpMonths, seps );
  811. if( !(InString(pMonthstoken, szMonthsList, TRUE)) )
  812. return RETVAL_FAIL;
  813. if( pMonthstoken )
  814. StringCopy ( szPrevTokens, pMonthstoken, SIZE_OF_ARRAY(szPrevTokens));
  815. while( pMonthstoken != NULL )
  816. {
  817. //check if month names are replicated like MAR,MAR from user input
  818. pPrevtoken = pMonthstoken;
  819. pMonthstoken = wcstok( NULL, seps );
  820. if ( pMonthstoken == NULL)
  821. return RETVAL_SUCCESS;
  822. if( !(InString(pMonthstoken, szMonthsList, TRUE)) )
  823. return RETVAL_FAIL;
  824. if( InString(pMonthstoken,szPrevTokens, TRUE) )
  825. return RETVAL_FAIL;
  826. StringConcat( szPrevTokens, _T("|"), SIZE_OF_ARRAY(szPrevTokens));
  827. StringConcat( szPrevTokens, pMonthstoken, SIZE_OF_ARRAY(szPrevTokens));
  828. }
  829. return RETVAL_SUCCESS;
  830. }
  831. /******************************************************************************
  832. Routine Description:
  833. This routine validates the days values specified by the user
  834. Arguments:
  835. [ in ] szDays : Days options given by user
  836. Return Value :
  837. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  838. on failure
  839. ******************************************************************************/
  840. DWORD
  841. ValidateDay(
  842. IN LPWSTR szDays
  843. )
  844. {
  845. WCHAR* pDaystoken = NULL;
  846. WCHAR seps[] = _T(", \n");
  847. WCHAR szDayModifier[MAX_STRING_LENGTH ] = L"\0";
  848. WCHAR szTmpDays[MAX_STRING_LENGTH] = L"\0";
  849. //get the valid day modifiers from the rc file
  850. StringCopy(szDayModifier,GetResString(IDS_DAY_MODIFIER_SUN), SIZE_OF_ARRAY(szDayModifier));
  851. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  852. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_MON), SIZE_OF_ARRAY(szDayModifier));
  853. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  854. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_TUE), SIZE_OF_ARRAY(szDayModifier));
  855. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  856. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_WED), SIZE_OF_ARRAY(szDayModifier));
  857. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  858. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_THU), SIZE_OF_ARRAY(szDayModifier));
  859. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  860. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_FRI), SIZE_OF_ARRAY(szDayModifier));
  861. StringConcat(szDayModifier,_T("|"), SIZE_OF_ARRAY(szDayModifier));
  862. StringConcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_SAT), SIZE_OF_ARRAY(szDayModifier));
  863. //check for any illegal input like MON, or ,MON [comma at the end of day name or before]
  864. LPCTSTR lpsz = NULL;
  865. if( szDays != NULL)
  866. lpsz = szDays;
  867. else
  868. return RETVAL_FAIL;
  869. if(*lpsz == _T(','))
  870. return RETVAL_FAIL;
  871. lpsz = _wcsdec(lpsz, lpsz + StringLength(lpsz, 0) );
  872. if( lpsz != NULL )
  873. {
  874. if( *lpsz == _T(',') )
  875. return RETVAL_FAIL;
  876. }
  877. if ( ( lpsz != NULL ) && ( _istspace(*lpsz) ))
  878. {
  879. return RETVAL_FAIL;
  880. }
  881. if( (InString( szDays , szDayModifier , TRUE )) || (InString( szDays , ASTERIX , TRUE )))
  882. {
  883. return RETVAL_SUCCESS;
  884. }
  885. //Check for multiple commas[,] after days like SUN,,,TUE errors
  886. lpsz = szDays;
  887. while ( StringLength ( lpsz, 0 ) )
  888. {
  889. if(*lpsz == _T(','))
  890. {
  891. lpsz = _wcsinc(lpsz);
  892. while ( ( lpsz != NULL ) && ( _istspace(*lpsz) ))
  893. lpsz = _wcsinc(lpsz);
  894. if( lpsz != NULL )
  895. {
  896. if(*lpsz == _T(','))
  897. return RETVAL_FAIL;
  898. }
  899. }
  900. else
  901. {
  902. lpsz = _wcsinc(lpsz);
  903. }
  904. }
  905. if(szDays != NULL)
  906. {
  907. StringCopy(szTmpDays, szDays, SIZE_OF_ARRAY(szTmpDays));
  908. }
  909. // If the szDays string is empty or NULL return error.
  910. if( (StringLength(szTmpDays, 0) <= 0) )
  911. {
  912. return RETVAL_FAIL;
  913. }
  914. //WCHAR* pPrevtoken = NULL;
  915. WCHAR szPrevtokens[MAX_TOKENS_LENGTH] = L"\0";
  916. // Establish string and get the first token:
  917. pDaystoken = wcstok( szTmpDays, seps );
  918. if( pDaystoken )
  919. {
  920. StringCopy( szPrevtokens , pDaystoken, SIZE_OF_ARRAY(szPrevtokens) );
  921. }
  922. while( pDaystoken != NULL )
  923. {
  924. //check if day names are replicated like SUN,MON,SUN from user input
  925. if( !(InString(pDaystoken,szDayModifier,TRUE)) )
  926. {
  927. return RETVAL_FAIL;
  928. }
  929. pDaystoken = wcstok( NULL, seps );
  930. if( pDaystoken )
  931. {
  932. if( (InString(pDaystoken,szPrevtokens,TRUE)) )
  933. {
  934. return RETVAL_FAIL;
  935. }
  936. StringConcat( szPrevtokens , _T("|"), SIZE_OF_ARRAY(szPrevtokens) );
  937. StringConcat( szPrevtokens , pDaystoken , SIZE_OF_ARRAY(szPrevtokens));
  938. }
  939. }
  940. return RETVAL_SUCCESS;
  941. }
  942. /******************************************************************************
  943. Routine Description:
  944. This routine validates the start date specified by the user
  945. Arguments:
  946. [ in ] szStartDate : Start date specified by user
  947. [ in ] dwSchedType : Schedule type
  948. [ in ] dwStDtOptCnt : whether start date specified by the user
  949. [ out ] bIsCurrentDate : If start date not specified then startdate = current date
  950. Return Value :
  951. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  952. on failure
  953. ******************************************************************************/
  954. DWORD
  955. ValidateStartDate(
  956. IN LPWSTR szStartDate,
  957. IN DWORD dwSchedType,
  958. IN DWORD dwStDtOptCnt,
  959. OUT BOOL &bIsCurrentDate
  960. )
  961. {
  962. DWORD dwRetval = RETVAL_SUCCESS;
  963. bIsCurrentDate = FALSE; // If TRUE : Startdate should be set to Current Date.
  964. WCHAR szFormat[MAX_DATE_STR_LEN] = L"\0";
  965. if ( RETVAL_FAIL == GetDateFormatString( szFormat) )
  966. {
  967. return RETVAL_FAIL;
  968. }
  969. switch (dwSchedType)
  970. {
  971. case SCHED_TYPE_MINUTE:
  972. case SCHED_TYPE_HOURLY:
  973. case SCHED_TYPE_DAILY:
  974. case SCHED_TYPE_WEEKLY:
  975. case SCHED_TYPE_MONTHLY:
  976. case SCHED_TYPE_ONIDLE:
  977. case SCHED_TYPE_ONSTART:
  978. case SCHED_TYPE_ONLOGON:
  979. if( (dwStDtOptCnt <= 0))
  980. {
  981. bIsCurrentDate = TRUE;
  982. return RETVAL_SUCCESS;
  983. }
  984. // validate the date string
  985. dwRetval = ValidateDateString(szStartDate, TRUE );
  986. if(RETVAL_FAIL == dwRetval)
  987. {
  988. return dwRetval;
  989. }
  990. return RETVAL_SUCCESS;
  991. case SCHED_TYPE_ONETIME:
  992. if( (dwStDtOptCnt <= 0))
  993. {
  994. bIsCurrentDate = TRUE;
  995. return RETVAL_SUCCESS;
  996. }
  997. dwRetval = ValidateDateString(szStartDate, TRUE );
  998. if(RETVAL_FAIL == dwRetval)
  999. {
  1000. return dwRetval;
  1001. }
  1002. return RETVAL_SUCCESS;
  1003. default:
  1004. // validate the date string
  1005. dwRetval = ValidateDateString(szStartDate, TRUE );
  1006. if(RETVAL_FAIL == dwRetval)
  1007. {
  1008. return dwRetval;
  1009. }
  1010. return RETVAL_SUCCESS;
  1011. }
  1012. return RETVAL_FAIL;
  1013. }
  1014. /******************************************************************************
  1015. Routine Description:
  1016. This routine validates the end date specified by the user
  1017. Arguments:
  1018. [ in ] szEndDate : End date specified by user
  1019. [ in ] dwSchedType : Schedule type
  1020. [ in ] dwEndDtOptCnt : whether end date specified by the user
  1021. Return Value :
  1022. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  1023. on failure
  1024. ******************************************************************************/
  1025. DWORD
  1026. ValidateEndDate(
  1027. IN LPWSTR szEndDate,
  1028. IN DWORD dwSchedType,
  1029. IN DWORD dwEndDtOptCnt
  1030. )
  1031. {
  1032. DWORD dwRetval = RETVAL_SUCCESS; // return value
  1033. WCHAR szFormat[MAX_DATE_STR_LEN] = L"\0";
  1034. if ( RETVAL_FAIL == GetDateFormatString( szFormat) )
  1035. {
  1036. return RETVAL_FAIL;
  1037. }
  1038. switch (dwSchedType)
  1039. {
  1040. case SCHED_TYPE_MINUTE:
  1041. case SCHED_TYPE_HOURLY:
  1042. case SCHED_TYPE_DAILY:
  1043. case SCHED_TYPE_WEEKLY:
  1044. case SCHED_TYPE_MONTHLY:
  1045. if( (dwEndDtOptCnt <= 0))
  1046. {
  1047. // No default value & Value is not mandatory.. so return success.
  1048. szEndDate = L"\0"; // Set to empty string.
  1049. return RETVAL_SUCCESS;
  1050. }
  1051. // validate end date string
  1052. dwRetval = ValidateDateString(szEndDate, FALSE );
  1053. if( RETVAL_FAIL == dwRetval )
  1054. {
  1055. return dwRetval;
  1056. }
  1057. else
  1058. {
  1059. return RETVAL_SUCCESS;
  1060. }
  1061. break;
  1062. case SCHED_TYPE_ONSTART:
  1063. case SCHED_TYPE_ONLOGON:
  1064. case SCHED_TYPE_ONIDLE:
  1065. case SCHED_TYPE_ONETIME:
  1066. if( dwEndDtOptCnt > 0 )
  1067. {
  1068. // Error. End date is not applicable here, but option specified.
  1069. ShowMessage(stderr,GetResString(IDS_ENDDATE_NA));
  1070. return RETVAL_FAIL;
  1071. }
  1072. else
  1073. {
  1074. return RETVAL_SUCCESS;
  1075. }
  1076. break;
  1077. default:
  1078. // validate end date string
  1079. dwRetval = ValidateDateString(szEndDate, FALSE );
  1080. if( RETVAL_FAIL == dwRetval )
  1081. {
  1082. return dwRetval;
  1083. }
  1084. else
  1085. {
  1086. return RETVAL_SUCCESS;
  1087. }
  1088. break;
  1089. }
  1090. return RETVAL_FAIL;
  1091. }
  1092. /******************************************************************************
  1093. Routine Description:
  1094. This routine validates the start time specified by the user
  1095. Arguments:
  1096. [ in ] szStartTime : End date specified by user
  1097. [ in ] dwSchedType : Schedule type
  1098. [ in ] dwStTimeOptCnt : whether end date specified by the user
  1099. [ out ] bIsCurrentTime : Determine if start time is present else assign
  1100. to current time
  1101. Return Value :
  1102. A DWORD value indicating RETVAL_SUCCESS on success else
  1103. RETVAL_FAIL on failure
  1104. ******************************************************************************/
  1105. DWORD
  1106. ValidateStartTime(
  1107. IN LPWSTR szStartTime,
  1108. IN DWORD dwSchedType,
  1109. IN DWORD dwStTimeOptCnt,
  1110. OUT BOOL &bIsCurrentTime
  1111. )
  1112. {
  1113. DWORD dwRetval = RETVAL_SUCCESS; // return value
  1114. bIsCurrentTime = FALSE; // If TRUE : Startdate should be set to Current Date.
  1115. switch (dwSchedType)
  1116. {
  1117. case SCHED_TYPE_MINUTE:
  1118. case SCHED_TYPE_HOURLY:
  1119. case SCHED_TYPE_DAILY:
  1120. case SCHED_TYPE_WEEKLY:
  1121. case SCHED_TYPE_MONTHLY:
  1122. if( (dwStTimeOptCnt <= 0))
  1123. {
  1124. bIsCurrentTime = TRUE;
  1125. return RETVAL_SUCCESS;
  1126. }
  1127. dwRetval = ValidateTimeString(szStartTime);
  1128. if(RETVAL_FAIL == dwRetval)
  1129. {
  1130. // Error. Invalid date string.
  1131. ShowMessage(stderr,GetResString(IDS_INVALIDFORMAT_STARTTIME));
  1132. return dwRetval;
  1133. }
  1134. return RETVAL_SUCCESS;
  1135. case SCHED_TYPE_ONETIME:
  1136. dwRetval = ValidateTimeString(szStartTime);
  1137. if( (dwStTimeOptCnt <= 0))
  1138. {
  1139. // Error. Start Time is not specified.
  1140. ShowMessage(stderr,GetResString(IDS_NO_STARTTIME));
  1141. return RETVAL_FAIL;
  1142. }
  1143. else if(RETVAL_FAIL == dwRetval)
  1144. {
  1145. // Error. Invalid date string.
  1146. ShowMessage(stderr,GetResString(IDS_INVALIDFORMAT_STARTTIME));
  1147. return dwRetval;
  1148. }
  1149. return RETVAL_SUCCESS;
  1150. case SCHED_TYPE_ONSTART:
  1151. case SCHED_TYPE_ONLOGON:
  1152. case SCHED_TYPE_ONIDLE:
  1153. if( dwStTimeOptCnt > 0 )
  1154. {
  1155. // Start Time is not applicable in this option.
  1156. //But the -starttime option specified. Display error.
  1157. ShowMessage(stderr,GetResString(IDS_STARTTIME_NA));
  1158. return RETVAL_FAIL;
  1159. }
  1160. else
  1161. {
  1162. return RETVAL_SUCCESS;
  1163. }
  1164. break;
  1165. default:
  1166. // Never comes here.
  1167. break;
  1168. }
  1169. return RETVAL_FAIL;
  1170. }
  1171. /******************************************************************************
  1172. Routine Description:
  1173. This routine validates the start time specified by the user
  1174. Arguments:
  1175. [ in ] szEndTime : End time specified by user
  1176. [ in ] dwSchedType : Schedule type
  1177. [ in ] dwStTimeOptCnt : whether end time specified by the user or not
  1178. Return Value :
  1179. A DWORD value indicating RETVAL_SUCCESS on success else
  1180. RETVAL_FAIL on failure
  1181. ******************************************************************************/
  1182. DWORD
  1183. ValidateEndTime(
  1184. IN LPWSTR szEndTime,
  1185. IN DWORD dwSchedType,
  1186. IN DWORD dwEndTimeOptCnt
  1187. )
  1188. {
  1189. DWORD dwRetval = RETVAL_SUCCESS; // return value
  1190. switch (dwSchedType)
  1191. {
  1192. case SCHED_TYPE_MINUTE:
  1193. case SCHED_TYPE_HOURLY:
  1194. case SCHED_TYPE_DAILY:
  1195. case SCHED_TYPE_WEEKLY:
  1196. case SCHED_TYPE_MONTHLY:
  1197. case SCHED_TYPE_ONETIME:
  1198. dwRetval = ValidateTimeString(szEndTime);
  1199. if( ( dwEndTimeOptCnt > 0 ) && ( RETVAL_FAIL == dwRetval) )
  1200. {
  1201. // Error. Invalid date string.
  1202. ShowMessage(stderr,GetResString(IDS_INVALIDFORMAT_ENDTIME));
  1203. return dwRetval;
  1204. }
  1205. return RETVAL_SUCCESS;
  1206. case SCHED_TYPE_ONSTART:
  1207. case SCHED_TYPE_ONLOGON:
  1208. case SCHED_TYPE_ONIDLE:
  1209. if( dwEndTimeOptCnt > 0 )
  1210. {
  1211. // Start Time is not applicable in this option.
  1212. //But the -endtime option specified. Display error.
  1213. ShowMessage(stderr,GetResString(IDS_ENDTIME_NA));
  1214. return RETVAL_FAIL;
  1215. }
  1216. else
  1217. {
  1218. return RETVAL_SUCCESS;
  1219. }
  1220. break;
  1221. default:
  1222. // Never comes here.
  1223. break;
  1224. }
  1225. return RETVAL_FAIL;
  1226. }
  1227. /******************************************************************************
  1228. Routine Description:
  1229. This routine validates the idle time specified by the user
  1230. Arguments:
  1231. [ in ] szIdleTime : Ilde time specified by user
  1232. [ in ] dwSchedType : Schedule type
  1233. [ in ] dwIdlTimeOptCnt : whether Idle time specified by the user
  1234. Return Value :
  1235. A DWORD value indicating RETVAL_SUCCESS on success else
  1236. RETVAL_FAIL on failure
  1237. ******************************************************************************/
  1238. DWORD
  1239. ValidateIdleTimeVal(
  1240. IN LPWSTR szIdleTime,
  1241. IN DWORD dwSchedType,
  1242. IN DWORD dwIdlTimeOptCnt
  1243. )
  1244. {
  1245. long lIdleTime = 0;
  1246. LPWSTR pszStopString = NULL;
  1247. switch (dwSchedType)
  1248. {
  1249. case SCHED_TYPE_MINUTE:
  1250. case SCHED_TYPE_HOURLY:
  1251. case SCHED_TYPE_DAILY:
  1252. case SCHED_TYPE_WEEKLY:
  1253. case SCHED_TYPE_MONTHLY:
  1254. case SCHED_TYPE_ONSTART:
  1255. case SCHED_TYPE_ONLOGON:
  1256. case SCHED_TYPE_ONETIME:
  1257. if( dwIdlTimeOptCnt > 0 )
  1258. {
  1259. ShowMessage(stderr ,GetResString(IDS_IDLETIME_NA));
  1260. return RETVAL_FAIL;
  1261. }
  1262. else
  1263. {
  1264. return RETVAL_SUCCESS;
  1265. }
  1266. break;
  1267. case SCHED_TYPE_ONIDLE:
  1268. if( dwIdlTimeOptCnt == 0 )
  1269. {
  1270. ShowMessage(stderr,GetResString(IDS_NO_IDLETIME));
  1271. return RETVAL_FAIL;
  1272. }
  1273. lIdleTime = wcstoul(szIdleTime,&pszStopString,BASE_TEN);
  1274. if( ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))) ||
  1275. (errno == ERANGE) ||( lIdleTime <= 0 ) || ( lIdleTime > 999 ) )
  1276. {
  1277. ShowMessage(stderr,GetResString(IDS_INVALIDORNO_IDLETIME));
  1278. return RETVAL_FAIL;
  1279. }
  1280. return RETVAL_SUCCESS;
  1281. default:
  1282. break;
  1283. }
  1284. ShowMessage(stderr,GetResString(IDS_INVALIDORNO_IDLETIME));
  1285. return RETVAL_FAIL;
  1286. }
  1287. /******************************************************************************
  1288. Routine Description:
  1289. This routine validates the date string.
  1290. Arguments:
  1291. [ in ] szDate : Date string
  1292. [ in ] bStartDate : flag
  1293. Return Value :
  1294. A DWORD value indicating RETVAL_SUCCESS on success else
  1295. RETVAL_FAIL on failure
  1296. ******************************************************************************/
  1297. DWORD
  1298. ValidateDateString(
  1299. IN LPWSTR szDate,
  1300. IN BOOL bStartDate
  1301. )
  1302. {
  1303. WORD dwDate = 0;
  1304. WORD dwMon = 0;
  1305. WORD dwYear = 0;
  1306. WCHAR* szValues[1] = {NULL};//To pass to FormatMessage() API
  1307. WCHAR szFormat[MAX_DATE_STR_LEN] = L"\0";
  1308. //WCHAR szBuffer[MAX_RES_STRING] = L"\0";
  1309. if(StringLength(szDate, 0) <= 0)
  1310. {
  1311. if ( TRUE == bStartDate )
  1312. {
  1313. ShowMessage ( stderr, GetResString (IDS_STARTDATE_EMPTY) );
  1314. }
  1315. else
  1316. {
  1317. ShowMessage ( stderr, GetResString (IDS_DURATION_EMPTY) );
  1318. }
  1319. return RETVAL_FAIL;
  1320. }
  1321. if ( RETVAL_FAIL == GetDateFormatString( szFormat) )
  1322. {
  1323. return RETVAL_FAIL;
  1324. }
  1325. if( GetDateFieldEntities(szDate, &dwDate, &dwMon, &dwYear) ) // Error
  1326. {
  1327. szValues[0] = (WCHAR*) (szFormat);
  1328. if ( TRUE == bStartDate )
  1329. {
  1330. ShowMessageEx ( stderr, 1, FALSE, GetResString(IDS_INVALIDFORMAT_STARTDATE), _X(szFormat));
  1331. }
  1332. else
  1333. {
  1334. ShowMessageEx ( stderr, 1, FALSE, GetResString(IDS_INVALIDFORMAT_ENDDATE), _X(szFormat));
  1335. }
  1336. //ShowMessage(stderr, _X(szBuffer) );
  1337. return RETVAL_FAIL;
  1338. }
  1339. if( ValidateDateFields(dwDate, dwMon, dwYear) )
  1340. {
  1341. if ( TRUE == bStartDate )
  1342. {
  1343. ShowMessage(stderr, GetResString(IDS_INVALID_STARTDATE) );
  1344. }
  1345. else
  1346. {
  1347. ShowMessage(stderr, GetResString(IDS_INVALID_ENDDATE) );
  1348. }
  1349. return RETVAL_FAIL;
  1350. }
  1351. return RETVAL_SUCCESS; // return success if no error.
  1352. }
  1353. /******************************************************************************
  1354. Routine Description:
  1355. This routine retrives the date field entities out of the date string
  1356. Arguments:
  1357. [ in ] szDate : Date string
  1358. [ out ] pdwDate : Pointer to date value[1,2,3 ...30,31 etc]
  1359. [ out ] pdwMon : Pointer to Month value[1,2,3 ...12 etc]
  1360. [ out ] pdwYear : Pointer to year value[2000,3000 etc]
  1361. Return Value :
  1362. A DWORD value indicating RETVAL_SUCCESS on success else
  1363. RETVAL_FAIL on failure
  1364. ******************************************************************************/
  1365. DWORD
  1366. GetDateFieldEntities(
  1367. IN LPWSTR szDate,
  1368. OUT WORD* pdwDate,
  1369. OUT WORD* pdwMon,
  1370. OUT WORD* pdwYear
  1371. )
  1372. {
  1373. WCHAR strDate[MAX_STRING_LENGTH] = L"\0"; // Date in WCHAR type string.
  1374. WCHAR tDate[MAX_DATE_STR_LEN] = L"\0"; // Date
  1375. WCHAR tMon[MAX_DATE_STR_LEN] = L"\0"; // Month
  1376. WCHAR tYear[MAX_DATE_STR_LEN] = L"\0"; // Year
  1377. WORD wFormatID = 0;
  1378. if(szDate != NULL)
  1379. {
  1380. StringCopy(strDate, szDate, SIZE_OF_ARRAY(strDate));
  1381. }
  1382. if(StringLength(strDate, 0) <= 0)
  1383. return RETVAL_FAIL; // No value specified in szDate.
  1384. if ( RETVAL_FAIL == GetDateFieldFormat( &wFormatID ))
  1385. {
  1386. return RETVAL_FAIL;
  1387. }
  1388. if ( wFormatID == 0 || wFormatID == 1 )
  1389. {
  1390. if( (StringLength(strDate, 0) != DATESTR_LEN) ||
  1391. (strDate[FIRST_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR)
  1392. || (strDate[SECOND_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR) )
  1393. {
  1394. return RETVAL_FAIL;
  1395. }
  1396. }
  1397. else
  1398. {
  1399. if( (StringLength(strDate, 0) != DATESTR_LEN) ||
  1400. (strDate[FOURTH_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR)
  1401. || (strDate[SEVENTH_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR) )
  1402. {
  1403. return RETVAL_FAIL;
  1404. }
  1405. }
  1406. // Get the individual date field entities using wcstok function
  1407. // with respect to regional options.
  1408. if ( wFormatID == 0 )
  1409. {
  1410. StringCopy(tMon, wcstok(strDate,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tMon)); // Get the Month field.
  1411. if(StringLength(tMon, 0) > 0)
  1412. {
  1413. StringCopy(tDate, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tDate)); // Get the date field.
  1414. StringCopy(tYear, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tYear)); // Get the Year field.
  1415. }
  1416. }
  1417. else if ( wFormatID == 1 )
  1418. {
  1419. StringCopy(tDate, wcstok(strDate,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tDate)); // Get the Month field.
  1420. if(StringLength(tDate, 0) > 0)
  1421. {
  1422. StringCopy(tMon, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tMon)); // Get the date field.
  1423. StringCopy(tYear, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tYear)); // Get the Year field.
  1424. }
  1425. }
  1426. else
  1427. {
  1428. StringCopy(tYear, wcstok(strDate,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tYear)); // Get the Month field.
  1429. if(StringLength(tYear, 0) > 0)
  1430. {
  1431. StringCopy(tMon, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tMon)); // Get the date field.
  1432. StringCopy(tDate, wcstok(NULL,DATE_SEPARATOR_STR), SIZE_OF_ARRAY(tDate)); // Get the Year field.
  1433. }
  1434. }
  1435. // Now convert string values to numeric for date validations.
  1436. LPWSTR pszStopString = NULL;
  1437. *pdwDate = (WORD)wcstoul(tDate,&pszStopString,BASE_TEN);
  1438. if( (errno == ERANGE) ||
  1439. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  1440. {
  1441. return RETVAL_FAIL;
  1442. }
  1443. *pdwMon = (WORD)wcstoul(tMon,&pszStopString,BASE_TEN);
  1444. if( (errno == ERANGE) ||
  1445. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  1446. {
  1447. return RETVAL_FAIL;
  1448. }
  1449. *pdwYear = (WORD)wcstoul(tYear,&pszStopString,BASE_TEN);
  1450. if( (errno == ERANGE) ||
  1451. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  1452. {
  1453. return RETVAL_FAIL;
  1454. }
  1455. return RETVAL_SUCCESS;
  1456. }
  1457. /******************************************************************************
  1458. Routine Description:
  1459. This routine validates the date field entities
  1460. Arguments:
  1461. [ in ] dwDate : Date value[Day in a month]
  1462. [ in ] dwMon : Month constant
  1463. [ in ] dwYear : year value
  1464. Return Value :
  1465. A DWORD value indicating RETVAL_SUCCESS on success else
  1466. RETVAL_FAIL on failure
  1467. ******************************************************************************/
  1468. DWORD
  1469. ValidateDateFields(
  1470. IN DWORD dwDate,
  1471. IN DWORD dwMon,
  1472. IN DWORD dwYear
  1473. )
  1474. {
  1475. if(dwYear <= MIN_YEAR || dwYear > MAX_YEAR)
  1476. return RETVAL_FAIL;
  1477. switch(dwMon)
  1478. {
  1479. case IND_JAN:
  1480. case IND_MAR:
  1481. case IND_MAY:
  1482. case IND_JUL:
  1483. case IND_AUG:
  1484. case IND_OCT:
  1485. case IND_DEC:
  1486. if(dwDate > 0 && dwDate <= 31)
  1487. {
  1488. return RETVAL_SUCCESS;
  1489. }
  1490. break;
  1491. case IND_APR:
  1492. case IND_JUN:
  1493. case IND_SEP:
  1494. case IND_NOV:
  1495. if(dwDate > 0 && dwDate < 31)
  1496. {
  1497. return RETVAL_SUCCESS;
  1498. }
  1499. break;
  1500. case IND_FEB:
  1501. if( ((dwYear % 4) == 0) && (dwDate > 0 && dwDate <= 29) )
  1502. {
  1503. return RETVAL_SUCCESS;
  1504. }
  1505. else if( ((dwYear % 4) != 0) && (dwDate > 0 && dwDate < 29) )
  1506. {
  1507. return RETVAL_SUCCESS;
  1508. }
  1509. break;
  1510. default:
  1511. break;
  1512. }
  1513. return RETVAL_FAIL;
  1514. }
  1515. /******************************************************************************
  1516. Routine Description:
  1517. This routine validates the time specified by the user
  1518. Arguments:
  1519. [ in ] szTime : time string
  1520. Return Value :
  1521. A DWORD value indicating RETVAL_SUCCESS on success else
  1522. RETVAL_FAIL on failure
  1523. ******************************************************************************/
  1524. DWORD
  1525. ValidateTimeString(
  1526. IN LPWSTR szTime
  1527. )
  1528. {
  1529. WORD dwHours = 0;
  1530. WORD dwMins = 0;
  1531. //WORD dwSecs = 0 ;
  1532. // Check for the empty string value.
  1533. if(StringLength(szTime, 0) <= 0)
  1534. {
  1535. return RETVAL_FAIL;
  1536. }
  1537. // Get separate entities from the given time string.
  1538. if( GetTimeFieldEntities(szTime, &dwHours, &dwMins ) )
  1539. {
  1540. return RETVAL_FAIL;
  1541. }
  1542. // Validate the individual entities of the given time.
  1543. if( ValidateTimeFields( dwHours, dwMins ) )
  1544. {
  1545. return RETVAL_FAIL;
  1546. }
  1547. return RETVAL_SUCCESS;
  1548. }
  1549. /******************************************************************************
  1550. Routine Description:
  1551. This routine retrieves the different fields of time
  1552. Arguments:
  1553. [ in ] szTime : Time string
  1554. [ out ] pdwHours : pointer to hours value
  1555. [ out ] pdwMins : pointer to mins value
  1556. Return Value :
  1557. A DWORD value indicating RETVAL_SUCCESS on success else
  1558. RETVAL_FAIL on failure
  1559. ******************************************************************************/
  1560. DWORD
  1561. GetTimeFieldEntities(
  1562. IN LPWSTR szTime,
  1563. OUT WORD* pdwHours,
  1564. OUT WORD* pdwMins
  1565. )
  1566. {
  1567. WCHAR strTime[MAX_STRING_LENGTH] = L"\0" ; // Time in WCHAR type string.
  1568. WCHAR tHours[MAX_TIME_STR_LEN] = L"\0" ; // Date
  1569. WCHAR tMins[MAX_TIME_STR_LEN] = L"\0" ; // Month
  1570. //WCHAR tSecs[MAX_TIME_STR_LEN] = L"\0" ; // Year
  1571. if(StringLength(szTime, 0) <= 0)
  1572. return RETVAL_FAIL;
  1573. StringCopy(strTime, szTime, SIZE_OF_ARRAY(strTime));
  1574. //
  1575. //Start Time accepts both HH:mm:ss and HH:mm formats even though seconds are of no use..
  1576. //This feature has been supported to be in sync with XP Professional.
  1577. //
  1578. if( ((StringLength(strTime, 0) != TIMESTR_LEN) && (StringLength(strTime, 0) != TIMESTR_OPT_LEN)) ||
  1579. ((strTime[FIRST_TIMESEPARATOR_POS] != TIME_SEPARATOR_CHAR) && (strTime[SECOND_TIMESEPARATOR_POS] != TIME_SEPARATOR_CHAR)) )
  1580. {
  1581. return RETVAL_FAIL;
  1582. }
  1583. // Get the individual Time field entities using wcstok function.in the order "hh" followed by "mm" followed by "ss"
  1584. StringCopy(tHours, wcstok(strTime,TIME_SEPARATOR_STR), SIZE_OF_ARRAY(tHours)); // Get the Hours field.
  1585. if(StringLength(tHours, 0) > 0)
  1586. {
  1587. StringCopy(tMins, wcstok(NULL,TIME_SEPARATOR_STR), SIZE_OF_ARRAY(tMins)); // Get the Minutes field.
  1588. }
  1589. LPWSTR pszStopString = NULL;
  1590. // Now convert string values to numeric for time validations.
  1591. *pdwHours = (WORD)wcstoul(tHours,&pszStopString,BASE_TEN);
  1592. if( (errno == ERANGE) ||
  1593. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  1594. {
  1595. return RETVAL_FAIL;
  1596. }
  1597. *pdwMins = (WORD)wcstoul(tMins,&pszStopString,BASE_TEN);
  1598. if( (errno == ERANGE) ||
  1599. ((pszStopString != NULL) && (StringLength( pszStopString, 0 ))))
  1600. {
  1601. return RETVAL_FAIL;
  1602. }
  1603. return RETVAL_SUCCESS;
  1604. }
  1605. /******************************************************************************
  1606. Routine Description:
  1607. This routine validates the time fields of a given time
  1608. Arguments:
  1609. [ in ] dwHours :Hours value
  1610. [ in ] dwMins :Minutes value
  1611. [ in ] dwSecs : seconds value
  1612. Return Value :
  1613. A DWORD value indicating RETVAL_SUCCESS on success else
  1614. RETVAL_FAIL on failure
  1615. ******************************************************************************/
  1616. DWORD
  1617. ValidateTimeFields(
  1618. IN DWORD dwHours,
  1619. IN DWORD dwMins
  1620. )
  1621. {
  1622. if ( dwHours <= HOURS_PER_DAY_MINUS_ONE )
  1623. {
  1624. if ( dwMins < MINUTES_PER_HOUR )
  1625. {
  1626. return RETVAL_SUCCESS;
  1627. }
  1628. else
  1629. {
  1630. return RETVAL_FAIL;
  1631. }
  1632. }
  1633. else
  1634. {
  1635. return RETVAL_FAIL;
  1636. }
  1637. }
  1638. /******************************************************************************
  1639. Routine Description:
  1640. This routine validates the time fields of a given time
  1641. Arguments:
  1642. [ in ] szDay : time string
  1643. Return Value :
  1644. A WORD value containing the day constant [TASK_SUNDAY,TASK_MONDAY etc]
  1645. ******************************************************************************/
  1646. WORD
  1647. GetTaskTrigwDayForDay(
  1648. IN LPWSTR szDay
  1649. )
  1650. {
  1651. WCHAR szDayBuff[MAX_RES_STRING] = L"\0";
  1652. WCHAR *token = NULL;
  1653. WCHAR seps[] = _T(" ,\n");
  1654. WORD dwRetval = 0;
  1655. SYSTEMTIME systime = {0,0,0,0,0,0,0,0};
  1656. if(StringLength(szDay, 0) != 0)
  1657. {
  1658. StringCopy(szDayBuff, szDay, SIZE_OF_ARRAY(szDayBuff));
  1659. }
  1660. // if /D is not specified.. set the default day to current day..
  1661. if( StringLength(szDayBuff, 0) <= 0 )
  1662. {
  1663. GetLocalTime (&systime);
  1664. switch ( systime.wDayOfWeek )
  1665. {
  1666. case 0:
  1667. return TASK_SUNDAY;
  1668. case 1:
  1669. return TASK_MONDAY;
  1670. case 2:
  1671. return TASK_TUESDAY;
  1672. case 3:
  1673. return TASK_WEDNESDAY;
  1674. case 4:
  1675. return TASK_THURSDAY;
  1676. case 5:
  1677. return TASK_FRIDAY;
  1678. case 6:
  1679. return TASK_SATURDAY;
  1680. default:
  1681. break;
  1682. }
  1683. }
  1684. token = wcstok( szDayBuff, seps );
  1685. while( token != NULL )
  1686. {
  1687. if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_SUN ), TRUE, 0)) )
  1688. dwRetval |= (TASK_SUNDAY);
  1689. else if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_MON ), TRUE, 0)) )
  1690. dwRetval |= (TASK_MONDAY);
  1691. else if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_TUE ), TRUE, 0)) )
  1692. dwRetval |= (TASK_TUESDAY);
  1693. else if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_WED ), TRUE, 0)) )
  1694. dwRetval |= (TASK_WEDNESDAY);
  1695. else if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_THU ), TRUE, 0)) )
  1696. dwRetval |= (TASK_THURSDAY);
  1697. else if( !(StringCompare(token,GetResString( IDS_DAY_MODIFIER_FRI ), TRUE, 0)) )
  1698. dwRetval |= (TASK_FRIDAY);
  1699. else if( !(StringCompare(token, GetResString( IDS_DAY_MODIFIER_SAT ), TRUE, 0)) )
  1700. dwRetval |= (TASK_SATURDAY);
  1701. else if( !(StringCompare(token, ASTERIX, TRUE, 0)) )
  1702. return (TASK_SUNDAY | TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY |
  1703. TASK_THURSDAY | TASK_FRIDAY | TASK_SATURDAY);
  1704. else
  1705. return 0;
  1706. token = wcstok( NULL, seps );
  1707. }
  1708. return dwRetval;
  1709. }
  1710. /******************************************************************************
  1711. Routine Description:
  1712. This routine validates the time fields of a given time
  1713. Arguments:
  1714. [ in ] szMonth : Month string
  1715. Return Value :
  1716. A WORD value containing the Month constant
  1717. [TASK_JANUARY,TASK_FEBRUARY etc]
  1718. ******************************************************************************/
  1719. WORD
  1720. GetTaskTrigwMonthForMonth(
  1721. IN LPWSTR szMonth
  1722. )
  1723. {
  1724. WCHAR *token = NULL;
  1725. WORD dwRetval = 0;
  1726. WCHAR strMon[MAX_TOKENS_LENGTH] = L"\0";
  1727. WCHAR seps[] = _T(" ,\n");
  1728. if( StringLength(szMonth, 0) <= 0 )
  1729. {
  1730. return (TASK_JANUARY | TASK_FEBRUARY | TASK_MARCH | TASK_APRIL | TASK_MAY | TASK_JUNE |
  1731. TASK_JULY | TASK_AUGUST | TASK_SEPTEMBER | TASK_OCTOBER
  1732. | TASK_NOVEMBER | TASK_DECEMBER );
  1733. }
  1734. StringCopy(strMon, szMonth, SIZE_OF_ARRAY(strMon));
  1735. token = wcstok( szMonth, seps );
  1736. while( token != NULL )
  1737. {
  1738. if( !(StringCompare(token, ASTERIX, TRUE, 0)) )
  1739. return (TASK_JANUARY | TASK_FEBRUARY | TASK_MARCH | TASK_APRIL
  1740. | TASK_MAY | TASK_JUNE | TASK_JULY | TASK_AUGUST | TASK_SEPTEMBER | TASK_OCTOBER
  1741. | TASK_NOVEMBER | TASK_DECEMBER );
  1742. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JAN ), TRUE, 0)) )
  1743. dwRetval |= (TASK_JANUARY);
  1744. else if( !(StringCompare(token,GetResString( IDS_MONTH_MODIFIER_FEB ), TRUE, 0)) )
  1745. dwRetval |= (TASK_FEBRUARY);
  1746. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_MAR ), TRUE, 0)) )
  1747. dwRetval |= (TASK_MARCH);
  1748. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_APR ), TRUE, 0)) )
  1749. dwRetval |= (TASK_APRIL);
  1750. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_MAY ), TRUE, 0)) )
  1751. dwRetval |= (TASK_MAY);
  1752. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JUN ), TRUE, 0)) )
  1753. dwRetval |= (TASK_JUNE);
  1754. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JUL ), TRUE, 0)) )
  1755. dwRetval |= (TASK_JULY);
  1756. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_AUG ), TRUE, 0)) )
  1757. dwRetval |= (TASK_AUGUST);
  1758. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_SEP ), TRUE, 0)) )
  1759. dwRetval |= (TASK_SEPTEMBER);
  1760. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_OCT ), TRUE, 0)) )
  1761. dwRetval |= (TASK_OCTOBER);
  1762. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_NOV ), TRUE, 0)) )
  1763. dwRetval |= (TASK_NOVEMBER);
  1764. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_DEC ), TRUE, 0)) )
  1765. dwRetval |= (TASK_DECEMBER);
  1766. else
  1767. return 0;
  1768. token = wcstok( NULL, seps );
  1769. }
  1770. return dwRetval;
  1771. }
  1772. /******************************************************************************
  1773. Routine Description:
  1774. This routine returns the corresponding month flag
  1775. Arguments:
  1776. [ in ] dwMonthId : Month index
  1777. Return Value :
  1778. A WORD value containing the Month constant
  1779. [TASK_JANUARY,TASK_FEBRUARY etc]
  1780. ******************************************************************************/
  1781. WORD
  1782. GetMonthId(
  1783. IN DWORD dwMonthId
  1784. )
  1785. {
  1786. DWORD dwMonthsArr[] = {TASK_JANUARY,TASK_FEBRUARY ,TASK_MARCH ,TASK_APRIL ,
  1787. TASK_MAY ,TASK_JUNE ,TASK_JULY ,TASK_AUGUST,
  1788. TASK_SEPTEMBER ,TASK_OCTOBER ,TASK_NOVEMBER ,TASK_DECEMBER } ;
  1789. DWORD wMonthFlags = 0;
  1790. DWORD dwMod = 0;
  1791. dwMod = dwMonthId - 1;
  1792. while(dwMod < 12)
  1793. {
  1794. wMonthFlags |= dwMonthsArr[dwMod];
  1795. dwMod = dwMod + dwMonthId;
  1796. }
  1797. return (WORD)wMonthFlags;
  1798. }
  1799. /******************************************************************************
  1800. Routine Description:
  1801. This routine returns the maximum Last day in the months specifed
  1802. Arguments:
  1803. [ in ] szMonths : string containing months specified by user
  1804. [ in ] wStartYear : string containing start year
  1805. Return Value :
  1806. A DWORD value specifying the maximum last day in the specified months
  1807. ******************************************************************************/
  1808. DWORD
  1809. GetNumDaysInaMonth(
  1810. IN WCHAR* szMonths,
  1811. IN WORD wStartYear
  1812. )
  1813. {
  1814. DWORD dwDays = 31;//max.no of days in a month
  1815. BOOL bMaxDays = FALSE;//if any of the months have 31 then days of value 31 is returned
  1816. if( ( StringLength(szMonths, 0) == 0 ) || ( StringCompare(szMonths,ASTERIX, TRUE, 0) == 0 ) )
  1817. return dwDays; //All months[default]
  1818. WCHAR *token = NULL;
  1819. WCHAR strMon[MAX_MONTH_STR_LEN] = L"\0";
  1820. WCHAR seps[] = _T(" ,\n");
  1821. StringCopy(strMon, szMonths, SIZE_OF_ARRAY(strMon));
  1822. token = wcstok( strMon, seps );
  1823. while( token != NULL )
  1824. {
  1825. if( !(StringCompare(token,GetResString( IDS_MONTH_MODIFIER_FEB ), TRUE, 0)) )
  1826. {
  1827. if( ( (wStartYear % 400) == 0) ||
  1828. ( ( (wStartYear % 4) == 0) &&
  1829. ( (wStartYear % 100) != 0) ) )
  1830. {
  1831. dwDays = 29;
  1832. }
  1833. else
  1834. {
  1835. dwDays = 28;
  1836. }
  1837. }
  1838. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JAN ), TRUE, 0)) )
  1839. {
  1840. bMaxDays = TRUE;
  1841. }
  1842. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_MAR ), TRUE, 0)) )
  1843. {
  1844. bMaxDays = TRUE;
  1845. }
  1846. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_MAY ), TRUE, 0)) )
  1847. {
  1848. bMaxDays = TRUE;
  1849. }
  1850. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JUL ), TRUE, 0)) )
  1851. {
  1852. bMaxDays = TRUE;
  1853. }
  1854. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_AUG ), TRUE, 0)) )
  1855. {
  1856. bMaxDays = TRUE;
  1857. }
  1858. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_OCT ), TRUE, 0)) )
  1859. {
  1860. bMaxDays = TRUE;
  1861. }
  1862. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_DEC ), TRUE, 0)) )
  1863. {
  1864. bMaxDays = TRUE;
  1865. }
  1866. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_APR ), TRUE, 0)) )
  1867. {
  1868. dwDays = 30;
  1869. }
  1870. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_JUN ), TRUE, 0)) )
  1871. {
  1872. dwDays = 30;
  1873. }
  1874. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_SEP ), TRUE, 0)) )
  1875. {
  1876. dwDays = 30;
  1877. }
  1878. else if( !(StringCompare(token, GetResString( IDS_MONTH_MODIFIER_NOV ), TRUE, 0)) )
  1879. {
  1880. dwDays = 30;
  1881. }
  1882. token = wcstok( NULL, seps );
  1883. }
  1884. if (bMaxDays == TRUE)
  1885. {
  1886. return 31;
  1887. }
  1888. else
  1889. {
  1890. return dwDays;
  1891. }
  1892. }
  1893. /******************************************************************************
  1894. Routine Description:
  1895. This routine checks the validates the taskname of the task to be created.
  1896. Arguments:
  1897. [ in ] pszJobName : Pointer to the job[task] name
  1898. Return Value :
  1899. If valid task name then TRUE else FALSE
  1900. ******************************************************************************/
  1901. BOOL
  1902. VerifyJobName(
  1903. IN WCHAR* pszJobName
  1904. )
  1905. {
  1906. WCHAR szTokens[] = {_T('<'),_T('>'),_T(':'),_T('/'),_T('\\'),_T('|')};
  1907. if( wcspbrk(pszJobName,szTokens) == NULL)
  1908. {
  1909. return TRUE;
  1910. }
  1911. else
  1912. {
  1913. return FALSE;
  1914. }
  1915. }
  1916. /******************************************************************************
  1917. Routine Description:
  1918. This routine gets the date format value with respective to regional options.
  1919. Arguments:
  1920. [ out ] pdwFormat : Date format value.
  1921. Return Value :
  1922. Returns RETVAL_FAIL on failure and RETVAL_SUCCESS on success.
  1923. ******************************************************************************/
  1924. DWORD
  1925. GetDateFieldFormat(
  1926. OUT WORD* pwFormat
  1927. )
  1928. {
  1929. LCID lcid;
  1930. WCHAR szBuffer[MAX_BUF_SIZE];
  1931. //Get the user default locale in the users computer
  1932. lcid = GetUserDefaultLCID();
  1933. //Get the date format
  1934. if (GetLocaleInfo(lcid, LOCALE_IDATE, szBuffer, MAX_BUF_SIZE))
  1935. {
  1936. switch (szBuffer[0])
  1937. {
  1938. case TEXT('0'):
  1939. *pwFormat = 0;
  1940. break;
  1941. case TEXT('1'):
  1942. *pwFormat = 1;
  1943. break;
  1944. case TEXT('2'):
  1945. *pwFormat = 2;
  1946. break;
  1947. default:
  1948. return RETVAL_FAIL;
  1949. }
  1950. }
  1951. return RETVAL_SUCCESS;
  1952. }
  1953. /******************************************************************************
  1954. Routine Description:
  1955. This routine gets the date format string with respective to regional options.
  1956. Arguments:
  1957. [ out ] szFormat : Date format string.
  1958. Return Value :
  1959. Returns RETVAL_FAIL on failure and RETVAL_SUCCESS on success.
  1960. ******************************************************************************/
  1961. DWORD
  1962. GetDateFormatString(
  1963. IN LPWSTR szFormat
  1964. )
  1965. {
  1966. WORD wFormatID = 0;
  1967. if ( RETVAL_FAIL == GetDateFieldFormat( &wFormatID ))
  1968. {
  1969. return RETVAL_FAIL;
  1970. }
  1971. if ( wFormatID == 0 )
  1972. {
  1973. StringCopy (szFormat, GetResString(IDS_MMDDYY_FORMAT), MAX_STRING_LENGTH);
  1974. }
  1975. else if ( wFormatID == 1 )
  1976. {
  1977. StringCopy (szFormat, GetResString( IDS_DDMMYY_FORMAT), MAX_STRING_LENGTH);
  1978. }
  1979. else if ( wFormatID == 2 )
  1980. {
  1981. StringCopy (szFormat, GetResString(IDS_YYMMDD_FORMAT), MAX_STRING_LENGTH);
  1982. }
  1983. else
  1984. {
  1985. return RETVAL_FAIL;
  1986. }
  1987. return RETVAL_SUCCESS;
  1988. }