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.

1342 lines
31 KiB

  1. /************************************************************************
  2. Copyright (c) 2000 - 2000 Microsoft Corporation
  3. Module Name :
  4. cjob.h
  5. Abstract :
  6. Main header file for handling jobs and files.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. #include "qmgrlib.h"
  11. #include <vector>
  12. #include <list>
  13. #include <xstring>
  14. #include <stllock.h>
  15. #include <limits.h>
  16. #include "clist.h"
  17. //
  18. // Job Specific Access Rights.
  19. //
  20. #define BG_JOB_QUERY_PROP (0x0001)
  21. #define BG_JOB_SET_PROP (0x0002)
  22. #define BG_JOB_NOTIFY (0x0004)
  23. #define BG_JOB_MANAGE (0x0008)
  24. #define BG_JOB_ALL_ACCESS ( BG_JOB_QUERY_PROP |\
  25. BG_JOB_SET_PROP |\
  26. BG_JOB_NOTIFY |\
  27. BG_JOB_MANAGE )
  28. #define BG_JOB_READ ( STANDARD_RIGHTS_READ |\
  29. BG_JOB_QUERY_PROP )
  30. #define BG_JOB_WRITE ( STANDARD_RIGHTS_WRITE |\
  31. BG_JOB_SET_PROP |\
  32. BG_JOB_NOTIFY |\
  33. BG_JOB_MANAGE )
  34. #define BG_JOB_EXECUTE ( STANDARD_RIGHTS_EXECUTE )
  35. class CFile;
  36. class CJob;
  37. class CJobError;
  38. class CEnumJobs;
  39. class CEnumFiles;
  40. class CJobManager;
  41. class CJobExternal;
  42. class CFileExternal;
  43. class CJobInactivityTimeout : public TaskSchedulerWorkItem
  44. {
  45. public:
  46. virtual void OnInactivityTimeout() = 0;
  47. virtual void OnDispatch() { return OnInactivityTimeout(); }
  48. };
  49. class CJobNoProgressItem : public TaskSchedulerWorkItem
  50. {
  51. public:
  52. virtual void OnNoProgress() = 0;
  53. virtual void OnDispatch() { return OnNoProgress(); }
  54. };
  55. class CJobCallbackItem : public TaskSchedulerWorkItem
  56. {
  57. public:
  58. virtual void OnMakeCallback() = 0;
  59. virtual void OnDispatch() { return OnMakeCallback(); }
  60. protected:
  61. enum CallbackMethod
  62. {
  63. CM_COMPLETE,
  64. CM_ERROR
  65. }
  66. m_method;
  67. };
  68. class CJobRetryItem : public TaskSchedulerWorkItem
  69. {
  70. public:
  71. virtual void OnRetryJob() = 0;
  72. virtual void OnDispatch() { return OnRetryJob(); }
  73. };
  74. class CJobModificationItem : public TaskSchedulerWorkItem
  75. {
  76. public:
  77. virtual void OnModificationCallback() = 0;
  78. virtual void OnDispatch() { return OnModificationCallback(); }
  79. ULONG m_ModificationsPending;
  80. CJobModificationItem() :
  81. m_ModificationsPending(0) {}
  82. };
  83. class CLockedJobReadPointer : public CLockedReadPointer<CJob, BG_JOB_READ>
  84. {
  85. public:
  86. CLockedJobReadPointer( CJob * job) : CLockedReadPointer<CJob, BG_JOB_READ>( job )
  87. {
  88. }
  89. HRESULT ValidateAccess();
  90. };
  91. class CLockedJobWritePointer : public CLockedWritePointer<CJob, BG_JOB_WRITE>
  92. {
  93. public:
  94. CLockedJobWritePointer( CJob * job) : CLockedWritePointer<CJob, BG_JOB_WRITE>( job )
  95. {
  96. }
  97. HRESULT ValidateAccess();
  98. };
  99. //------------------------------------------------------------------------
  100. class CJobExternal : public IBackgroundCopyJob2
  101. {
  102. friend CJob;
  103. public:
  104. // IUnknown Methods
  105. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  106. ULONG _stdcall AddRef(void);
  107. ULONG _stdcall Release(void);
  108. // IBackgroundCopyJob methods
  109. HRESULT STDMETHODCALLTYPE AddFileSetInternal(
  110. /* [in] */ ULONG cFileCount,
  111. /* [size_is][in] */ BG_FILE_INFO *pFileSet);
  112. HRESULT STDMETHODCALLTYPE AddFileSet(
  113. /* [in] */ ULONG cFileCount,
  114. /* [size_is][in] */ BG_FILE_INFO *pFileSet)
  115. {
  116. EXTERNAL_FUNC_WRAP( AddFileSetInternal( cFileCount, pFileSet ) )
  117. }
  118. HRESULT STDMETHODCALLTYPE AddFileInternal(
  119. /* [in] */ LPCWSTR RemoteUrl,
  120. /* [in] */ LPCWSTR LocalName);
  121. HRESULT STDMETHODCALLTYPE AddFile(
  122. /* [in] */ LPCWSTR RemoteUrl,
  123. /* [in] */ LPCWSTR LocalName)
  124. {
  125. EXTERNAL_FUNC_WRAP( AddFileInternal( RemoteUrl, LocalName ) )
  126. }
  127. HRESULT STDMETHODCALLTYPE EnumFilesInternal(
  128. /* [out] */ IEnumBackgroundCopyFiles **pEnum);
  129. HRESULT STDMETHODCALLTYPE EnumFiles(
  130. /* [out] */ IEnumBackgroundCopyFiles **ppEnum
  131. )
  132. {
  133. EXTERNAL_FUNC_WRAP( EnumFilesInternal( ppEnum ) )
  134. }
  135. HRESULT STDMETHODCALLTYPE SuspendInternal( void);
  136. HRESULT STDMETHODCALLTYPE Suspend( void)
  137. {
  138. EXTERNAL_FUNC_WRAP( SuspendInternal() )
  139. }
  140. HRESULT STDMETHODCALLTYPE ResumeInternal( void);
  141. HRESULT STDMETHODCALLTYPE Resume( void)
  142. {
  143. EXTERNAL_FUNC_WRAP( ResumeInternal() )
  144. }
  145. HRESULT STDMETHODCALLTYPE CancelInternal( void);
  146. HRESULT STDMETHODCALLTYPE Cancel( void)
  147. {
  148. EXTERNAL_FUNC_WRAP( CancelInternal() )
  149. }
  150. HRESULT STDMETHODCALLTYPE CompleteInternal( void);
  151. HRESULT STDMETHODCALLTYPE Complete( void)
  152. {
  153. EXTERNAL_FUNC_WRAP( CompleteInternal() )
  154. }
  155. HRESULT STDMETHODCALLTYPE GetIdInternal(
  156. /* [out] */ GUID *pVal);
  157. HRESULT STDMETHODCALLTYPE GetId(
  158. /* [out] */ GUID *pVal)
  159. {
  160. EXTERNAL_FUNC_WRAP( GetIdInternal( pVal ) )
  161. }
  162. HRESULT STDMETHODCALLTYPE GetTypeInternal(
  163. /* [out] */ BG_JOB_TYPE *pVal);
  164. HRESULT STDMETHODCALLTYPE GetType(
  165. /* [out] */ BG_JOB_TYPE *pVal)
  166. {
  167. EXTERNAL_FUNC_WRAP( GetTypeInternal( pVal ) )
  168. }
  169. HRESULT STDMETHODCALLTYPE GetProgressInternal(
  170. /* [out] */ BG_JOB_PROGRESS *pVal);
  171. HRESULT STDMETHODCALLTYPE GetProgress(
  172. /* [out] */ BG_JOB_PROGRESS *pVal)
  173. {
  174. EXTERNAL_FUNC_WRAP( GetProgressInternal( pVal ) )
  175. }
  176. HRESULT STDMETHODCALLTYPE GetTimesInternal(
  177. /* [out] */ BG_JOB_TIMES *pVal);
  178. HRESULT STDMETHODCALLTYPE GetTimes(
  179. /* [out] */ BG_JOB_TIMES *pVal)
  180. {
  181. EXTERNAL_FUNC_WRAP( GetTimesInternal( pVal ) )
  182. }
  183. HRESULT STDMETHODCALLTYPE GetStateInternal(
  184. /* [out] */ BG_JOB_STATE *pVal);
  185. HRESULT STDMETHODCALLTYPE GetState(
  186. /* [out] */ BG_JOB_STATE *pVal)
  187. {
  188. EXTERNAL_FUNC_WRAP( GetStateInternal( pVal ) )
  189. }
  190. HRESULT STDMETHODCALLTYPE GetErrorInternal(
  191. /* [out] */ IBackgroundCopyError **ppError);
  192. HRESULT STDMETHODCALLTYPE GetError(
  193. /* [out] */ IBackgroundCopyError **ppError)
  194. {
  195. EXTERNAL_FUNC_WRAP( GetErrorInternal( ppError ) )
  196. }
  197. HRESULT STDMETHODCALLTYPE GetOwnerInternal(
  198. /* [out] */ LPWSTR *pVal);
  199. HRESULT STDMETHODCALLTYPE GetOwner(
  200. /* [out] */ LPWSTR *pVal)
  201. {
  202. EXTERNAL_FUNC_WRAP( GetOwnerInternal( pVal ) )
  203. }
  204. HRESULT STDMETHODCALLTYPE SetDisplayNameInternal(
  205. /* [in] */ LPCWSTR Val);
  206. HRESULT STDMETHODCALLTYPE SetDisplayName(
  207. /* [in] */ LPCWSTR Val)
  208. {
  209. EXTERNAL_FUNC_WRAP( SetDisplayNameInternal( Val ) )
  210. }
  211. HRESULT STDMETHODCALLTYPE GetDisplayNameInternal(
  212. /* [out] */ LPWSTR *pVal);
  213. HRESULT STDMETHODCALLTYPE GetDisplayName(
  214. /* [out] */ LPWSTR *pVal)
  215. {
  216. EXTERNAL_FUNC_WRAP( GetDisplayNameInternal( pVal ) )
  217. }
  218. HRESULT STDMETHODCALLTYPE SetDescriptionInternal(
  219. /* [in] */ LPCWSTR Val);
  220. HRESULT STDMETHODCALLTYPE SetDescription(
  221. /* [in] */ LPCWSTR Val)
  222. {
  223. EXTERNAL_FUNC_WRAP( SetDescriptionInternal( Val ) )
  224. }
  225. HRESULT STDMETHODCALLTYPE GetDescriptionInternal(
  226. /* [out] */ LPWSTR *pVal);
  227. HRESULT STDMETHODCALLTYPE GetDescription(
  228. /* [out] */ LPWSTR *pVal)
  229. {
  230. EXTERNAL_FUNC_WRAP( GetDescriptionInternal( pVal ) )
  231. }
  232. HRESULT STDMETHODCALLTYPE SetPriorityInternal(
  233. /* [in] */ BG_JOB_PRIORITY Val);
  234. HRESULT STDMETHODCALLTYPE SetPriority(
  235. /* [in] */ BG_JOB_PRIORITY Val)
  236. {
  237. EXTERNAL_FUNC_WRAP( SetPriorityInternal( Val ) )
  238. }
  239. HRESULT STDMETHODCALLTYPE GetPriorityInternal(
  240. /* [out] */ BG_JOB_PRIORITY *pVal);
  241. HRESULT STDMETHODCALLTYPE GetPriority(
  242. /* [out] */ BG_JOB_PRIORITY *pVal)
  243. {
  244. EXTERNAL_FUNC_WRAP( GetPriorityInternal( pVal ) )
  245. }
  246. HRESULT STDMETHODCALLTYPE SetNotifyFlagsInternal(
  247. /* [in] */ ULONG Val);
  248. HRESULT STDMETHODCALLTYPE SetNotifyFlags(
  249. /* [in] */ ULONG Val)
  250. {
  251. EXTERNAL_FUNC_WRAP( SetNotifyFlagsInternal( Val ) )
  252. }
  253. HRESULT STDMETHODCALLTYPE GetNotifyFlagsInternal(
  254. /* [out] */ ULONG *pVal);
  255. HRESULT STDMETHODCALLTYPE GetNotifyFlags(
  256. /* [out] */ ULONG *pVal)
  257. {
  258. EXTERNAL_FUNC_WRAP( GetNotifyFlagsInternal( pVal ) )
  259. }
  260. HRESULT STDMETHODCALLTYPE
  261. SetNotifyInterfaceInternal(
  262. IUnknown * Val
  263. );
  264. HRESULT STDMETHODCALLTYPE
  265. SetNotifyInterface(
  266. IUnknown * Val
  267. )
  268. {
  269. EXTERNAL_FUNC_WRAP( SetNotifyInterfaceInternal( Val ) )
  270. }
  271. HRESULT STDMETHODCALLTYPE
  272. GetNotifyInterfaceInternal(
  273. IUnknown ** ppVal
  274. );
  275. HRESULT STDMETHODCALLTYPE
  276. GetNotifyInterface(
  277. IUnknown ** ppVal
  278. )
  279. {
  280. EXTERNAL_FUNC_WRAP( GetNotifyInterfaceInternal( ppVal ) )
  281. }
  282. HRESULT STDMETHODCALLTYPE SetMinimumRetryDelayInternal(
  283. /* [in] */ ULONG Seconds);
  284. HRESULT STDMETHODCALLTYPE SetMinimumRetryDelay(
  285. /* [in] */ ULONG Seconds)
  286. {
  287. EXTERNAL_FUNC_WRAP( SetMinimumRetryDelayInternal( Seconds ) )
  288. }
  289. HRESULT STDMETHODCALLTYPE GetMinimumRetryDelayInternal(
  290. /* [out] */ ULONG *Seconds);
  291. HRESULT STDMETHODCALLTYPE GetMinimumRetryDelay(
  292. /* [out] */ ULONG *Seconds)
  293. {
  294. EXTERNAL_FUNC_WRAP( GetMinimumRetryDelayInternal( Seconds ) )
  295. }
  296. HRESULT STDMETHODCALLTYPE SetNoProgressTimeoutInternal(
  297. /* [in] */ ULONG Seconds);
  298. HRESULT STDMETHODCALLTYPE SetNoProgressTimeout(
  299. /* [in] */ ULONG Seconds)
  300. {
  301. EXTERNAL_FUNC_WRAP( SetNoProgressTimeoutInternal( Seconds ) )
  302. }
  303. HRESULT STDMETHODCALLTYPE GetNoProgressTimeoutInternal(
  304. /* [out] */ ULONG *Seconds);
  305. HRESULT STDMETHODCALLTYPE GetNoProgressTimeout(
  306. /* [out] */ ULONG *Seconds)
  307. {
  308. EXTERNAL_FUNC_WRAP( GetNoProgressTimeoutInternal( Seconds ) )
  309. }
  310. HRESULT STDMETHODCALLTYPE GetErrorCountInternal(
  311. /* [out] */ ULONG *Errors);
  312. HRESULT STDMETHODCALLTYPE GetErrorCount(
  313. /* [out] */ ULONG *Errors)
  314. {
  315. EXTERNAL_FUNC_WRAP( GetErrorCountInternal( Errors ) )
  316. }
  317. HRESULT STDMETHODCALLTYPE SetProxySettingsInternal(
  318. /* [in] */ BG_JOB_PROXY_USAGE ProxyUsage,
  319. /* [in] */ LPCWSTR ProxyList,
  320. /* [in] */ LPCWSTR ProxyBypassList );
  321. HRESULT STDMETHODCALLTYPE SetProxySettings(
  322. /* [in] */ BG_JOB_PROXY_USAGE ProxyUsage,
  323. /* [in] */ LPCWSTR ProxyList,
  324. /* [in] */ LPCWSTR ProxyBypassList )
  325. {
  326. EXTERNAL_FUNC_WRAP( SetProxySettingsInternal( ProxyUsage, ProxyList, ProxyBypassList ) )
  327. }
  328. HRESULT STDMETHODCALLTYPE GetProxySettingsInternal(
  329. /* [out] */ BG_JOB_PROXY_USAGE *pProxyUsage,
  330. /* [out] */ LPWSTR *pProxyList,
  331. /* [out] */ LPWSTR *pProxyBypassList );
  332. HRESULT STDMETHODCALLTYPE GetProxySettings(
  333. /* [out] */ BG_JOB_PROXY_USAGE *pProxyUsage,
  334. /* [out] */ LPWSTR *pProxyList,
  335. /* [out] */ LPWSTR *pProxyBypassList )
  336. {
  337. EXTERNAL_FUNC_WRAP( GetProxySettingsInternal( pProxyUsage, pProxyList, pProxyBypassList ) )
  338. }
  339. HRESULT STDMETHODCALLTYPE TakeOwnershipInternal();
  340. HRESULT STDMETHODCALLTYPE TakeOwnership()
  341. {
  342. EXTERNAL_FUNC_WRAP( TakeOwnershipInternal( ) )
  343. }
  344. // IBackgroundCopyJob2 methods (external)
  345. HRESULT STDMETHODCALLTYPE SetNotifyCmdLine(
  346. /* [in] */ LPCWSTR Program,
  347. /* [in] */ LPCWSTR Parameters )
  348. {
  349. EXTERNAL_FUNC_WRAP( SetNotifyCmdLineInternal( Program, Parameters ) );
  350. }
  351. HRESULT STDMETHODCALLTYPE GetNotifyCmdLine(
  352. /* [out] */ LPWSTR *pProgram,
  353. /* [out] */ LPWSTR *pParameters )
  354. {
  355. EXTERNAL_FUNC_WRAP( GetNotifyCmdLineInternal( pProgram, pParameters ) );
  356. }
  357. HRESULT STDMETHODCALLTYPE GetReplyProgress(
  358. /* [in] */ BG_JOB_REPLY_PROGRESS *pProgress)
  359. {
  360. EXTERNAL_FUNC_WRAP( GetReplyProgressInternal( pProgress) );
  361. }
  362. HRESULT STDMETHODCALLTYPE GetReplyData(
  363. /* [size_is][size_is][out] */ byte **ppBuffer,
  364. /* [unique][out][in] */ UINT64 *pLength)
  365. {
  366. EXTERNAL_FUNC_WRAP( GetReplyDataInternal(ppBuffer, pLength) );
  367. }
  368. HRESULT STDMETHODCALLTYPE SetReplyFileName(
  369. /* [unique][in] */ LPCWSTR ReplyFileName)
  370. {
  371. EXTERNAL_FUNC_WRAP( SetReplyFileNameInternal( ReplyFileName) );
  372. }
  373. HRESULT STDMETHODCALLTYPE GetReplyFileName(
  374. /* [out] */ LPWSTR *pReplyFileName)
  375. {
  376. EXTERNAL_FUNC_WRAP( GetReplyFileNameInternal( pReplyFileName) );
  377. }
  378. HRESULT STDMETHODCALLTYPE SetCredentials(
  379. /* [unique][switch_is][in] */ BG_AUTH_CREDENTIALS *pCredentials)
  380. {
  381. EXTERNAL_FUNC_WRAP( SetCredentialsInternal( pCredentials ) );
  382. }
  383. HRESULT STDMETHODCALLTYPE RemoveCredentials(
  384. /* [unique][switch_is][in] */ BG_AUTH_TARGET Target,
  385. BG_AUTH_SCHEME Scheme )
  386. {
  387. EXTERNAL_FUNC_WRAP( RemoveCredentialsInternal( Target, Scheme ) );
  388. }
  389. // internal versions of IBackgroundCopyJob2 methods
  390. HRESULT STDMETHODCALLTYPE SetNotifyCmdLineInternal(
  391. /* [in] */ LPCWSTR Program,
  392. /* [in] */ LPCWSTR Parameters );
  393. HRESULT STDMETHODCALLTYPE GetNotifyCmdLineInternal(
  394. /* [out] */ LPWSTR *pProgram,
  395. /* [out] */ LPWSTR *pParameters );
  396. HRESULT STDMETHODCALLTYPE GetReplyProgressInternal(
  397. /* [in] */ BG_JOB_REPLY_PROGRESS *pProgress);
  398. HRESULT STDMETHODCALLTYPE GetReplyDataInternal(
  399. /* [size_is][size_is][out] */ byte **ppBuffer,
  400. /* [unique][out][in] */ UINT64 *pLength);
  401. HRESULT STDMETHODCALLTYPE SetReplyFileNameInternal(
  402. /* [unique][in] */ LPCWSTR ReplyFileName);
  403. HRESULT STDMETHODCALLTYPE GetReplyFileNameInternal(
  404. /* [out] */ LPWSTR *pReplyFileName);
  405. HRESULT STDMETHODCALLTYPE SetCredentialsInternal(
  406. /* [unique][switch_is][in] */ BG_AUTH_CREDENTIALS *pCredentials);
  407. HRESULT STDMETHODCALLTYPE RemoveCredentialsInternal(
  408. /* [unique][switch_is][in] */ BG_AUTH_TARGET Target,
  409. BG_AUTH_SCHEME Scheme );
  410. // Other methods
  411. CJobExternal();
  412. ~CJobExternal();
  413. private:
  414. CJob *pJob;
  415. long m_refs;
  416. long m_ServiceInstance;
  417. void SetInterfaceClass(
  418. CJob *pVal
  419. )
  420. {
  421. pJob = pVal;
  422. }
  423. void NotifyInternalDelete()
  424. {
  425. // Release the internal refcount
  426. Release();
  427. }
  428. };
  429. class CUnknownFileSizeItem
  430. {
  431. public:
  432. CFile *const m_file;
  433. StringHandle m_url;
  434. CUnknownFileSizeItem(
  435. CFile *pFile,
  436. StringHandle URL ) :
  437. m_file( pFile ),
  438. m_url( URL )
  439. {
  440. }
  441. };
  442. class CUnknownFileSizeList : public list<CUnknownFileSizeItem>
  443. {
  444. public:
  445. bool Add( CFile *pFile, const StringHandle & URL )
  446. {
  447. try
  448. {
  449. push_back( CUnknownFileSizeItem( pFile, URL ) );
  450. }
  451. catch( ComError Error )
  452. {
  453. return false;
  454. }
  455. return true;
  456. }
  457. };
  458. class COldJobInterface;
  459. class COldGroupInterface;
  460. class CJob :
  461. public IntrusiveList<CJob>::Link,
  462. public CJobInactivityTimeout,
  463. public CJobRetryItem,
  464. public CJobCallbackItem,
  465. public CJobNoProgressItem,
  466. public CJobModificationItem
  467. {
  468. friend class CGroupList;
  469. friend class CJobExternal;
  470. friend class COldJobInterface;
  471. friend class COldGroupInterface;
  472. public:
  473. class CFileList : public vector<CFile *>
  474. {
  475. public:
  476. HRESULT Serialize( HANDLE hFile );
  477. void Unserialize( HANDLE hFile, CJob* Job );
  478. void Delete( iterator Initial, iterator Terminal );
  479. };
  480. void HandleAddFile();
  481. HRESULT AddFileSet(
  482. /* [in] */ ULONG cFileCount,
  483. /* [size_is][in] */ BG_FILE_INFO *pFileSet
  484. );
  485. HRESULT AddFile(
  486. /* [in] */ LPCWSTR RemoteUrl,
  487. /* [in] */ LPCWSTR LocalName,
  488. bool SingleAdd );
  489. virtual HRESULT Suspend();
  490. virtual HRESULT Resume();
  491. virtual HRESULT Cancel();
  492. virtual HRESULT Complete();
  493. GUID GetId() const
  494. {
  495. return m_id;
  496. }
  497. BG_JOB_TYPE GetType() const
  498. {
  499. return m_type;
  500. }
  501. void GetProgress(
  502. /* [out] */ BG_JOB_PROGRESS *pVal) const;
  503. void GetTimes(
  504. /* [out] */ BG_JOB_TIMES *pVal) const;
  505. HRESULT SetDisplayName(
  506. /* [in] */ LPCWSTR Val);
  507. HRESULT GetDisplayName(
  508. /* [out] */ LPWSTR *pVal) const;
  509. HRESULT SetDescription(
  510. /* [in] */ LPCWSTR Val);
  511. HRESULT GetDescription(
  512. /* [out] */ LPWSTR *pVal) const;
  513. HRESULT SetPriority(
  514. /* [in] */ BG_JOB_PRIORITY Val);
  515. HRESULT GetOwner(
  516. /* [out] */ LPWSTR *pVal) const;
  517. HRESULT SetNotifyFlags(
  518. /* [in] */ ULONG Val);
  519. ULONG GetNotifyFlags() const
  520. {
  521. return m_NotifyFlags;
  522. }
  523. HRESULT
  524. SetNotifyInterface(
  525. IUnknown * Val
  526. );
  527. HRESULT
  528. GetNotifyInterface(
  529. IUnknown ** ppVal
  530. ) const;
  531. BOOL
  532. TestNotifyInterface();
  533. HRESULT SetMinimumRetryDelay(
  534. /* [in] */ ULONG Seconds);
  535. HRESULT GetMinimumRetryDelay(
  536. /* [out] */ ULONG *Seconds) const;
  537. HRESULT SetNoProgressTimeout(
  538. /* [in] */ ULONG Seconds);
  539. HRESULT GetNoProgressTimeout(
  540. /* [out] */ ULONG *Seconds) const;
  541. HRESULT STDMETHODCALLTYPE GetErrorCount(
  542. /* [out] */ ULONG *Errors) const;
  543. HRESULT
  544. SetProxySettings(
  545. BG_JOB_PROXY_USAGE ProxyUsage,
  546. LPCWSTR ProxyList,
  547. LPCWSTR ProxyBypassList
  548. );
  549. HRESULT
  550. GetProxySettings(
  551. BG_JOB_PROXY_USAGE *pProxyUsage,
  552. LPWSTR *pProxyList,
  553. LPWSTR *pProxyBypassList
  554. ) const;
  555. HRESULT TakeOwnership();
  556. virtual HRESULT
  557. GetReplyProgress(
  558. BG_JOB_REPLY_PROGRESS *pProgress
  559. ) const;
  560. virtual HRESULT
  561. GetReplyFileName(
  562. LPWSTR * pVal
  563. ) const;
  564. virtual HRESULT
  565. SetReplyFileName(
  566. LPCWSTR Val
  567. );
  568. virtual HRESULT
  569. GetReplyData(
  570. byte **ppBuffer,
  571. UINT64 *pLength
  572. ) const;
  573. virtual HRESULT
  574. SetNotifyCmdLine(
  575. LPCWSTR Program,
  576. LPCWSTR Parameters
  577. );
  578. virtual HRESULT
  579. GetNotifyCmdLine(
  580. LPWSTR *pProgram,
  581. LPWSTR *pParameters
  582. ) const;
  583. HRESULT
  584. SetCredentials(
  585. BG_AUTH_CREDENTIALS *pCredentials
  586. );
  587. HRESULT
  588. RemoveCredentials(
  589. BG_AUTH_TARGET Target,
  590. BG_AUTH_SCHEME Scheme
  591. );
  592. // CJobCallbackItem methods
  593. void OnMakeCallback();
  594. // CJobRetryItem methods
  595. virtual void OnRetryJob();
  596. // CJobInactivityTimeout methods
  597. virtual void OnInactivityTimeout();
  598. // CJobNoProgressItem methods
  599. virtual void OnNoProgress();
  600. // CJobModificationItem methods
  601. virtual void OnModificationCallback();
  602. // other methods
  603. virtual void OnNetworkConnect();
  604. virtual void OnNetworkDisconnect();
  605. void RemoveFromManager();
  606. void CancelWorkitems();
  607. // TaskSchedulerWorkItem
  608. SidHandle GetSid()
  609. {
  610. return m_NotifySid;
  611. }
  612. bool
  613. IsCallbackEnabled(
  614. DWORD bit
  615. );
  616. void ScheduleModificationCallback();
  617. CJob(
  618. LPCWSTR Name,
  619. BG_JOB_TYPE Type,
  620. REFGUID JobId,
  621. SidHandle NotifySid
  622. );
  623. protected:
  624. #define NO_FILE_INDEX LONG_MIN
  625. #define REPLY_FILE_INDEX (-1)
  626. bool
  627. RecordError(
  628. QMErrInfo * ErrInfo,
  629. LONG FileIndex
  630. );
  631. void
  632. LogUnsuccessfulFileDeletion(
  633. CFileList & files
  634. );
  635. //
  636. // used only by unserialize
  637. //
  638. CJob();
  639. public:
  640. virtual ~CJob();
  641. BG_JOB_PRIORITY _GetPriority() const
  642. {
  643. return m_priority;
  644. }
  645. BG_JOB_STATE _GetState() const
  646. {
  647. return m_state;
  648. }
  649. void SetState( BG_JOB_STATE state );
  650. bool
  651. CheckStateTransition(
  652. BG_JOB_STATE Old,
  653. BG_JOB_STATE New
  654. );
  655. inline SidHandle GetOwnerSid()
  656. {
  657. return m_sd->GetOwnerSid();
  658. }
  659. BOOL IsIncomplete() const
  660. {
  661. if (m_state < BG_JOB_STATE_TRANSFERRED)
  662. {
  663. return TRUE;
  664. }
  665. return FALSE;
  666. }
  667. bool ShouldThrottle() const
  668. {
  669. return (m_priority!=BG_JOB_PRIORITY_FOREGROUND);
  670. }
  671. HRESULT DeleteFileIndex( ULONG index );
  672. HRESULT IsVisible();
  673. bool IsOwner( SidHandle user );
  674. virtual bool IsRunning();
  675. virtual bool IsRunnable();
  676. virtual void Transfer();
  677. void
  678. SetTransientError(
  679. QMErrInfo & ErrInfo,
  680. LONG FileIndex,
  681. bool fRetryLater,
  682. bool fUpdateTime
  683. );
  684. virtual void
  685. FileComplete();
  686. virtual void
  687. FileTransientError(
  688. QMErrInfo * ErrInfo
  689. );
  690. virtual void
  691. FileFatalError(
  692. QMErrInfo * ErrInfo
  693. );
  694. virtual void
  695. FileChangedOnServer()
  696. {
  697. UpdateModificationTime();
  698. }
  699. virtual void UpdateProgress(
  700. UINT64 BytesTransferred,
  701. UINT64 BytesTotal
  702. );
  703. void JobTransferred();
  704. HRESULT CommitTemporaryFiles();
  705. HRESULT RemoveTemporaryFiles( DWORD StartingIndex=0 );
  706. void
  707. UpdateModificationTime(
  708. bool fReplace = TRUE
  709. );
  710. void
  711. UpdateLastAccessTime(
  712. );
  713. void SetCompletionTime( const FILETIME *pftCompletionTime = 0 );
  714. void SetModificationTime( const FILETIME *pftModificationTime = 0 );
  715. void SetLastAccessTime( const FILETIME *pftModificationTime = 0 );
  716. CFile * GetCurrentFile() const
  717. {
  718. if (m_CurrentFile < m_files.size())
  719. {
  720. return m_files[ m_CurrentFile ];
  721. }
  722. else
  723. {
  724. return NULL;
  725. }
  726. }
  727. virtual bool IsTransferringToDrive( const WCHAR *CanonicalVolume );
  728. BOOL IsEmpty() const
  729. {
  730. if (m_files.size() == 0)
  731. {
  732. return TRUE;
  733. }
  734. return FALSE;
  735. }
  736. virtual CFile * _GetFileIndex( LONG index ) const;
  737. virtual HRESULT Serialize( HANDLE hFile );
  738. virtual void Unserialize( HANDLE hFile, int Type );
  739. static CJob * UnserializeJob( HANDLE hFile );
  740. CJobExternal* GetExternalInterface()
  741. {
  742. return m_ExternalInterface;
  743. }
  744. COldGroupInterface *GetOldExternalGroupInterface()
  745. {
  746. return m_OldExternalGroupInterface;
  747. }
  748. void SetOldExternalGroupInterface( COldGroupInterface *GroupInterface )
  749. {
  750. ASSERT( !m_OldExternalGroupInterface );
  751. m_OldExternalGroupInterface = GroupInterface;
  752. }
  753. COldJobInterface *GetOldExternalJobInterface() const
  754. {
  755. return m_OldExternalJobInterface;
  756. }
  757. void SetOldExternalJobInterface( COldJobInterface *JobInterface )
  758. {
  759. ASSERT( !m_OldExternalJobInterface );
  760. m_OldExternalJobInterface = JobInterface;
  761. }
  762. void UnlinkFromExternalInterfaces();
  763. void NotifyInternalDelete()
  764. {
  765. GetExternalInterface()->NotifyInternalDelete();
  766. }
  767. ULONG AddRef(void)
  768. {
  769. return GetExternalInterface()->AddRef();
  770. }
  771. ULONG Release(void)
  772. {
  773. return GetExternalInterface()->Release();
  774. }
  775. HRESULT CheckClientAccess(
  776. IN DWORD RequestedAccess
  777. ) const;
  778. void ScheduleCompletionCallback(
  779. DWORD Seconds = 0
  780. );
  781. void ScheduleErrorCallback(
  782. DWORD Seconds = 0
  783. );
  784. void RetryNow();
  785. void RecalcTransientError( bool ForResume=false );
  786. const CJobError *GetError() const
  787. {
  788. if ( !m_error.IsErrorSet() )
  789. return NULL;
  790. return &m_error;
  791. }
  792. //--------------------------------------------------------------------
  793. BG_JOB_PRIORITY m_priority;
  794. BG_JOB_STATE m_state;
  795. BG_JOB_TYPE m_type;
  796. void OnDiskChange( const WCHAR *CanonicalVolume, DWORD VolumeSerialNumber );
  797. void OnDismount( const WCHAR *CanonicalVolume );
  798. bool OnDeviceLock( const WCHAR *CanonicalVolume );
  799. bool OnDeviceUnlock( const WCHAR *CanonicalVolume );
  800. bool AreRemoteSizesKnown()
  801. {
  802. for(CFileList::iterator iter = m_files.begin(); iter != m_files.end(); iter++ )
  803. {
  804. if ( (*iter)->_GetBytesTotal() == -1 )
  805. return false;
  806. }
  807. return true;
  808. }
  809. bool
  810. VerifyFileSizes(
  811. HANDLE hToken
  812. );
  813. CUnknownFileSizeList* GetUnknownFileSizeList() throw( ComError );
  814. const PROXY_SETTINGS & QueryProxySettings() const
  815. {
  816. return m_ProxySettings;
  817. }
  818. const CCredentialsContainer & QueryCredentialsList() const
  819. {
  820. return m_Credentials;
  821. }
  822. virtual StringHandle GetHostId() const
  823. {
  824. return StringHandle();
  825. }
  826. virtual DWORD GetHostIdFallbackTimeout() const
  827. {
  828. return 0xFFFFFFFF;
  829. }
  830. enum ChangeType
  831. {
  832. CHG_CANCEL,
  833. CHG_TAKE_OWNERSHIP,
  834. CHG_SETPROP
  835. };
  836. enum PropertyType
  837. {
  838. PROP_NONE,
  839. PROP_NAME,
  840. PROP_DESCRIPTION
  841. };
  842. HRESULT NonOwnerModificationCheck(
  843. SidHandle CurrentSid,
  844. enum ChangeType Change,
  845. enum PropertyType Property
  846. );
  847. virtual HRESULT
  848. ExcludeFilesFromBackup(
  849. IN IVssCreateWriterMetadata *pMetadata
  850. );
  851. protected:
  852. GUID m_id;
  853. StringHandle m_name;
  854. StringHandle m_description;
  855. StringHandle m_appid;
  856. SidHandle m_NotifySid;
  857. IBackgroundCopyCallback * m_NotifyPointer;
  858. DWORD m_NotifyFlags;
  859. BOOL m_fGroupNotifySid;
  860. StringHandle m_NotifyProgram;
  861. StringHandle m_NotifyParameters;
  862. long m_NotifyLaunchAttempts;
  863. CJobSecurityDescriptor * m_sd;
  864. LONG m_CurrentFile;
  865. CFileList m_files;
  866. CJobError m_error;
  867. ULONG m_retries;
  868. ULONG m_MinimumRetryDelay;
  869. ULONG m_NoProgressTimeout;
  870. FILETIME m_CreationTime;
  871. FILETIME m_LastAccessTime;
  872. FILETIME m_ModificationTime;
  873. FILETIME m_TransferCompletionTime;
  874. FILETIME m_SerializeTime;
  875. CJobExternal * m_ExternalInterface;
  876. static GENERIC_MAPPING s_AccessMapping;
  877. COldGroupInterface *m_OldExternalGroupInterface;
  878. COldJobInterface *m_OldExternalJobInterface;
  879. PROXY_SETTINGS m_ProxySettings;
  880. CCredentialsContainer m_Credentials;
  881. bool m_fVolumeLocked;
  882. bool m_FilesVerified;
  883. //--------------------------------------------------------------------
  884. HRESULT InterfaceCallback();
  885. HRESULT CmdLineCallback();
  886. HRESULT RescheduleCallback();
  887. HRESULT OldInterfaceCallback();
  888. HRESULT
  889. UpdateString(
  890. StringHandle & destination,
  891. const StringHandle & Val
  892. );
  893. HRESULT
  894. SetLimitedString(
  895. StringHandle & destination,
  896. LPCWSTR Val,
  897. SIZE_T limit
  898. );
  899. };
  900. class CUploadJob : public CJob
  901. {
  902. public:
  903. virtual HRESULT Serialize(HANDLE hFile);
  904. virtual void Unserialize(HANDLE hFile, int Type);
  905. CUploadJob(
  906. LPCWSTR Name,
  907. BG_JOB_TYPE Type,
  908. REFGUID JobId,
  909. SidHandle NotifySid
  910. );
  911. CUploadJob() : m_ReplyFile( 0 )
  912. {
  913. }
  914. virtual ~CUploadJob();
  915. virtual HRESULT Resume();
  916. virtual HRESULT Cancel();
  917. virtual HRESULT Complete();
  918. UPLOAD_DATA & GetUploadData() { return m_UploadData; }
  919. CFile * GetUploadFile() { return m_files[ 0 ]; }
  920. virtual StringHandle GetHostId() const
  921. {
  922. return m_UploadData.HostId;
  923. }
  924. virtual DWORD GetHostIdFallbackTimeout() const
  925. {
  926. return m_UploadData.HostIdFallbackTimeout;
  927. }
  928. virtual CFile * _GetFileIndex( LONG index ) const;
  929. virtual bool IsRunnable();
  930. virtual void Transfer();
  931. virtual bool IsTransferringToDrive( const WCHAR *CanonicalVolume );
  932. virtual void
  933. FileComplete();
  934. virtual void
  935. FileTransientError(
  936. QMErrInfo * ErrInfo
  937. );
  938. virtual void
  939. FileFatalError(
  940. QMErrInfo * ErrInfo
  941. );
  942. virtual void OnRetryJob();
  943. virtual void OnInactivityTimeout();
  944. bool SessionInProgress()
  945. {
  946. if (m_UploadData.State > UPLOAD_STATE_CREATE_SESSION &&
  947. m_UploadData.State < UPLOAD_STATE_CLOSED)
  948. {
  949. return true;
  950. }
  951. return false;
  952. }
  953. void SetReplyFile( CFile * file ) throw( ComError );
  954. CFile * QueryReplyFile() { return m_ReplyFile; }
  955. StringHandle QueryReplyFileName() { return m_ReplyFileName; }
  956. HRESULT GenerateReplyFile( bool fSerialize );
  957. HRESULT DeleteGeneratedReplyFile();
  958. HRESULT RemoveReplyFile();
  959. HRESULT CommitReplyFile();
  960. virtual HRESULT
  961. GetReplyProgress(
  962. BG_JOB_REPLY_PROGRESS *pProgress
  963. ) const;
  964. virtual HRESULT
  965. GetReplyFileName(
  966. LPWSTR * pVal
  967. ) const;
  968. virtual HRESULT
  969. SetReplyFileName(
  970. LPCWSTR Val
  971. );
  972. virtual HRESULT
  973. GetReplyData(
  974. byte **ppBuffer,
  975. UINT64 *pLength
  976. ) const;
  977. // This is a hack because CJob cannot access a protected member of CUploadJob
  978. //
  979. void ClearOwnFileNameBit() { m_fOwnReplyFileName = false; }
  980. virtual void UpdateProgress(
  981. UINT64 BytesTransferred,
  982. UINT64 BytesTotal
  983. );
  984. bool CheckHostIdFallbackTimeout();
  985. virtual HRESULT
  986. ExcludeFilesFromBackup(
  987. IN IVssCreateWriterMetadata *pMetadata
  988. );
  989. protected:
  990. UPLOAD_DATA m_UploadData;
  991. CFile * m_ReplyFile;
  992. StringHandle m_ReplyFileName;
  993. bool m_fOwnReplyFileName;
  994. };