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.

389 lines
9.6 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: jobs.h
  7. //
  8. // Contents: Definition of the shell IDLIST type for Jobs
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1/5/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include <mstask.h>
  18. #ifndef _JOBIDL_HXX__
  19. #define _JOBIDL_HXX__
  20. #include <common.hxx>
  21. #include <StrSafe.h>
  22. //____________________________________________________________________________
  23. //
  24. // Job folder details view columns enumeration.
  25. //____________________________________________________________________________
  26. enum COLUMNS
  27. {
  28. COLUMN_NAME,
  29. COLUMN_SCHEDULE,
  30. COLUMN_NEXTRUNTIME,
  31. COLUMN_LASTRUNTIME,
  32. COLUMN_STATUS,
  33. COLUMN_LASTEXITCODE,
  34. COLUMN_CREATOR,
  35. COLUMN_COUNT
  36. };
  37. //____________________________________________________________________________
  38. //
  39. // class: CJobID
  40. //
  41. // synopsis: IDLIST type struct for Jobs
  42. //____________________________________________________________________________
  43. //
  44. #define IDJOB_BUFFER_SIZE (MAX_PATH * 3)
  45. #define MASK_BITS (0xFFF0)
  46. #define VALID_ID (0x00A0)
  47. #define ID_JOB (0x00A1)
  48. #define ID_QUEUE (0x00A2)
  49. #define ID_NEWJOB (0x00A3)
  50. #define ID_NEWQUEUE (0x00A4)
  51. #define ID_TEMPLATE (0x00A5) // create new task template object
  52. enum EJobStatus
  53. {
  54. ejsRunning = 1,
  55. ejsNotScheduled,
  56. ejsMissed,
  57. ejsWouldNotStart,
  58. ejsBadAcct,
  59. ejsResAcct
  60. };
  61. class CJobID
  62. {
  63. public:
  64. CJobID();
  65. HRESULT Load(LPCTSTR pszFolderPath, LPTSTR pszJobPath);
  66. HRESULT Rename(CJobID &jidIn, LPCOLESTR lpszName);
  67. CJobID *Clone(void);
  68. void LoadDummy(LPTSTR pszJobName);
  69. void InitToTemplate();
  70. LPTSTR GetNextRunTimeString(TCHAR tcBuff[], UINT cchBuff,
  71. BOOL fForComparison,
  72. LPSHELLDETAILS lpDetails=NULL);
  73. ULONG GetSize() { return _cb; }
  74. BOOL IsJob() { return _id == ID_JOB; }
  75. BOOL IsTemplate() { return _id == ID_TEMPLATE; }
  76. LPTSTR GetExtension()
  77. {
  78. switch (_id)
  79. {
  80. case ID_JOB: return TSZ_DOTJOB;
  81. // case ID_QUEUE: return g_szDotQue;
  82. default: return TEXT("");
  83. }
  84. }
  85. BOOL IsRunning() { return _status == ejsRunning; }
  86. BOOL IsJobNotScheduled() { return _status == ejsNotScheduled; }
  87. BOOL WasRunMissed() { return _status == ejsMissed; }
  88. BOOL DidJobStartFail() { return _status == ejsWouldNotStart; }
  89. BOOL DidJobBadAcct() { return _status == ejsBadAcct; }
  90. BOOL DidJobRestAcct() { return _status == ejsResAcct; }
  91. ULONG GetJobFlags() { return _ulJobFlags; }
  92. BOOL IsJobFlagOn(ULONG flag) { return (_ulJobFlags & flag) ? TRUE : FALSE; }
  93. TASK_TRIGGER & GetTrigger() { return _sJobTrigger; }
  94. TASK_TRIGGER_TYPE GetTriggerType() { return _sJobTrigger.TriggerType; }
  95. BOOL IsTriggerFlagOn(ULONG flag)
  96. { return (_sJobTrigger.rgFlags & flag) ? TRUE : FALSE; }
  97. USHORT GetTriggerCount() { return _cTriggers; }
  98. SYSTEMTIME & GetLastRunTime() { return _stLastRunTime; }
  99. SYSTEMTIME & GetNextRunTime() { return _stNextRunTime; }
  100. DWORD & GetExitCode() { return _dwExitCode; }
  101. LPTSTR GetAppName() { return _cBuf; }
  102. LPTSTR GetCreator() { return &_cBuf[_oCreator]; }
  103. LPTSTR GetPath() { return &_cBuf[_oPath];; }
  104. LPTSTR GetName() { return &_cBuf[_oName]; }
  105. size_t GetAppNameOffset()
  106. { return offsetof(CJobID, _cBuf); }
  107. size_t GetCreatorOffset()
  108. { return (offsetof(CJobID, _cBuf) + _oCreator * sizeof(TCHAR)); }
  109. size_t GetPathOffset()
  110. { return (offsetof(CJobID, _cBuf) + _oPath * sizeof(TCHAR)); }
  111. size_t GetNameOffset()
  112. { return (offsetof(CJobID, _cBuf) + _oName * sizeof(TCHAR)); }
  113. #if (DBG == 1)
  114. VOID Validate();
  115. #endif // (DBG == 1)
  116. USHORT _cb; // This must be a USHORT & be the first member,
  117. // as dictated by the idlist definition.
  118. USHORT _id; // To validate that the given pidl is indeed
  119. // one of our own. And also to determine
  120. // if it is a Job/NewJob/Queue/NewQueue
  121. USHORT _status; // 1 => running, 0 => idle status
  122. USHORT _oCreator;
  123. USHORT _oPath;
  124. USHORT _oName;
  125. ULONG _ulJobFlags;
  126. SYSTEMTIME _stLastRunTime;
  127. SYSTEMTIME _stNextRunTime;
  128. FILETIME _ftCreation;
  129. FILETIME _ftLastWrite;
  130. DWORD _dwExitCode;
  131. USHORT _cTriggers;
  132. TASK_TRIGGER _sJobTrigger; // structure job trigger
  133. //
  134. // The contents of the buffer are as follows:
  135. // _cBuf[0] = application name
  136. // _cBuf[_oCreator] = creator name
  137. // _cBuf[_oPath] = job object path
  138. // _cBuf[_oName] = job object name
  139. //
  140. TCHAR _cBuf[IDJOB_BUFFER_SIZE];
  141. private:
  142. void
  143. _NullTerminate();
  144. };
  145. typedef CJobID UNALIGNED * PJOBID;
  146. typedef CJobID UNALIGNED * UNALIGNED * PPJOBID;
  147. //+--------------------------------------------------------------------------
  148. //
  149. // Member: CJobID::CJobID
  150. //
  151. // Synopsis: ctor
  152. //
  153. // History: 12-08-1997 DavidMun Created
  154. //
  155. //---------------------------------------------------------------------------
  156. inline
  157. CJobID::CJobID():
  158. _cb(0)
  159. {
  160. }
  161. //+--------------------------------------------------------------------------
  162. //
  163. // Member: CJobID::_NullTerminate
  164. //
  165. // Synopsis: Ensure that the two bytes just past the declared size of
  166. // this object are zero.
  167. //
  168. // History: 05-30-1997 DavidMun Created
  169. //
  170. //---------------------------------------------------------------------------
  171. inline void
  172. CJobID::_NullTerminate()
  173. {
  174. // Sanity check that we won't write outside of this
  175. Win4Assert(_cb + sizeof(USHORT) <= sizeof(CJobID));
  176. if (_cb + sizeof(USHORT) <= sizeof(CJobID))
  177. {
  178. UNALIGNED USHORT *pusNextCB = (UNALIGNED USHORT *)(((BYTE *)this) + _cb);
  179. *pusNextCB = 0;
  180. }
  181. }
  182. inline void
  183. CJobID::LoadDummy(
  184. LPTSTR pszJobName)
  185. {
  186. _id = ID_JOB;
  187. _oPath = _oName = 0;
  188. // lstrcpy(_cBuf, PathFindFileName(pszJobName));
  189. StringCchCopy(_cBuf, IDJOB_BUFFER_SIZE, PathFindFileName(pszJobName));
  190. TCHAR * ptcExtn = PathFindExtension(_cBuf);
  191. if (ptcExtn)
  192. {
  193. *ptcExtn = TEXT('\0');
  194. }
  195. _cb = offsetof(CJobID, _cBuf) + (lstrlen(_cBuf) + 1) * sizeof(TCHAR);
  196. _NullTerminate();
  197. }
  198. #define JOBID_MIN_SIZE (sizeof(CJobID) - IDJOB_BUFFER_SIZE * sizeof(TCHAR))
  199. inline
  200. BOOL
  201. JF_IsValidID(LPCITEMIDLIST pidl)
  202. {
  203. if (pidl)
  204. {
  205. if (pidl->mkid.cb >= JOBID_MIN_SIZE)
  206. {
  207. return ((((PJOBID)pidl)->_id & MASK_BITS) == VALID_ID);
  208. }
  209. }
  210. return FALSE;
  211. }
  212. //____________________________________________________________________________
  213. //
  214. // class: CJob CIDA
  215. //
  216. // synopsis: format of CF_JOBIDLIST
  217. //____________________________________________________________________________
  218. //
  219. typedef HGLOBAL HJOBIDA;
  220. class CJobIDA
  221. {
  222. public:
  223. PJOBID GetItem(UINT i) {
  224. return (i >= cidl) ? NULL : (PJOBID)(((LPBYTE)this) + aoffset[i]);
  225. }
  226. PJOBID operator [](UINT i) {
  227. return (i >= cidl) ? NULL : (PJOBID)(((LPBYTE)this) + aoffset[i]);
  228. }
  229. UINT cidl; // number of CJobIDs
  230. UINT aoffset[1]; // offset to the CJobIDs
  231. };
  232. typedef CJobIDA * PJOBIDA;
  233. HJOBIDA
  234. HJOBIDA_Create(
  235. UINT cidl,
  236. PJOBID * apjidl);
  237. void
  238. HJOBIDA_Free(
  239. HJOBIDA hJobIDA);
  240. HDROP
  241. HDROPFromJobIDList(
  242. LPCTSTR pszFolderPath,
  243. UINT cidl,
  244. PJOBID * apjidl);
  245. HGLOBAL
  246. CreateIDListArray(
  247. LPCITEMIDLIST pidlFolder,
  248. UINT cidl,
  249. PJOBID *apjidl);
  250. //____________________________________________________________________________
  251. //
  252. // Functions to clone and free a LPCITEMIDLIST array.
  253. //____________________________________________________________________________
  254. LPITEMIDLIST*
  255. ILA_Clone(
  256. UINT cidl,
  257. LPCITEMIDLIST* apidl);
  258. VOID
  259. ILA_Free(
  260. UINT cidl,
  261. LPITEMIDLIST* apidl);
  262. //____________________________________________________________________________
  263. //
  264. // Functions to access the CJob & CSchedule
  265. //____________________________________________________________________________
  266. HRESULT
  267. JFGetJobScheduler(
  268. LPTSTR pszMachine,
  269. ITaskScheduler ** ppJobScheduler,
  270. LPCTSTR * ppszFolderPath);
  271. HRESULT
  272. JFCopyJob(
  273. HWND hwndOwner,
  274. TCHAR szFileFrom[],
  275. LPCTSTR pszFolderPath,
  276. BOOL fMove);
  277. HRESULT
  278. GetTriggerStringFromTrigger(
  279. TASK_TRIGGER * pJobTrigger,
  280. LPTSTR psTrigger,
  281. UINT cchTrigger,
  282. LPSHELLDETAILS lpDetails);
  283. BOOL
  284. IsAScheduleObject(
  285. TCHAR szFile[]);
  286. //____________________________________________________________________________
  287. //
  288. // Misc functions.
  289. //____________________________________________________________________________
  290. LPITEMIDLIST *
  291. SHIDLFromJobIDL(
  292. UINT cidl,
  293. PJOBID * apjidl);
  294. #endif // _JOBIDL_HXX__