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.

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