Source code of Windows XP (NT5)
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.

2102 lines
52 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. [ in ] tcresubops : Structure containing the task's properties
  32. [ in ] 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(TCREATESUBOPTS& tcresubops, TCREATEOPVALS &tcreoptvals,
  41. TCMDPARSER cmdOptions[], DWORD dwScheduleType)
  42. {
  43. DWORD dwRetval = RETVAL_SUCCESS;
  44. BOOL bIsStDtCurDt = FALSE;
  45. BOOL bIsStTimeCurTime = FALSE;
  46. BOOL bIsDefltValMod = FALSE;
  47. // Validate whether -s, -u, -p options specified correctly or not.
  48. //Accept password if -p not specified.
  49. if( dwRetval = ValidateRemoteSysInfo( tcresubops.szServer, tcresubops.szUser,
  50. tcresubops.szPassword, cmdOptions, tcresubops, tcreoptvals) )
  51. return dwRetval; // Error.
  52. // Validate Modifier value.
  53. if( dwRetval = ValidateModifierVal( tcresubops.szModifier, dwScheduleType,
  54. cmdOptions[OI_MODIFIER].dwActuals,
  55. cmdOptions[OI_DAY].dwActuals,
  56. cmdOptions[OI_MONTHS].dwActuals,
  57. bIsDefltValMod) )
  58. {
  59. return dwRetval; // error in modifier value
  60. }
  61. else
  62. {
  63. if(bIsDefltValMod)
  64. lstrcpy(tcresubops.szModifier,DEFAULT_MODIFIER_SZ);
  65. }
  66. // Validate Day and Month strings
  67. if ( dwRetval = ValidateDayAndMonth( tcresubops.szDays, tcresubops.szMonths,
  68. dwScheduleType,
  69. cmdOptions[OI_DAY].dwActuals,
  70. cmdOptions[OI_MONTHS].dwActuals,
  71. cmdOptions[OI_MODIFIER].dwActuals,
  72. tcresubops.szModifier) )
  73. {
  74. return dwRetval; // Error found in Day/Month string.
  75. }
  76. // Validate Start Date value.
  77. if ( dwRetval = ValidateStartDate( tcresubops.szStartDate, dwScheduleType,
  78. cmdOptions[OI_STARTDATE].dwActuals,
  79. bIsStDtCurDt) )
  80. {
  81. return dwRetval; // Error in Day/Month string.
  82. }
  83. else
  84. {
  85. if(bIsStDtCurDt) // Set start date to current date.
  86. tcreoptvals.bSetStartDateToCurDate = TRUE;
  87. }
  88. // Validate End Date value.
  89. if ( dwRetval = ValidateEndDate( tcresubops.szEndDate, dwScheduleType,
  90. cmdOptions[OI_ENDDATE].dwActuals) )
  91. {
  92. return dwRetval; // Error in Day/Month string.
  93. }
  94. //Check Whether end date should be greater than startdate
  95. WORD wEndDay = 0;
  96. WORD wEndMonth = 0;
  97. WORD wEndYear = 0;
  98. WORD wStartDay = 0;
  99. WORD wStartMonth = 0;
  100. WORD wStartYear = 0;
  101. WORD wFormatID = 0;
  102. if( cmdOptions[OI_ENDDATE].dwActuals != 0 )
  103. {
  104. if( RETVAL_FAIL == GetDateFieldEntities( tcresubops.szEndDate,&wEndDay,
  105. &wEndMonth,&wEndYear))
  106. {
  107. return S_FALSE;
  108. }
  109. }
  110. SYSTEMTIME systime = {0,0,0,0,0,0,0,0};
  111. if(bIsStDtCurDt)
  112. {
  113. GetLocalTime(&systime);
  114. wStartDay = systime.wDay;
  115. wStartMonth = systime.wMonth;
  116. wStartYear = systime.wYear;
  117. }
  118. else if( ( cmdOptions[OI_STARTDATE].dwActuals != 0 ) &&
  119. (RETVAL_FAIL == GetDateFieldEntities(tcresubops.szStartDate,
  120. &wStartDay,&wStartMonth,
  121. &wStartYear)))
  122. {
  123. return S_FALSE;
  124. }
  125. if( (cmdOptions[OI_ENDDATE].dwActuals != 0) )
  126. {
  127. if( ( wEndYear == wStartYear ) )
  128. {
  129. // For same years if the end month is less than start month or for same years and same months
  130. // if the endday is less than the startday.
  131. if ( ( wEndMonth < wStartMonth ) || ( ( wEndMonth == wStartMonth ) && ( wEndDay < wStartDay ) ) )
  132. {
  133. DISPLAY_MESSAGE(stderr, GetResString(IDS_ENDATE_INVALID));
  134. return RETVAL_FAIL;
  135. }
  136. }
  137. else if ( wEndYear < wStartYear )
  138. {
  139. DISPLAY_MESSAGE(stderr, GetResString(IDS_ENDATE_INVALID));
  140. return RETVAL_FAIL;
  141. }
  142. }
  143. // Validate Start Time value.
  144. if ( dwRetval = ValidateStartTime( tcresubops.szStartTime, dwScheduleType,
  145. cmdOptions[OI_STARTTIME].dwActuals,
  146. bIsStTimeCurTime) )
  147. {
  148. return dwRetval; // Error found in starttime.
  149. }
  150. else
  151. {
  152. if(bIsStTimeCurTime)
  153. tcreoptvals.bSetStartTimeToCurTime = TRUE;
  154. }
  155. // Validate Idle Time value.
  156. if ( dwRetval = ValidateIdleTimeVal( tcresubops.szIdleTime, dwScheduleType,
  157. cmdOptions[OI_IDLETIME].dwActuals) )
  158. {
  159. return dwRetval;
  160. }
  161. return RETVAL_SUCCESS;
  162. }
  163. /******************************************************************************
  164. Routine Description:
  165. This routine validates the options specified by the user reg.create
  166. option for remote server.
  167. Arguments:
  168. [ in ] szServer : Server name
  169. [ in ] szUser : User name
  170. [ in ] szPassword : Password
  171. [ in ] cmdOptions : TCMDPARSER Array containg the options given by the user
  172. [ in ] tcreoptvals: Structure containing optional values to set
  173. Return Value :
  174. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  175. on failure
  176. ******************************************************************************/
  177. DWORD ValidateRemoteSysInfo(LPTSTR szServer, LPTSTR szUser, LPTSTR szPassword,
  178. TCMDPARSER cmdOptions[], TCREATESUBOPTS& tcresubops, TCREATEOPVALS& tcreoptvals)
  179. {
  180. // "-rp" should not be specified without "-ru"
  181. if ( ( ( cmdOptions[ OI_RUNASUSERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_RUNASPASSWORD ].dwActuals == 1 ) ) ||
  182. ( ( cmdOptions[ OI_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_PASSWORD ].dwActuals == 1 ) ) ||
  183. ( ( cmdOptions[ OI_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_PASSWORD ].dwActuals == 1 ) ) ||
  184. ( ( cmdOptions[ OI_RUNASUSERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_PASSWORD ].dwActuals == 1 ) ) ||
  185. ( ( cmdOptions[ OI_USERNAME ].dwActuals == 0 ) && ( cmdOptions[ OI_RUNASUSERNAME ].dwActuals == 0 ) &&
  186. ( cmdOptions[ OI_RUNASPASSWORD ].dwActuals == 1 ) && ( cmdOptions[ OI_PASSWORD ].dwActuals == 1 ) ) )
  187. {
  188. // invalid syntax
  189. DISPLAY_MESSAGE(stderr, GetResString(IDS_CPASSWORD_BUT_NOUSERNAME));
  190. return RETVAL_FAIL; // indicate failure
  191. }
  192. if ( IsLocalSystem( tcresubops.szServer ) == TRUE )
  193. {
  194. tcreoptvals.bPassword = TRUE;
  195. }
  196. // check whether the password (-p) specified in the command line or not
  197. // and also check whether '*' or empty is given for -p or not
  198. if( cmdOptions[ OI_PASSWORD ].dwActuals == 1 )
  199. {
  200. if ( IsLocalSystem( tcresubops.szServer ) == FALSE )
  201. {
  202. if( lstrcmpi (tcresubops.szPassword, ASTERIX) == 0 )
  203. {
  204. tcreoptvals.bPassword = FALSE;
  205. }
  206. else
  207. {
  208. tcreoptvals.bPassword = TRUE;
  209. }
  210. }
  211. }
  212. if( ( cmdOptions[ OI_RUNASPASSWORD ].dwActuals == 1 ) )
  213. {
  214. tcreoptvals.bRunAsPassword = TRUE;
  215. }
  216. return RETVAL_SUCCESS;
  217. }
  218. /******************************************************************************
  219. Routine Description:
  220. This routine validates & determines the modifier value .
  221. Arguments:
  222. [ in ] szModifier : Modifer value
  223. [ in ] dwScheduleType : Type of schedule[Daily,once,weekly etc]
  224. [ in ] dwModOptActCnt : Modifier optional value
  225. [ in ] dwDayOptCnt : Days value
  226. [ in ] dwMonOptCnt : Months value
  227. [ out ] bIsDefltValMod : Whether default value should be given for modifier
  228. Return Value :
  229. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  230. on failure
  231. ******************************************************************************/
  232. DWORD
  233. ValidateModifierVal(LPCTSTR szModifier, DWORD dwScheduleType,
  234. DWORD dwModOptActCnt, DWORD dwDayOptCnt,
  235. DWORD dwMonOptCnt, BOOL& bIsDefltValMod
  236. )
  237. {
  238. TCHAR szDayType[MAX_RES_STRING];
  239. DWORD dwModifier = 0;
  240. lstrcpy(szDayType,GetResString(IDS_TASK_FIRSTWEEK));
  241. lstrcat(szDayType,_T("|"));
  242. lstrcat(szDayType,GetResString(IDS_TASK_SECONDWEEK));
  243. lstrcat(szDayType,_T("|"));
  244. lstrcat(szDayType,GetResString(IDS_TASK_THIRDWEEK));
  245. lstrcat(szDayType,_T("|"));
  246. lstrcat(szDayType,GetResString(IDS_TASK_FOURTHWEEK));
  247. lstrcat(szDayType,_T("|"));
  248. lstrcat(szDayType,GetResString(IDS_TASK_LASTWEEK));
  249. bIsDefltValMod = FALSE; // If TRUE : Set modifier to default value, 1.
  250. LPTSTR pszStopString = NULL;
  251. switch( dwScheduleType )
  252. {
  253. case SCHED_TYPE_MINUTE: // Schedule type is Minute
  254. if( (dwModOptActCnt <= 0) || (lstrlen(szModifier) < 0) )
  255. {
  256. bIsDefltValMod = TRUE;
  257. return RETVAL_SUCCESS;
  258. }
  259. dwModifier = _tcstoul(szModifier,&pszStopString,BASE_TEN);
  260. if( lstrlen( pszStopString ))
  261. break;
  262. if( dwModifier > 0 && dwModifier < 1440 ) // Valid Range 1 - 1439
  263. return RETVAL_SUCCESS;
  264. break;
  265. // Schedule type is Hourly
  266. case SCHED_TYPE_HOURLY:
  267. if( (dwModOptActCnt <= 0) || (lstrlen(szModifier) < 0) )
  268. {
  269. bIsDefltValMod = TRUE;
  270. return RETVAL_SUCCESS;
  271. }
  272. dwModifier = _tcstoul(szModifier,&pszStopString,BASE_TEN);
  273. if( lstrlen( pszStopString ) )
  274. break;
  275. if( dwModifier > 0 && dwModifier < 24 ) // Valid Range 1 - 23
  276. return RETVAL_SUCCESS;
  277. break;
  278. // Schedule type is Daily
  279. case SCHED_TYPE_DAILY:
  280. // -days option is NOT APPLICABLE for DAILY type item.
  281. if( (dwDayOptCnt > 0) )
  282. {// Invalid sysntax. Return error
  283. // Modifier option and days options both should not specified same time.
  284. bIsDefltValMod = FALSE;
  285. DISPLAY_MESSAGE(stderr, GetResString(IDS_DAYS_NA));
  286. return RETVAL_FAIL;
  287. }
  288. // -months option is NOT APPLICABLE for DAILY type item.
  289. if( dwMonOptCnt > 0 )
  290. {// Invalid sysntax. Return error
  291. // Modifier option and days options both should not specified same time.
  292. bIsDefltValMod = FALSE;
  293. DISPLAY_MESSAGE(stderr , GetResString(IDS_MON_NA));
  294. return RETVAL_FAIL;
  295. }
  296. // Check whether the -modifier switch is psecified. If not, then take default value.
  297. if( (dwModOptActCnt <= 0) || (lstrlen(szModifier) < 0) )
  298. {
  299. // Modifier options is not specified. So, set it to default value. (i.e, 1 )
  300. bIsDefltValMod = TRUE;
  301. return RETVAL_SUCCESS;
  302. }
  303. dwModifier = _tcstoul(szModifier,&pszStopString,BASE_TEN);
  304. if( lstrlen( pszStopString ) )
  305. break;
  306. // If the -modifier option is specified, then validate the value.
  307. if( dwModifier > 0 && dwModifier < 366 ) // Valid Range 1 - 365
  308. {
  309. return RETVAL_SUCCESS;
  310. }
  311. else
  312. {
  313. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_MODIFIER));
  314. return RETVAL_FAIL;
  315. }
  316. break;
  317. // Schedule type is Weekly
  318. case SCHED_TYPE_WEEKLY:
  319. // If -modifier option is not specified, then set it to default value.
  320. if( (dwModOptActCnt <= 0) || (lstrlen(szModifier) < 0) )
  321. {
  322. // Modifier options is not specified. So, set it to default value. (i.e, 1 )
  323. bIsDefltValMod = TRUE;
  324. return RETVAL_SUCCESS;
  325. }
  326. if( dwModOptActCnt > 0)
  327. {
  328. dwModifier = _tcstoul(szModifier,&pszStopString,BASE_TEN);
  329. if( lstrlen( pszStopString ) )
  330. break;
  331. if( dwModifier > 0 && dwModifier < 53 ) // Valid Range 1 - 52
  332. return RETVAL_SUCCESS;
  333. break;
  334. }
  335. break;
  336. // Schedule type is Monthly
  337. case SCHED_TYPE_MONTHLY:
  338. // If -modifier option is not specified, then set it to default value.
  339. if( ( dwModOptActCnt > 0) && (lstrlen(szModifier) == 0) )
  340. {
  341. // Modifier option is not proper. So display error and return false.
  342. bIsDefltValMod = FALSE;
  343. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_MODIFIER));
  344. return RETVAL_FAIL;
  345. }
  346. //check if the modifier is LASTDAY[not case sensitive]
  347. if( lstrcmpi( szModifier , GetResString( IDS_DAY_MODIFIER_LASTDAY ) ) == 0)
  348. return RETVAL_SUCCESS;
  349. //Check if -mo is in between FIRST,SECOND ,THIRD, LAST
  350. //then -days[ MON to SUN ] is applicable , -months is also applicable
  351. if( InString ( szModifier , szDayType , TRUE ) )
  352. {
  353. return RETVAL_SUCCESS;
  354. }
  355. else
  356. {
  357. dwModifier = _tcstoul(szModifier,&pszStopString,BASE_TEN);
  358. if( lstrlen( pszStopString ) )
  359. break;
  360. if( ( dwModOptActCnt == 1 ) && ( dwModifier < 1 || dwModifier > 12 ) ) //check whether -mo value is in between 1 - 12
  361. {
  362. //invalid -mo value
  363. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_MODIFIER));
  364. return RETVAL_FAIL;
  365. }
  366. return RETVAL_SUCCESS;
  367. }
  368. break;
  369. case SCHED_TYPE_ONETIME:
  370. case SCHED_TYPE_ONSTART:
  371. case SCHED_TYPE_ONLOGON:
  372. case SCHED_TYPE_ONIDLE:
  373. if( dwModOptActCnt <= 0 )
  374. {
  375. // Modifier option is not applicable. So, return success.
  376. bIsDefltValMod = FALSE;
  377. return RETVAL_SUCCESS;
  378. }
  379. else
  380. {
  381. // Modifier option is not applicable. But specified. So, return error.
  382. bIsDefltValMod = FALSE;
  383. DISPLAY_MESSAGE(stderr, GetResString(IDS_MODIFIER_NA));
  384. return RETVAL_FAIL;
  385. }
  386. break;
  387. default:
  388. return RETVAL_FAIL;
  389. }
  390. // Modifier option is not proper. So display error and return false.
  391. bIsDefltValMod = FALSE;
  392. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_MODIFIER));
  393. return RETVAL_FAIL;
  394. }
  395. /******************************************************************************
  396. Routine Description:
  397. This routine validates & determines the day,month value .
  398. Arguments:
  399. [ in ] szDay : Day value
  400. [ in ] szMonths : Months[Daily,once,weekly etc]
  401. [ in ] dwSchedType : Modifier optional value
  402. [ in ] dwDayOptCnt : Days option value
  403. [ in ] dwMonOptCnt : Months option value
  404. [ in ] dwOptModifier : Modifier option value
  405. [ in ] szModifier : Whether default value for modifier
  406. Return Value :
  407. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  408. on failure
  409. ******************************************************************************/
  410. DWORD
  411. ValidateDayAndMonth(LPTSTR szDay, LPTSTR szMonths, DWORD dwSchedType,
  412. DWORD dwDayOptCnt,DWORD dwMonOptCnt, DWORD dwOptModifier, LPTSTR szModifier)
  413. {
  414. DWORD dwRetval = 0;
  415. DWORD dwModifier = 0;
  416. DWORD dwDays = 0;
  417. TCHAR szDayModifier[MAX_RES_STRING] = NULL_STRING;
  418. //get the valid week day modifiers from the rc file
  419. lstrcpy(szDayModifier,GetResString(IDS_TASK_FIRSTWEEK));
  420. lstrcat(szDayModifier,_T("|"));
  421. lstrcat(szDayModifier,GetResString(IDS_TASK_SECONDWEEK));
  422. lstrcat(szDayModifier,_T("|"));
  423. lstrcat(szDayModifier,GetResString(IDS_TASK_THIRDWEEK));
  424. lstrcat(szDayModifier,_T("|"));
  425. lstrcat(szDayModifier,GetResString(IDS_TASK_FOURTHWEEK));
  426. lstrcat(szDayModifier,_T("|"));
  427. lstrcat(szDayModifier,GetResString(IDS_TASK_LASTWEEK));
  428. switch (dwSchedType)
  429. {
  430. case SCHED_TYPE_DAILY:
  431. // -days and -months optons is not applicable. SO, check for it.
  432. if( dwDayOptCnt > 0 || dwMonOptCnt > 0)
  433. {
  434. return RETVAL_FAIL;
  435. }
  436. return RETVAL_SUCCESS;
  437. break;
  438. case SCHED_TYPE_MONTHLY:
  439. if( dwMonOptCnt > 0 && lstrlen(szMonths) == 0)
  440. {
  441. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_VALUE_FOR_MON));
  442. return RETVAL_FAIL;
  443. }
  444. //if the modifier is LASTDAY
  445. if( lstrcmpi( szModifier , GetResString( IDS_DAY_MODIFIER_LASTDAY ) ) == 0)
  446. {
  447. //-day is not applicable for this case only -months is applicable
  448. if( dwDayOptCnt > 0 )
  449. {
  450. DISPLAY_MESSAGE(stderr, GetResString(IDS_DAYS_NA));
  451. return RETVAL_FAIL;
  452. }
  453. if(lstrlen(szMonths))
  454. {
  455. if( ( ValidateMonth( szMonths ) == RETVAL_SUCCESS ) ||
  456. InString( szMonths, ASTERIX, TRUE ) )
  457. {
  458. return RETVAL_SUCCESS;
  459. }
  460. else
  461. {
  462. DISPLAY_MESSAGE(stderr , GetResString(IDS_INVALID_VALUE_FOR_MON));
  463. return RETVAL_FAIL;
  464. }
  465. }
  466. else
  467. {
  468. DISPLAY_MESSAGE(stderr ,GetResString(IDS_NO_MONTH_VALUE));
  469. return RETVAL_FAIL;
  470. }
  471. }
  472. // If -day is specified then check whether the day value is valid or not.
  473. if( InString( szDay, ASTERIX, TRUE) )
  474. {
  475. DISPLAY_MESSAGE(stderr ,GetResString(IDS_INVALID_VALUE_FOR_DAY));
  476. return RETVAL_FAIL;
  477. }
  478. if(( lstrlen (szDay ) == 0 ) && InString(szModifier, szDayModifier, TRUE))
  479. {
  480. DISPLAY_MESSAGE(stderr, GetResString(IDS_NO_DAY_VALUE));
  481. return RETVAL_FAIL;
  482. }
  483. if( dwDayOptCnt )
  484. {
  485. dwModifier = (DWORD) AsLong(szModifier, BASE_TEN);
  486. //check for multiples days,if then return error
  487. if ( _tcspbrk ( szDay , COMMA_STRING ) )
  488. {
  489. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  490. return RETVAL_FAIL;
  491. }
  492. if( ValidateDay( szDay ) == RETVAL_SUCCESS )
  493. {
  494. //Check the modifier value should be in FIRST, SECOND, THIRD, FOURTH, LAST OR LASTDAY etc..
  495. if(!( InString(szModifier, szDayModifier, TRUE) ) )
  496. {
  497. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  498. return RETVAL_FAIL;
  499. }
  500. }
  501. else
  502. {
  503. dwDays = (DWORD) AsLong(szDay, BASE_TEN);
  504. if( ( dwDays < 1 ) || ( dwDays > 31 ) )
  505. {
  506. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  507. return RETVAL_FAIL;
  508. }
  509. if( ( dwOptModifier == 1 ) && ( ( dwModifier < 1 ) || ( dwModifier > 12 ) ) )
  510. {
  511. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_MODIFIER));
  512. return RETVAL_FAIL;
  513. }
  514. if( InString(szModifier, szDayModifier, TRUE) )
  515. {
  516. DISPLAY_MESSAGE(stderr, GetResString(IDS_INVALID_VALUE_FOR_DAY));
  517. return RETVAL_FAIL;
  518. }
  519. if(dwMonOptCnt && lstrlen(szModifier))
  520. {
  521. DISPLAY_MESSAGE(stderr ,GetResString(IDS_INVALID_VALUE_FOR_MON));
  522. return RETVAL_FAIL;
  523. }
  524. }
  525. } //end of dwDayOptCnt
  526. if(lstrlen(szMonths))
  527. {
  528. if( lstrlen(szModifier) )
  529. {
  530. dwModifier = (DWORD) AsLong(szModifier, BASE_TEN);
  531. if(dwModifier >= 1 && dwModifier <= 12)
  532. {
  533. DISPLAY_MESSAGE( stderr ,GetResString(IDS_MON_NA));
  534. return RETVAL_FAIL;
  535. }
  536. }
  537. if( ( ValidateMonth( szMonths ) == RETVAL_SUCCESS ) ||
  538. InString( szMonths, ASTERIX, TRUE ) )
  539. {
  540. return RETVAL_SUCCESS;
  541. }
  542. else
  543. {
  544. DISPLAY_MESSAGE(stderr ,GetResString(IDS_INVALID_VALUE_FOR_MON));
  545. return RETVAL_FAIL;
  546. }
  547. }
  548. // assgin default values for month,day
  549. return RETVAL_SUCCESS;
  550. case SCHED_TYPE_HOURLY:
  551. case SCHED_TYPE_ONETIME:
  552. case SCHED_TYPE_ONSTART:
  553. case SCHED_TYPE_ONLOGON:
  554. case SCHED_TYPE_ONIDLE:
  555. case SCHED_TYPE_MINUTE:
  556. // -months switch is NOT APPLICABLE.
  557. if( dwMonOptCnt > 0 )
  558. {
  559. DISPLAY_MESSAGE(stderr ,GetResString(IDS_MON_NA));
  560. return RETVAL_FAIL;
  561. }
  562. // -days switch is NOT APPLICABLE.
  563. if( dwDayOptCnt > 0 )
  564. {
  565. DISPLAY_MESSAGE(stderr ,GetResString(IDS_DAYS_NA));
  566. return RETVAL_FAIL;
  567. }
  568. break;
  569. case SCHED_TYPE_WEEKLY:
  570. // -months field is NOT APPLICABLE for WEEKLY item.
  571. if( dwMonOptCnt > 0 )
  572. {
  573. DISPLAY_MESSAGE(stderr ,GetResString(IDS_MON_NA));
  574. return RETVAL_FAIL;
  575. }
  576. if(dwDayOptCnt > 0)
  577. {
  578. if( dwRetval = ValidateDay(szDay) )
  579. {
  580. DISPLAY_MESSAGE(stderr ,GetResString(IDS_INVALID_VALUE_FOR_DAY));
  581. return RETVAL_FAIL;
  582. }
  583. }
  584. return RETVAL_SUCCESS;
  585. default:
  586. break;
  587. }
  588. return RETVAL_SUCCESS;
  589. }
  590. /******************************************************************************
  591. Routine Description:
  592. This routine validates the months values specified by the user
  593. Arguments:
  594. [ in ] szMonths : Months options given by user
  595. Return Value :
  596. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  597. on failure
  598. ******************************************************************************/
  599. DWORD
  600. ValidateMonth(LPTSTR szMonths)
  601. {
  602. _TCHAR* pMonthstoken = NULL; // For getting months.
  603. _TCHAR seps[] = _T(", \n");
  604. _TCHAR szMonthsList[MAX_STRING_LENGTH] = NULL_STRING;
  605. _TCHAR szTmpMonths[MAX_STRING_LENGTH] = NULL_STRING;
  606. _TCHAR szPrevTokens[MAX_TOKENS_LENGTH] = NULL_STRING;
  607. LPCTSTR lpsz = NULL;
  608. // If the szMonths string is empty or NULL return error.
  609. if( szMonths == NULL )
  610. {
  611. return RETVAL_FAIL;
  612. }
  613. else
  614. {
  615. lpsz = szMonths;
  616. }
  617. //check for any illegal input like only ,DEC,[comma at the end of month name or before]
  618. if(*lpsz == _T(','))
  619. return RETVAL_FAIL;
  620. lpsz = _tcsdec(lpsz, lpsz + _tcslen(lpsz) );
  621. if( lpsz != NULL )
  622. {
  623. if( *lpsz == _T(','))
  624. return RETVAL_FAIL;
  625. }
  626. //get the valid month modifiers from the rc file
  627. lstrcpy(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JAN));
  628. lstrcat(szMonthsList,_T("|"));
  629. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_FEB));
  630. lstrcat(szMonthsList,_T("|"));
  631. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_MAR));
  632. lstrcat(szMonthsList,_T("|"));
  633. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_APR));
  634. lstrcat(szMonthsList,_T("|"));
  635. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_MAY));
  636. lstrcat(szMonthsList,_T("|"));
  637. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JUN));
  638. lstrcat(szMonthsList,_T("|"));
  639. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_JUL));
  640. lstrcat(szMonthsList,_T("|"));
  641. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_AUG));
  642. lstrcat(szMonthsList,_T("|"));
  643. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_SEP));
  644. lstrcat(szMonthsList,_T("|"));
  645. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_OCT));
  646. lstrcat(szMonthsList,_T("|"));
  647. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_NOV));
  648. lstrcat(szMonthsList,_T("|"));
  649. lstrcat(szMonthsList,GetResString(IDS_MONTH_MODIFIER_DEC));
  650. if( InString( szMonths , szMonthsList , TRUE ) &&
  651. InString( szMonths , ASTERIX , TRUE ) )
  652. {
  653. return RETVAL_FAIL;
  654. }
  655. if( InString( szMonths , ASTERIX , TRUE ) )
  656. return RETVAL_SUCCESS;
  657. //Check for multiple commas[,] after months like FEB,,,MAR errors
  658. lpsz = szMonths;
  659. while ( lstrlen ( lpsz ) )
  660. {
  661. if(*lpsz == _T(','))
  662. {
  663. lpsz = _tcsinc(lpsz);
  664. while ( ( lpsz != NULL ) && ( _istspace(*lpsz) ) )
  665. lpsz = _tcsinc(lpsz);
  666. if( lpsz != NULL )
  667. {
  668. if(*lpsz == _T(','))
  669. return RETVAL_FAIL;
  670. }
  671. }
  672. else
  673. lpsz = _tcsinc(lpsz);
  674. }
  675. lstrcpy(szTmpMonths, szMonths);
  676. _TCHAR* pPrevtoken = NULL;
  677. pMonthstoken = _tcstok( szTmpMonths, seps );
  678. if( !(InString(pMonthstoken, szMonthsList, TRUE)) )
  679. return RETVAL_FAIL;
  680. if( pMonthstoken )
  681. lstrcpy ( szPrevTokens, pMonthstoken);
  682. while( pMonthstoken != NULL )
  683. {
  684. //check if month names are replicated like MAR,MAR from user input
  685. pPrevtoken = pMonthstoken;
  686. pMonthstoken = _tcstok( NULL, seps );
  687. if ( pMonthstoken == NULL)
  688. return RETVAL_SUCCESS;
  689. if( !(InString(pMonthstoken, szMonthsList, TRUE)) )
  690. return RETVAL_FAIL;
  691. if( InString(pMonthstoken,szPrevTokens, TRUE) )
  692. return RETVAL_FAIL;
  693. lstrcat( szPrevTokens, _T("|"));
  694. lstrcat( szPrevTokens, pMonthstoken);
  695. }
  696. return RETVAL_SUCCESS;
  697. }
  698. /******************************************************************************
  699. Routine Description:
  700. This routine validates the days values specified by the user
  701. Arguments:
  702. [ in ] szDays : Days options given by user
  703. Return Value :
  704. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  705. on failure
  706. ******************************************************************************/
  707. DWORD
  708. ValidateDay(LPTSTR szDays)
  709. {
  710. TCHAR* pDaystoken = NULL;
  711. TCHAR seps[] = _T(", \n");
  712. TCHAR szDayModifier[MAX_STRING_LENGTH ] = NULL_STRING;
  713. TCHAR szTmpDays[MAX_STRING_LENGTH] = NULL_STRING;
  714. //get the valid day modifiers from the rc file
  715. lstrcpy(szDayModifier,GetResString(IDS_DAY_MODIFIER_SUN));
  716. lstrcat(szDayModifier,_T("|"));
  717. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_MON));
  718. lstrcat(szDayModifier,_T("|"));
  719. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_TUE));
  720. lstrcat(szDayModifier,_T("|"));
  721. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_WED));
  722. lstrcat(szDayModifier,_T("|"));
  723. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_THU));
  724. lstrcat(szDayModifier,_T("|"));
  725. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_FRI));
  726. lstrcat(szDayModifier,_T("|"));
  727. lstrcat(szDayModifier,GetResString(IDS_DAY_MODIFIER_SAT));
  728. //check for any illegal input like MON, or ,MON [comma at the end of day name or before]
  729. LPCTSTR lpsz = NULL;
  730. if( szDays != NULL)
  731. lpsz = szDays;
  732. else
  733. return RETVAL_FAIL;
  734. if(*lpsz == _T(','))
  735. return RETVAL_FAIL;
  736. lpsz = _tcsdec(lpsz, lpsz + _tcslen(lpsz) );
  737. if( lpsz != NULL )
  738. {
  739. if( *lpsz == _T(',') )
  740. return RETVAL_FAIL;
  741. }
  742. if ( ( lpsz != NULL ) && ( _istspace(*lpsz) ))
  743. {
  744. return RETVAL_FAIL;
  745. }
  746. if( (InString( szDays , szDayModifier , TRUE )) || (InString( szDays , ASTERIX , TRUE )))
  747. {
  748. return RETVAL_SUCCESS;
  749. }
  750. //Check for multiple commas[,] after days like SUN,,,TUE errors
  751. lpsz = szDays;
  752. while ( lstrlen ( lpsz ) )
  753. {
  754. if(*lpsz == _T(','))
  755. {
  756. lpsz = _tcsinc(lpsz);
  757. while ( ( lpsz != NULL ) && ( _istspace(*lpsz) ))
  758. lpsz = _tcsinc(lpsz);
  759. if( lpsz != NULL )
  760. {
  761. if(*lpsz == _T(','))
  762. return RETVAL_FAIL;
  763. }
  764. }
  765. else
  766. {
  767. lpsz = _tcsinc(lpsz);
  768. }
  769. }
  770. if(szDays != NULL)
  771. lstrcpy(szTmpDays, szDays);
  772. // If the szDays string is empty or NULL return error.
  773. if( (lstrlen(szTmpDays) <= 0) )
  774. {
  775. return RETVAL_FAIL;
  776. }
  777. //_TCHAR* pPrevtoken = NULL;
  778. _TCHAR szPrevtokens[MAX_TOKENS_LENGTH] = NULL_STRING;
  779. // Establish string and get the first token:
  780. pDaystoken = _tcstok( szTmpDays, seps );
  781. if( pDaystoken )
  782. lstrcpy( szPrevtokens , pDaystoken );
  783. while( pDaystoken != NULL )
  784. {
  785. //check if day names are replicated like SUN,MON,SUN from user input
  786. if( !(InString(pDaystoken,szDayModifier,TRUE)) )
  787. {
  788. return RETVAL_FAIL;
  789. }
  790. pDaystoken = _tcstok( NULL, seps );
  791. if( pDaystoken )
  792. {
  793. if( (InString(pDaystoken,szPrevtokens,TRUE)) )
  794. {
  795. return RETVAL_FAIL;
  796. }
  797. lstrcat( szPrevtokens , _T("|") );
  798. lstrcat( szPrevtokens , pDaystoken );
  799. }
  800. }
  801. return RETVAL_SUCCESS;
  802. }
  803. /******************************************************************************
  804. Routine Description:
  805. This routine validates the start date specified by the user
  806. Arguments:
  807. [ in ] szStartDate : Start date specified by user
  808. [ in ] dwSchedType : Schedule type
  809. [ in ] dwStDtOptCnt : whether start date specified by the user
  810. [ out ] bIsCurrentDate : If start date not specified then startdate = current date
  811. Return Value :
  812. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  813. on failure
  814. ******************************************************************************/
  815. DWORD
  816. ValidateStartDate(LPTSTR szStartDate, DWORD dwSchedType, DWORD dwStDtOptCnt,
  817. BOOL &bIsCurrentDate)
  818. {
  819. DWORD dwRetval = RETVAL_SUCCESS;
  820. bIsCurrentDate = FALSE; // If TRUE : Startdate should be set to Current Date.
  821. TCHAR szBuffer[MAX_STRING_LENGTH] = NULL_STRING;
  822. _TCHAR* szValues[1] = {NULL};//To pass to FormatMessage() API
  823. TCHAR szFormat[MAX_DATE_STR_LEN] = NULL_STRING;
  824. if ( RETVAL_FAIL == GetDateFormatString( szFormat) )
  825. {
  826. return RETVAL_FAIL;
  827. }
  828. switch (dwSchedType)
  829. {
  830. case SCHED_TYPE_MINUTE:
  831. case SCHED_TYPE_HOURLY:
  832. case SCHED_TYPE_DAILY:
  833. case SCHED_TYPE_WEEKLY:
  834. case SCHED_TYPE_MONTHLY:
  835. case SCHED_TYPE_ONIDLE:
  836. case SCHED_TYPE_ONSTART:
  837. case SCHED_TYPE_ONLOGON:
  838. if( (dwStDtOptCnt <= 0))
  839. {
  840. bIsCurrentDate = TRUE;
  841. return RETVAL_SUCCESS;
  842. }
  843. if(dwRetval = ValidateDateString(szStartDate))
  844. {
  845. szValues[0] = (_TCHAR*) (szFormat);
  846. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  847. GetResString(IDS_INVALIDFORMAT_STARTDATE),0,MAKELANGID(LANG_NEUTRAL,
  848. SUBLANG_DEFAULT),szBuffer,
  849. MAX_STRING_LENGTH,(va_list*)szValues );
  850. DISPLAY_MESSAGE(stderr, szBuffer);
  851. return dwRetval;
  852. }
  853. return RETVAL_SUCCESS;
  854. case SCHED_TYPE_ONETIME:
  855. if( (dwStDtOptCnt <= 0))
  856. {
  857. bIsCurrentDate = TRUE;
  858. return RETVAL_SUCCESS;
  859. }
  860. if( (dwRetval = ValidateDateString(szStartDate)))
  861. {
  862. szValues[0] = (_TCHAR*) (szFormat);
  863. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  864. GetResString(IDS_INVALIDFORMAT_STARTDATE),0,MAKELANGID(LANG_NEUTRAL,
  865. SUBLANG_DEFAULT),szBuffer,
  866. MAX_STRING_LENGTH,(va_list*)szValues );
  867. DISPLAY_MESSAGE(stderr, szBuffer);
  868. return dwRetval;
  869. }
  870. return RETVAL_SUCCESS;
  871. default:
  872. break;
  873. }
  874. return RETVAL_FAIL;
  875. }
  876. /******************************************************************************
  877. Routine Description:
  878. This routine validates the end date specified by the user
  879. Arguments:
  880. [ in ] szEndDate : End date specified by user
  881. [ in ] dwSchedType : Schedule type
  882. [ in ] dwEndDtOptCnt : whether end date specified by the user
  883. Return Value :
  884. A DWORD value indicating RETVAL_SUCCESS on success else RETVAL_FAIL
  885. on failure
  886. ******************************************************************************/
  887. DWORD
  888. ValidateEndDate(LPTSTR szEndDate, DWORD dwSchedType, DWORD dwEndDtOptCnt)
  889. {
  890. DWORD dwRetval = RETVAL_SUCCESS; // return value
  891. TCHAR szFormat[MAX_DATE_STR_LEN] = NULL_STRING;
  892. _TCHAR* szValues[1] = {NULL};//To pass to FormatMessage() API
  893. TCHAR szBuffer[MAX_STRING_LENGTH] = NULL_STRING;
  894. if ( RETVAL_FAIL == GetDateFormatString( szFormat) )
  895. {
  896. return RETVAL_FAIL;
  897. }
  898. switch (dwSchedType)
  899. {
  900. case SCHED_TYPE_MINUTE:
  901. case SCHED_TYPE_HOURLY:
  902. case SCHED_TYPE_DAILY:
  903. case SCHED_TYPE_WEEKLY:
  904. case SCHED_TYPE_MONTHLY:
  905. if( (dwEndDtOptCnt <= 0))
  906. {
  907. // No default value & Value is not mandatory.. so return success.
  908. szEndDate = NULL_STRING; // Set to empty string.
  909. return RETVAL_SUCCESS;
  910. }
  911. if(dwRetval = ValidateDateString(szEndDate))
  912. {
  913. szValues[0] = (_TCHAR*) (szFormat);
  914. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  915. GetResString(IDS_INVALIDFORMAT_ENDDATE),0,MAKELANGID(LANG_NEUTRAL,
  916. SUBLANG_DEFAULT),szBuffer,
  917. MAX_STRING_LENGTH,(va_list*)szValues );
  918. DISPLAY_MESSAGE(stderr, szBuffer);
  919. return dwRetval;
  920. }
  921. else
  922. {
  923. return RETVAL_SUCCESS;
  924. }
  925. break;
  926. case SCHED_TYPE_ONSTART:
  927. case SCHED_TYPE_ONLOGON:
  928. case SCHED_TYPE_ONIDLE:
  929. case SCHED_TYPE_ONETIME:
  930. if( dwEndDtOptCnt > 0 )
  931. {
  932. // Error. End date is not applicable here, but option specified.
  933. DISPLAY_MESSAGE(stderr,GetResString(IDS_ENDDATE_NA));
  934. return RETVAL_FAIL;
  935. }
  936. else
  937. {
  938. return RETVAL_SUCCESS;
  939. }
  940. break;
  941. default:
  942. // Never comes here.
  943. break;
  944. }
  945. return RETVAL_FAIL;
  946. }
  947. /******************************************************************************
  948. Routine Description:
  949. This routine validates the start time specified by the user
  950. Arguments:
  951. [ in ] szStartTime : End date specified by user
  952. [ in ] dwSchedType : Schedule type
  953. [ in ] dwStTimeOptCnt : whether end date specified by the user
  954. [ out ] bIsCurrentTime : Determine if start time is present else assign
  955. to current time
  956. Return Value :
  957. A DWORD value indicating RETVAL_SUCCESS on success else
  958. RETVAL_FAIL on failure
  959. ******************************************************************************/
  960. DWORD
  961. ValidateStartTime(LPTSTR szStartTime, DWORD dwSchedType, DWORD dwStTimeOptCnt,
  962. BOOL &bIsCurrentTime)
  963. {
  964. DWORD dwRetval = RETVAL_SUCCESS; // return value
  965. bIsCurrentTime = FALSE; // If TRUE : Startdate should be set to Current Date.
  966. switch (dwSchedType)
  967. {
  968. case SCHED_TYPE_MINUTE:
  969. case SCHED_TYPE_HOURLY:
  970. case SCHED_TYPE_DAILY:
  971. case SCHED_TYPE_WEEKLY:
  972. case SCHED_TYPE_MONTHLY:
  973. if( (dwStTimeOptCnt <= 0))
  974. {
  975. bIsCurrentTime = TRUE;
  976. return RETVAL_SUCCESS;
  977. }
  978. if(dwRetval = ValidateTimeString(szStartTime))
  979. {
  980. // Error. Invalid date string.
  981. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALIDFORMAT_STARTTIME));
  982. return dwRetval;
  983. }
  984. return RETVAL_SUCCESS;
  985. case SCHED_TYPE_ONETIME:
  986. if( (dwStTimeOptCnt <= 0))
  987. {
  988. // Error. Start Time is not specified.
  989. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_STARTTIME));
  990. return RETVAL_FAIL;
  991. }
  992. else if(dwRetval = ValidateTimeString(szStartTime))
  993. {
  994. // Error. Invalid date string.
  995. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALIDFORMAT_STARTTIME));
  996. return dwRetval;
  997. }
  998. return RETVAL_SUCCESS;
  999. case SCHED_TYPE_ONSTART:
  1000. case SCHED_TYPE_ONLOGON:
  1001. case SCHED_TYPE_ONIDLE:
  1002. if( dwStTimeOptCnt > 0 )
  1003. {
  1004. // Start Time is not applicable in this option.
  1005. //But the -starttime option specified. Display error.
  1006. DISPLAY_MESSAGE(stderr,GetResString(IDS_STARTTIME_NA));
  1007. return RETVAL_FAIL;
  1008. }
  1009. else
  1010. {
  1011. return RETVAL_SUCCESS;
  1012. }
  1013. break;
  1014. default:
  1015. // Never comes here.
  1016. break;
  1017. }
  1018. return RETVAL_FAIL;
  1019. }
  1020. /******************************************************************************
  1021. Routine Description:
  1022. This routine validates the idle time specified by the user
  1023. Arguments:
  1024. [ in ] szIdleTime : Ilde time specified by user
  1025. [ in ] dwSchedType : Schedule type
  1026. [ in ] dwIdlTimeOptCnt : whether Idle time specified by the user
  1027. Return Value :
  1028. A DWORD value indicating RETVAL_SUCCESS on success else
  1029. RETVAL_FAIL on failure
  1030. ******************************************************************************/
  1031. DWORD
  1032. ValidateIdleTimeVal(LPTSTR szIdleTime, DWORD dwSchedType,
  1033. DWORD dwIdlTimeOptCnt)
  1034. {
  1035. long lIdleTime = 0;
  1036. LPTSTR pszStopString = NULL;
  1037. switch (dwSchedType)
  1038. {
  1039. case SCHED_TYPE_MINUTE:
  1040. case SCHED_TYPE_HOURLY:
  1041. case SCHED_TYPE_DAILY:
  1042. case SCHED_TYPE_WEEKLY:
  1043. case SCHED_TYPE_MONTHLY:
  1044. case SCHED_TYPE_ONSTART:
  1045. case SCHED_TYPE_ONLOGON:
  1046. case SCHED_TYPE_ONETIME:
  1047. if( dwIdlTimeOptCnt > 0 )
  1048. {
  1049. DISPLAY_MESSAGE(stderr ,GetResString(IDS_IDLETIME_NA));
  1050. return RETVAL_FAIL;
  1051. }
  1052. else
  1053. {
  1054. return RETVAL_SUCCESS;
  1055. }
  1056. break;
  1057. case SCHED_TYPE_ONIDLE:
  1058. if( dwIdlTimeOptCnt == 0 )
  1059. {
  1060. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_IDLETIME));
  1061. return RETVAL_FAIL;
  1062. }
  1063. lIdleTime = _tcstoul(szIdleTime,&pszStopString,BASE_TEN);
  1064. if( lstrlen( pszStopString ) || ( lIdleTime <= 0 ) || ( lIdleTime > 999 ) )
  1065. {
  1066. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALIDORNO_IDLETIME));
  1067. return RETVAL_FAIL;
  1068. }
  1069. return RETVAL_SUCCESS;
  1070. default:
  1071. break;
  1072. }
  1073. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALIDORNO_IDLETIME));
  1074. return RETVAL_FAIL;
  1075. }
  1076. /******************************************************************************
  1077. Routine Description:
  1078. This routine validates the date string.
  1079. Arguments:
  1080. [ in ] szDate : Date string
  1081. Return Value :
  1082. A DWORD value indicating RETVAL_SUCCESS on success else
  1083. RETVAL_FAIL on failure
  1084. ******************************************************************************/
  1085. DWORD
  1086. ValidateDateString(LPTSTR szDate)
  1087. {
  1088. WORD dwDate = 0;
  1089. WORD dwMon = 0;
  1090. WORD dwYear = 0;
  1091. if(lstrlen(szDate) <= 0)
  1092. {
  1093. return RETVAL_FAIL;
  1094. }
  1095. if( GetDateFieldEntities(szDate, &dwDate, &dwMon, &dwYear) ) // Error
  1096. {
  1097. return RETVAL_FAIL;
  1098. }
  1099. if( ValidateDateFields(dwDate, dwMon, dwYear) )
  1100. {
  1101. return RETVAL_FAIL;
  1102. }
  1103. return RETVAL_SUCCESS; // return success if no error.
  1104. }
  1105. /******************************************************************************
  1106. Routine Description:
  1107. This routine retrives the date field entities out of the date string
  1108. Arguments:
  1109. [ in ] szDate : Date string
  1110. [ out ] pdwDate : Pointer to date value[1,2,3 ...30,31 etc]
  1111. [ out ] pdwMon : Pointer to Month value[1,2,3 ...12 etc]
  1112. [ out ] pdwYear : Pointer to year value[2000,3000 etc]
  1113. Return Value :
  1114. A DWORD value indicating RETVAL_SUCCESS on success else
  1115. RETVAL_FAIL on failure
  1116. ******************************************************************************/
  1117. DWORD
  1118. GetDateFieldEntities(LPTSTR szDate, WORD* pdwDate, WORD* pdwMon, WORD* pdwYear)
  1119. {
  1120. _TCHAR strDate[MAX_STRING_LENGTH] = NULL_STRING; // Date in _TCHAR type string.
  1121. _TCHAR tDate[MAX_DATE_STR_LEN] = NULL_STRING; // Date
  1122. _TCHAR tMon[MAX_DATE_STR_LEN] = NULL_STRING; // Month
  1123. _TCHAR tYear[MAX_DATE_STR_LEN] = NULL_STRING; // Year
  1124. WORD wFormatID = 0;
  1125. if(szDate != NULL)
  1126. lstrcpy(strDate,szDate);
  1127. if(lstrlen(strDate) <= 0)
  1128. return RETVAL_FAIL; // No value specified in szDate.
  1129. if ( RETVAL_FAIL == GetDateFieldFormat( &wFormatID ))
  1130. {
  1131. return RETVAL_FAIL;
  1132. }
  1133. if ( wFormatID == 0 || wFormatID == 1 )
  1134. {
  1135. if( (lstrlen(strDate) != DATESTR_LEN) ||
  1136. (strDate[FIRST_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR)
  1137. || (strDate[SECOND_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR) )
  1138. {
  1139. return RETVAL_FAIL;
  1140. }
  1141. }
  1142. else
  1143. {
  1144. if( (lstrlen(strDate) != DATESTR_LEN) ||
  1145. (strDate[FOURTH_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR)
  1146. || (strDate[SEVENTH_DATESEPARATOR_POS] != DATE_SEPARATOR_CHAR) )
  1147. {
  1148. return RETVAL_FAIL;
  1149. }
  1150. }
  1151. // Get the individual date field entities using _tcstok function
  1152. // with respect to regional options.
  1153. if ( wFormatID == 0 )
  1154. {
  1155. lstrcpy(tMon, _tcstok(strDate,DATE_SEPARATOR_STR)); // Get the Month field.
  1156. if(lstrlen(tMon) > 0)
  1157. {
  1158. lstrcpy(tDate, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the date field.
  1159. lstrcpy(tYear, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the Year field.
  1160. }
  1161. }
  1162. else if ( wFormatID == 1 )
  1163. {
  1164. lstrcpy(tDate, _tcstok(strDate,DATE_SEPARATOR_STR)); // Get the Month field.
  1165. if(lstrlen(tDate) > 0)
  1166. {
  1167. lstrcpy(tMon, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the date field.
  1168. lstrcpy(tYear, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the Year field.
  1169. }
  1170. }
  1171. else
  1172. {
  1173. lstrcpy(tYear, _tcstok(strDate,DATE_SEPARATOR_STR)); // Get the Month field.
  1174. if(lstrlen(tYear) > 0)
  1175. {
  1176. lstrcpy(tMon, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the date field.
  1177. lstrcpy(tDate, _tcstok(NULL,DATE_SEPARATOR_STR)); // Get the Year field.
  1178. }
  1179. }
  1180. // Now convert string values to numeric for date validations.
  1181. LPTSTR pszStopString = NULL;
  1182. *pdwDate = (WORD)_tcstoul(tDate,&pszStopString,BASE_TEN);
  1183. if( lstrlen( pszStopString ))
  1184. return RETVAL_FAIL;
  1185. *pdwMon = (WORD)_tcstoul(tMon,&pszStopString,BASE_TEN);
  1186. if( lstrlen( pszStopString ))
  1187. return RETVAL_FAIL;
  1188. *pdwYear = (WORD)_tcstoul(tYear,&pszStopString,BASE_TEN);
  1189. if( lstrlen( pszStopString ))
  1190. return RETVAL_FAIL;
  1191. return RETVAL_SUCCESS;
  1192. }
  1193. /******************************************************************************
  1194. Routine Description:
  1195. This routine validates the date field entities
  1196. Arguments:
  1197. [ in ] dwDate : Date value[Day in a month]
  1198. [ in ] dwMon : Month constant
  1199. [ in ] dwYear : year value
  1200. Return Value :
  1201. A DWORD value indicating RETVAL_SUCCESS on success else
  1202. RETVAL_FAIL on failure
  1203. ******************************************************************************/
  1204. DWORD
  1205. ValidateDateFields( DWORD dwDate, DWORD dwMon, DWORD dwYear)
  1206. {
  1207. if(dwYear < MIN_YEAR || dwYear > MAX_YEAR)
  1208. return RETVAL_FAIL;
  1209. switch(dwMon)
  1210. {
  1211. case IND_JAN:
  1212. case IND_MAR:
  1213. case IND_MAY:
  1214. case IND_JUL:
  1215. case IND_AUG:
  1216. case IND_OCT:
  1217. case IND_DEC:
  1218. if(dwDate > 0 && dwDate <= 31)
  1219. {
  1220. return RETVAL_SUCCESS;
  1221. }
  1222. break;
  1223. case IND_APR:
  1224. case IND_JUN:
  1225. case IND_SEP:
  1226. case IND_NOV:
  1227. if(dwDate > 0 && dwDate < 31)
  1228. {
  1229. return RETVAL_SUCCESS;
  1230. }
  1231. break;
  1232. case IND_FEB:
  1233. if( ((dwYear % 4) == 0) && (dwDate > 0 && dwDate <= 29) )
  1234. {
  1235. return RETVAL_SUCCESS;
  1236. }
  1237. else if( ((dwYear % 4) != 0) && (dwDate > 0 && dwDate < 29) )
  1238. {
  1239. return RETVAL_SUCCESS;
  1240. }
  1241. break;
  1242. default:
  1243. break;
  1244. }
  1245. return RETVAL_FAIL;
  1246. }
  1247. /******************************************************************************
  1248. Routine Description:
  1249. This routine validates the time specified by the user
  1250. Arguments:
  1251. [ in ] szTime : time string
  1252. Return Value :
  1253. A DWORD value indicating RETVAL_SUCCESS on success else
  1254. RETVAL_FAIL on failure
  1255. ******************************************************************************/
  1256. DWORD
  1257. ValidateTimeString(LPTSTR szTime)
  1258. {
  1259. WORD dwHours = 0;
  1260. WORD dwMins = 0;
  1261. WORD dwSecs = 0 ;
  1262. // Check for the empty string value.
  1263. if(lstrlen(szTime) <= 0)
  1264. {
  1265. return RETVAL_FAIL;
  1266. }
  1267. // Get separate entities from the given time string.
  1268. if( GetTimeFieldEntities(szTime, &dwHours, &dwMins, &dwSecs) )
  1269. {
  1270. return RETVAL_FAIL;
  1271. }
  1272. // Validate the individual entities of the given time.
  1273. if( ValidateTimeFields(dwHours, dwMins, dwSecs) )
  1274. {
  1275. return RETVAL_FAIL;
  1276. }
  1277. return RETVAL_SUCCESS;
  1278. }
  1279. /******************************************************************************
  1280. Routine Description:
  1281. This routine retrieves the different fields of time
  1282. Arguments:
  1283. [ in ] szTime : Time string
  1284. [ out ] pdwHours : pointer to hours value
  1285. [ out ] pdwMins : pointer to mins value
  1286. [ out ] pdwSecs : pointer to seconds value
  1287. Return Value :
  1288. A DWORD value indicating RETVAL_SUCCESS on success else
  1289. RETVAL_FAIL on failure
  1290. ******************************************************************************/
  1291. DWORD
  1292. GetTimeFieldEntities(LPTSTR szTime, WORD* pdwHours, WORD* pdwMins,
  1293. WORD* pdwSecs)
  1294. {
  1295. _TCHAR strTime[MAX_STRING_LENGTH] = NULL_STRING ; // Time in _TCHAR type string.
  1296. _TCHAR tHours[MAX_TIME_STR_LEN] = NULL_STRING ; // Date
  1297. _TCHAR tMins[MAX_TIME_STR_LEN] = NULL_STRING ; // Month
  1298. _TCHAR tSecs[MAX_TIME_STR_LEN] = NULL_STRING ; // Year
  1299. if(lstrlen(szTime) <= 0)
  1300. return RETVAL_FAIL;
  1301. lstrcpy(strTime, szTime);
  1302. if( (lstrlen(strTime) != TIMESTR_LEN) || (strTime[FIRST_TIMESEPARATOR_POS]
  1303. != TIME_SEPARATOR_CHAR) || (strTime[SECOND_TIMESEPARATOR_POS] != TIME_SEPARATOR_CHAR) )
  1304. return RETVAL_FAIL;
  1305. // Get the individual Time field entities using _tcstok function.in the order "hh" followed by "mm" followed by "ss"
  1306. lstrcpy(tHours, _tcstok(strTime,TIME_SEPARATOR_STR)); // Get the Hours field.
  1307. if(lstrlen(tHours) > 0)
  1308. {
  1309. lstrcpy(tMins, _tcstok(NULL,TIME_SEPARATOR_STR)); // Get the Minutes field.
  1310. lstrcpy(tSecs, _tcstok(NULL,TIME_SEPARATOR_STR)); // Get the Seconds field.
  1311. }
  1312. LPTSTR pszStopString = NULL;
  1313. // Now convert string values to numeric for time validations.
  1314. *pdwHours = (WORD)_tcstoul(tHours,&pszStopString,BASE_TEN);
  1315. if( lstrlen( pszStopString ) )
  1316. return RETVAL_FAIL;
  1317. *pdwMins = (WORD)_tcstoul(tMins,&pszStopString,BASE_TEN);
  1318. if( lstrlen( pszStopString ))
  1319. return RETVAL_FAIL;
  1320. *pdwSecs = (WORD)_tcstoul(tSecs,&pszStopString,BASE_TEN);
  1321. if( lstrlen( pszStopString ))
  1322. return RETVAL_FAIL;
  1323. return RETVAL_SUCCESS;
  1324. }
  1325. /******************************************************************************
  1326. Routine Description:
  1327. This routine validates the time fields of a given time
  1328. Arguments:
  1329. [ in ] dwHours :Hours value
  1330. [ in ] dwMins :Minutes value
  1331. [ in ] dwSecs : seconds value
  1332. Return Value :
  1333. A DWORD value indicating RETVAL_SUCCESS on success else
  1334. RETVAL_FAIL on failure
  1335. ******************************************************************************/
  1336. DWORD
  1337. ValidateTimeFields( DWORD dwHours, DWORD dwMins, DWORD dwSecs)
  1338. {
  1339. if ( dwHours <= HOURS_PER_DAY_MINUS_ONE )
  1340. {
  1341. if ( ( dwMins < MINUTES_PER_HOUR ) && ( dwSecs < SECS_PER_MINUTE) )
  1342. {
  1343. return RETVAL_SUCCESS;
  1344. }
  1345. else
  1346. {
  1347. return RETVAL_FAIL;
  1348. }
  1349. }
  1350. else
  1351. {
  1352. return RETVAL_FAIL;
  1353. }
  1354. }
  1355. /******************************************************************************
  1356. Routine Description:
  1357. This routine validates the time fields of a given time
  1358. Arguments:
  1359. [ in ] szDay : time string
  1360. Return Value :
  1361. A WORD value containing the day constant [TASK_SUNDAY,TASK_MONDAY etc]
  1362. ******************************************************************************/
  1363. WORD
  1364. GetTaskTrigwDayForDay(LPTSTR szDay)
  1365. {
  1366. TCHAR szDayBuff[MAX_RES_STRING] = NULL_STRING;
  1367. TCHAR *token = NULL;
  1368. TCHAR seps[] = _T(" ,\n");
  1369. WORD dwRetval = 0;
  1370. if(lstrlen(szDay) != 0)
  1371. lstrcpy(szDayBuff, szDay);
  1372. if( lstrlen(szDayBuff) <= 0 )
  1373. {
  1374. return (TASK_MONDAY);//Default value
  1375. }
  1376. token = _tcstok( szDayBuff, seps );
  1377. while( token != NULL )
  1378. {
  1379. if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_SUN ))) )
  1380. dwRetval |= (TASK_SUNDAY);
  1381. else if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_MON ))) )
  1382. dwRetval |= (TASK_MONDAY);
  1383. else if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_TUE ))) )
  1384. dwRetval |= (TASK_TUESDAY);
  1385. else if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_WED ))) )
  1386. dwRetval |= (TASK_WEDNESDAY);
  1387. else if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_THU ))) )
  1388. dwRetval |= (TASK_THURSDAY);
  1389. else if( !(lstrcmpi(token,GetResString( IDS_DAY_MODIFIER_FRI ))) )
  1390. dwRetval |= (TASK_FRIDAY);
  1391. else if( !(lstrcmpi(token, GetResString( IDS_DAY_MODIFIER_SAT ))) )
  1392. dwRetval |= (TASK_SATURDAY);
  1393. else if( !(lstrcmpi(token, ASTERIX)) )
  1394. return (TASK_SUNDAY | TASK_MONDAY | TASK_TUESDAY | TASK_WEDNESDAY |
  1395. TASK_THURSDAY | TASK_FRIDAY | TASK_SATURDAY);
  1396. else
  1397. return 0;
  1398. token = _tcstok( NULL, seps );
  1399. }
  1400. return dwRetval;
  1401. }
  1402. /******************************************************************************
  1403. Routine Description:
  1404. This routine validates the time fields of a given time
  1405. Arguments:
  1406. [ in ] szMonth : Month string
  1407. Return Value :
  1408. A WORD value containing the Month constant
  1409. [TASK_JANUARY,TASK_FEBRUARY etc]
  1410. ******************************************************************************/
  1411. WORD
  1412. GetTaskTrigwMonthForMonth(LPTSTR szMonth)
  1413. {
  1414. TCHAR *token = NULL;
  1415. WORD dwRetval = 0;
  1416. TCHAR strMon[MAX_TOKENS_LENGTH] = NULL_STRING;
  1417. TCHAR seps[] = _T(" ,\n");
  1418. if( lstrlen(szMonth) <= 0 )
  1419. {
  1420. return (TASK_JANUARY | TASK_FEBRUARY | TASK_MARCH | TASK_APRIL | TASK_MAY | TASK_JUNE |
  1421. TASK_JULY | TASK_AUGUST | TASK_SEPTEMBER | TASK_OCTOBER
  1422. | TASK_NOVEMBER | TASK_DECEMBER );
  1423. }
  1424. lstrcpy(strMon, szMonth);
  1425. token = _tcstok( szMonth, seps );
  1426. while( token != NULL )
  1427. {
  1428. if( !(lstrcmpi(token, ASTERIX)) )
  1429. return (TASK_JANUARY | TASK_FEBRUARY | TASK_MARCH | TASK_APRIL
  1430. | TASK_MAY | TASK_JUNE | TASK_JULY | TASK_AUGUST | TASK_SEPTEMBER | TASK_OCTOBER
  1431. | TASK_NOVEMBER | TASK_DECEMBER );
  1432. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JAN ))) )
  1433. dwRetval |= (TASK_JANUARY);
  1434. else if( !(lstrcmpi(token,GetResString( IDS_MONTH_MODIFIER_FEB ))) )
  1435. dwRetval |= (TASK_FEBRUARY);
  1436. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_MAR ))) )
  1437. dwRetval |= (TASK_MARCH);
  1438. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_APR ))) )
  1439. dwRetval |= (TASK_APRIL);
  1440. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_MAY ))) )
  1441. dwRetval |= (TASK_MAY);
  1442. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JUN ))) )
  1443. dwRetval |= (TASK_JUNE);
  1444. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JUL ))) )
  1445. dwRetval |= (TASK_JULY);
  1446. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_AUG ))) )
  1447. dwRetval |= (TASK_AUGUST);
  1448. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_SEP ))) )
  1449. dwRetval |= (TASK_SEPTEMBER);
  1450. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_OCT ))) )
  1451. dwRetval |= (TASK_OCTOBER);
  1452. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_NOV ))) )
  1453. dwRetval |= (TASK_NOVEMBER);
  1454. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_DEC ))) )
  1455. dwRetval |= (TASK_DECEMBER);
  1456. else
  1457. return 0;
  1458. token = _tcstok( NULL, seps );
  1459. }
  1460. return dwRetval;
  1461. }
  1462. /******************************************************************************
  1463. Routine Description:
  1464. This routine returns the corresponding month flag
  1465. Arguments:
  1466. [ in ] dwMonthId : Month index
  1467. Return Value :
  1468. A WORD value containing the Month constant
  1469. [TASK_JANUARY,TASK_FEBRUARY etc]
  1470. ******************************************************************************/
  1471. WORD
  1472. GetMonthId(DWORD dwMonthId)
  1473. {
  1474. DWORD dwMonthsArr[] = {TASK_JANUARY,TASK_FEBRUARY ,TASK_MARCH ,TASK_APRIL ,
  1475. TASK_MAY ,TASK_JUNE ,TASK_JULY ,TASK_AUGUST,
  1476. TASK_SEPTEMBER ,TASK_OCTOBER ,TASK_NOVEMBER ,TASK_DECEMBER } ;
  1477. DWORD wMonthFlags = 0;
  1478. DWORD dwMod = 0;
  1479. dwMod = dwMonthId - 1;
  1480. while(dwMod < 12)
  1481. {
  1482. wMonthFlags |= dwMonthsArr[dwMod];
  1483. dwMod = dwMod + dwMonthId;
  1484. }
  1485. return (WORD)wMonthFlags;
  1486. }
  1487. /******************************************************************************
  1488. Routine Description:
  1489. This routine returns the maximum Last day in the months specifed
  1490. Arguments:
  1491. [ in ] szMonths : string containing months specified by user
  1492. [ in ] wStartYear : string containing start year
  1493. Return Value :
  1494. A DWORD value specifying the maximum last day in the specified months
  1495. ******************************************************************************/
  1496. DWORD GetNumDaysInaMonth(TCHAR* szMonths, WORD wStartYear)
  1497. {
  1498. DWORD dwDays = 31;//max.no of days in a month
  1499. BOOL bMaxDays = FALSE;//if any of the months have 31 then days of value 31 is returned
  1500. if( ( lstrlen(szMonths) == 0 ) || ( lstrcmpi(szMonths,ASTERIX) == 0 ) )
  1501. return dwDays; //All months[default]
  1502. TCHAR *token = NULL;
  1503. TCHAR strMon[MAX_MONTH_STR_LEN] = NULL_STRING;
  1504. TCHAR seps[] = _T(" ,\n");
  1505. lstrcpy(strMon, szMonths);
  1506. token = _tcstok( strMon, seps );
  1507. while( token != NULL )
  1508. {
  1509. if( !(lstrcmpi(token,GetResString( IDS_MONTH_MODIFIER_FEB ))) )
  1510. {
  1511. if( ( (wStartYear % 400) == 0) ||
  1512. ( ( (wStartYear % 4) == 0) &&
  1513. ( (wStartYear % 100) != 0) ) )
  1514. {
  1515. dwDays = 29;
  1516. }
  1517. else
  1518. {
  1519. dwDays = 28;
  1520. }
  1521. }
  1522. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JAN ))) )
  1523. {
  1524. bMaxDays = TRUE;
  1525. }
  1526. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_MAR ))) )
  1527. {
  1528. bMaxDays = TRUE;
  1529. }
  1530. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_MAY ))) )
  1531. {
  1532. bMaxDays = TRUE;
  1533. }
  1534. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JUL ))) )
  1535. {
  1536. bMaxDays = TRUE;
  1537. }
  1538. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_AUG ))) )
  1539. {
  1540. bMaxDays = TRUE;
  1541. }
  1542. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_OCT ))) )
  1543. {
  1544. bMaxDays = TRUE;
  1545. }
  1546. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_DEC ))) )
  1547. {
  1548. bMaxDays = TRUE;
  1549. }
  1550. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_APR ))) )
  1551. {
  1552. dwDays = 30;
  1553. }
  1554. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_JUN ))) )
  1555. {
  1556. dwDays = 30;
  1557. }
  1558. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_SEP ))) )
  1559. {
  1560. dwDays = 30;
  1561. }
  1562. else if( !(lstrcmpi(token, GetResString( IDS_MONTH_MODIFIER_NOV ))) )
  1563. {
  1564. dwDays = 30;
  1565. }
  1566. token = _tcstok( NULL, seps );
  1567. }
  1568. if (bMaxDays == TRUE)
  1569. return 31;
  1570. else
  1571. return dwDays;
  1572. }
  1573. /******************************************************************************
  1574. Routine Description:
  1575. This routine checks the validates the taskname of the task to be created.
  1576. Arguments:
  1577. [ in ] pszJobName : Pointer to the job[task] name
  1578. Return Value :
  1579. If valid task name then TRUE else FALSE
  1580. ******************************************************************************/
  1581. BOOL VerifyJobName(_TCHAR* pszJobName)
  1582. {
  1583. _TCHAR szTokens[] = {_T('<'),_T('>'),_T(':'),_T('/'),_T('\\'),_T('|')};
  1584. if( _tcspbrk(pszJobName,szTokens) == NULL)
  1585. return TRUE;
  1586. else
  1587. return FALSE;
  1588. }
  1589. /******************************************************************************
  1590. Routine Description:
  1591. This routine gets the date format value with respective to regional options.
  1592. Arguments:
  1593. [ out ] pdwFormat : Date format value.
  1594. Return Value :
  1595. Returns RETVAL_FAIL on failure and RETVAL_SUCCESS on success.
  1596. ******************************************************************************/
  1597. DWORD GetDateFieldFormat(WORD* pwFormat)
  1598. {
  1599. LCID lcid;
  1600. _TCHAR szBuffer[MAX_BUF_SIZE];
  1601. //Get the user default locale in the users computer
  1602. lcid = GetUserDefaultLCID();
  1603. //Get the date format
  1604. if (GetLocaleInfo(lcid, LOCALE_IDATE, szBuffer, MAX_BUF_SIZE))
  1605. {
  1606. switch (szBuffer[0])
  1607. {
  1608. case TEXT('0'):
  1609. *pwFormat = 0;
  1610. break;
  1611. case TEXT('1'):
  1612. *pwFormat = 1;
  1613. break;
  1614. case TEXT('2'):
  1615. *pwFormat = 2;
  1616. break;
  1617. default:
  1618. return RETVAL_FAIL;
  1619. }
  1620. }
  1621. return RETVAL_SUCCESS;
  1622. }
  1623. /******************************************************************************
  1624. Routine Description:
  1625. This routine gets the date format string with respective to regional options.
  1626. Arguments:
  1627. [ out ] szFormat : Date format string.
  1628. Return Value :
  1629. Returns RETVAL_FAIL on failure and RETVAL_SUCCESS on success.
  1630. ******************************************************************************/
  1631. DWORD GetDateFormatString(LPTSTR szFormat)
  1632. {
  1633. WORD wFormatID = 0;
  1634. if ( RETVAL_FAIL == GetDateFieldFormat( &wFormatID ))
  1635. {
  1636. return RETVAL_FAIL;
  1637. }
  1638. if ( wFormatID == 0 )
  1639. {
  1640. lstrcpy (szFormat, GetResString(IDS_MMDDYY_FORMAT));
  1641. }
  1642. else if ( wFormatID == 1 )
  1643. {
  1644. lstrcpy (szFormat, GetResString( IDS_DDMMYY_FORMAT));
  1645. }
  1646. else if ( wFormatID == 2 )
  1647. {
  1648. lstrcpy (szFormat, GetResString(IDS_YYMMDD_FORMAT));
  1649. }
  1650. else
  1651. {
  1652. return RETVAL_FAIL;
  1653. }
  1654. return RETVAL_SUCCESS;
  1655. }