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.

275 lines
5.8 KiB

  1. /************************************************************************
  2. Copyright (c) 2000 - 2000 Microsoft Corporation
  3. Module Name :
  4. cjob.h
  5. Abstract :
  6. Main header file for files.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. class CFile;
  11. class CJob;
  12. class CFileExternal;
  13. class CJobExternal;
  14. class CFileExternal : public IBackgroundCopyFile
  15. {
  16. public:
  17. friend CFile;
  18. // IUnknown Methods
  19. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  20. ULONG _stdcall AddRef(void);
  21. ULONG _stdcall Release(void);
  22. // IBackgroundCopyFile methods
  23. HRESULT STDMETHODCALLTYPE GetRemoteNameInternal(
  24. /* [out] */ LPWSTR *pVal);
  25. HRESULT STDMETHODCALLTYPE GetRemoteName(
  26. /* [out] */ LPWSTR *pVal)
  27. {
  28. EXTERNAL_FUNC_WRAP( GetRemoteNameInternal( pVal ) )
  29. }
  30. HRESULT STDMETHODCALLTYPE GetLocalNameInternal(
  31. /* [out] */ LPWSTR *pVal);
  32. HRESULT STDMETHODCALLTYPE GetLocalName(
  33. /* [out] */ LPWSTR *pVal)
  34. {
  35. EXTERNAL_FUNC_WRAP( GetLocalNameInternal( pVal ) )
  36. }
  37. HRESULT STDMETHODCALLTYPE GetProgressInternal(
  38. /* [out] */ BG_FILE_PROGRESS *pVal);
  39. HRESULT STDMETHODCALLTYPE GetProgress(
  40. /* [out] */ BG_FILE_PROGRESS *pVal)
  41. {
  42. EXTERNAL_FUNC_WRAP( GetProgressInternal( pVal ) )
  43. }
  44. // other methods
  45. CFileExternal(
  46. CFile * file,
  47. CJobExternal * JobExternal
  48. );
  49. ~CFileExternal();
  50. private:
  51. long m_refs;
  52. long m_ServiceInstance;
  53. CFile * m_file;
  54. CJobExternal * m_JobExternal;
  55. };
  56. class CFile : public ITransferCallback
  57. {
  58. public:
  59. friend CFileExternal;
  60. // ITransferCallback methods
  61. virtual bool
  62. DownloaderProgress(
  63. UINT64 BytesTransferred,
  64. UINT64 BytesTotal
  65. );
  66. virtual bool PollAbort();
  67. virtual bool
  68. UploaderProgress(
  69. UINT64 BytesTransferred
  70. );
  71. // other methods
  72. CFile(
  73. CJob* Job,
  74. BG_JOB_TYPE FileType,
  75. StringHandle RemoteName,
  76. StringHandle LocalName
  77. );
  78. virtual ~CFile();
  79. bool Transfer( HANDLE hToken,
  80. BG_JOB_PRIORITY priority,
  81. const PROXY_SETTINGS & ProxySettings,
  82. const CCredentialsContainer *Credentials,
  83. QMErrInfo & ErrInfo
  84. );
  85. void
  86. DiscoverBytesTotal(
  87. HANDLE Token,
  88. const PROXY_SETTINGS & ProxySettings,
  89. const CCredentialsContainer * Credentials,
  90. QMErrInfo & ErrorInfo
  91. );
  92. HRESULT GetRemoteName( LPWSTR *pVal ) const;
  93. HRESULT GetLocalName( LPWSTR *pVal ) const;
  94. const StringHandle & GetRemoteName() const
  95. {
  96. return m_RemoteName;
  97. }
  98. const StringHandle & GetLocalName() const
  99. {
  100. return m_LocalName;
  101. }
  102. const StringHandle & GetTemporaryName() const
  103. {
  104. return m_TemporaryName;
  105. }
  106. void GetProgress( BG_FILE_PROGRESS *pVal ) const;
  107. HRESULT Serialize( HANDLE hFile );
  108. static CFile * Unserialize( HANDLE hFile, CJob* Job );
  109. UINT64 _GetBytesTransferred() const
  110. {
  111. return m_BytesTransferred;
  112. }
  113. UINT64 _GetBytesTotal() const
  114. {
  115. return m_BytesTotal;
  116. }
  117. void SetBytesTotal( UINT64 BytesTotal )
  118. {
  119. m_BytesTotal = BytesTotal;
  120. }
  121. void SetBytesTransferred( UINT64 BytesTransferred )
  122. {
  123. m_BytesTransferred = BytesTransferred;
  124. }
  125. bool IsCompleted()
  126. {
  127. return m_Completed;
  128. }
  129. bool ReceivedAllData()
  130. {
  131. return (m_BytesTotal == m_BytesTransferred);
  132. }
  133. CFileExternal * CreateExternalInterface();
  134. CJob* GetJob() const
  135. {
  136. return m_Job;
  137. }
  138. HRESULT CheckClientAccess(
  139. IN DWORD RequestedAccess
  140. ) const;
  141. HRESULT MoveTempFile();
  142. HRESULT DeleteTempFile();
  143. HRESULT VerifyLocalName( LPCWSTR name, BG_JOB_TYPE JobType );
  144. BOOL VerifyRemoteName( LPCWSTR name );
  145. static HRESULT VerifyLocalFileName( LPCWSTR name, BG_JOB_TYPE JobType );
  146. bool IsCanonicalVolume( const WCHAR *CanonicalVolume )
  147. {
  148. return ( _wcsicmp( m_CanonicalVolumePath, CanonicalVolume ) == 0 );
  149. }
  150. HRESULT ValidateAccessForUser( SidHandle sid, bool fWrite );
  151. bool ValidateDriveInfo( HANDLE hToken, QMErrInfo & ErrInfo );
  152. bool OnDiskChange( const WCHAR *CanonicalVolume, DWORD VolumeSerialNumber );
  153. bool OnDismount( const WCHAR *CanonicalVolume );
  154. void ChangedOnServer();
  155. static bool IsDriveTypeRemote( UINT DriveType )
  156. {
  157. return
  158. ( DriveType == DRIVE_UNKNOWN ) ||
  159. ( DriveType == DRIVE_NO_ROOT_DIR ) ||
  160. ( DriveType == DRIVE_REMOTE );
  161. }
  162. static bool IsAbsolutePath( const WCHAR * Path )
  163. {
  164. bool ret;
  165. if ( (Path [0] == L'\\' && Path[1] == L'\\') ||
  166. (iswalpha ( Path [0] ) && Path [1] == L':' && Path[ 2 ] == L'\\') ) {
  167. ret = true;
  168. } else {
  169. ret = false;
  170. }
  171. return ret;
  172. }
  173. DWORD GetSizeEstimate()
  174. {
  175. //
  176. // Serialize() will store five file paths and five constants
  177. //
  178. return (5 * MAX_PATH * sizeof(WCHAR)) + 5 * sizeof( UINT64 );
  179. }
  180. HANDLE OpenLocalFileForUpload() throw( ComError );
  181. HRESULT SetLocalFileTime( FILETIME Time );
  182. private:
  183. CFile(
  184. CJob* Job
  185. );
  186. StringHandle m_RemoteName;
  187. StringHandle m_LocalName;
  188. StringHandle m_TemporaryName;
  189. FILETIME m_LocalFileTime;
  190. UINT64 m_BytesTotal;
  191. UINT64 m_BytesTransferred;
  192. bool m_Completed;
  193. CJob * m_Job;
  194. // Drive information
  195. StringHandle m_VolumePath;
  196. StringHandle m_CanonicalVolumePath;
  197. UINT m_DriveType;
  198. DWORD m_VolumeSerialNumber;
  199. };