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.

320 lines
6.3 KiB

  1. /************************************************************************
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name :
  4. bitsadmin.h
  5. Abstract :
  6. Main header file for bitsadmin.
  7. Author :
  8. Mike Zoran mzoran May 2002.
  9. Revision History :
  10. Notes:
  11. *************************************************************************/
  12. #define MAKE_UNICODE(x) L ## x
  13. #include <windows.h>
  14. #include <sddl.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <bits.h>
  19. #include <bits1_5.h>
  20. #include <ntverp.h>
  21. #include <locale.h>
  22. #include <strsafe.h>
  23. #include <memory>
  24. void CheckHR( const WCHAR *pFailTxt, HRESULT Hr );
  25. using namespace std;
  26. typedef auto_ptr<WCHAR> CAutoString;
  27. const UINT MAX_GUID_CHARS=40;
  28. typedef OLECHAR GUIDSTR[MAX_GUID_CHARS];
  29. extern bool g_Shutdown;
  30. extern HANDLE g_MainThreadHandle;
  31. void PollShutdown();
  32. void SignalShutdown( DWORD MilliTimeout );
  33. class AbortException
  34. {
  35. public:
  36. int Code;
  37. AbortException( int ErrorCode ) :
  38. Code( ErrorCode )
  39. {
  40. }
  41. };
  42. template<class T> class SmartRefPointer
  43. {
  44. private:
  45. T * m_Interface;
  46. void ReleaseIt()
  47. {
  48. if ( m_Interface )
  49. m_Interface->Release();
  50. m_Interface = NULL;
  51. }
  52. void RefIt()
  53. {
  54. if ( m_Interface )
  55. m_Interface->AddRef();
  56. }
  57. public:
  58. SmartRefPointer()
  59. {
  60. m_Interface = NULL;
  61. }
  62. SmartRefPointer( T * RawInterface )
  63. {
  64. m_Interface = RawInterface;
  65. RefIt();
  66. }
  67. SmartRefPointer( SmartRefPointer & Other )
  68. {
  69. m_Interface = Other.m_Interface;
  70. RefIt();
  71. }
  72. ~SmartRefPointer()
  73. {
  74. ReleaseIt();
  75. }
  76. T * Get() const
  77. {
  78. return m_Interface;
  79. }
  80. T * Release()
  81. {
  82. T * temp = m_Interface;
  83. m_Interface = NULL;
  84. return temp;
  85. }
  86. void Clear()
  87. {
  88. ReleaseIt();
  89. }
  90. T** GetRecvPointer()
  91. {
  92. ReleaseIt();
  93. return &m_Interface;
  94. }
  95. SmartRefPointer & operator=( SmartRefPointer & Other )
  96. {
  97. ReleaseIt();
  98. m_Interface = Other.m_Interface;
  99. RefIt();
  100. return *this;
  101. }
  102. T* operator->() const
  103. {
  104. return m_Interface;
  105. }
  106. operator const T*() const
  107. {
  108. return m_Interface;
  109. }
  110. };
  111. typedef SmartRefPointer<IUnknown> SmartIUnknownPointer;
  112. typedef SmartRefPointer<IBackgroundCopyManager> SmartManagerPointer;
  113. typedef SmartRefPointer<IBackgroundCopyJob> SmartJobPointer;
  114. typedef SmartRefPointer<IBackgroundCopyJob2> SmartJob2Pointer;
  115. typedef SmartRefPointer<IBackgroundCopyError> SmartJobErrorPointer;
  116. typedef SmartRefPointer<IBackgroundCopyFile> SmartFilePointer;
  117. typedef SmartRefPointer<IEnumBackgroundCopyFiles> SmartEnumFilesPointer;
  118. typedef SmartRefPointer<IEnumBackgroundCopyJobs> SmartEnumJobsPointer;
  119. class AutoStringPointer
  120. {
  121. private:
  122. WCHAR * m_String;
  123. public:
  124. AutoStringPointer( WCHAR *pString = NULL )
  125. {
  126. m_String = pString;
  127. }
  128. ~AutoStringPointer()
  129. {
  130. delete m_String;
  131. m_String = NULL;
  132. }
  133. WCHAR *Get()
  134. {
  135. return m_String;
  136. }
  137. WCHAR ** GetRecvPointer()
  138. {
  139. delete m_String;
  140. m_String = NULL;
  141. return &m_String;
  142. }
  143. void Clear()
  144. {
  145. delete m_String;
  146. m_String = NULL;
  147. }
  148. operator WCHAR *() const
  149. {
  150. return m_String;
  151. }
  152. AutoStringPointer & operator=( WCHAR *pString )
  153. {
  154. delete m_String;
  155. m_String = pString;
  156. return *this;
  157. }
  158. };
  159. extern WCHAR* pComputerName;
  160. extern SmartManagerPointer g_Manager;
  161. extern bool bRawReturn;
  162. extern bool bWrap;
  163. extern bool bExplicitWrap;
  164. inline HRESULT
  165. Job2FromJob(
  166. SmartJobPointer & Job,
  167. SmartJob2Pointer & Job2
  168. )
  169. {
  170. return Job->QueryInterface( __uuidof(IBackgroundCopyJob2), (void **) Job2.GetRecvPointer() );
  171. }
  172. //
  173. // Generic print operators and input functions
  174. //
  175. class BITSOUTStream
  176. {
  177. HANDLE Handle;
  178. char MBBuffer[ 4096 * 8 ];
  179. WCHAR Buffer[ 4096 ];
  180. DWORD BufferUsed;
  181. public:
  182. BITSOUTStream( DWORD StdHandle ) :
  183. BufferUsed( 0 ),
  184. Handle( GetStdHandle( StdHandle ) )
  185. {
  186. }
  187. void FlushBuffer( bool HasNewLine=false );
  188. void OutputString( const WCHAR *RawString );
  189. HANDLE GetHandle() { return Handle; }
  190. };
  191. extern BITSOUTStream bcout;
  192. extern BITSOUTStream bcerr;
  193. BITSOUTStream& operator<< (BITSOUTStream &s, const WCHAR * String );
  194. BITSOUTStream& operator<< (BITSOUTStream &s, UINT64 Number );
  195. WCHAR * HRESULTToString( HRESULT Hr );
  196. BITSOUTStream& operator<< ( BITSOUTStream &s, AutoStringPointer & String );
  197. BITSOUTStream& operator<< ( BITSOUTStream &s, GUID & guid );
  198. BITSOUTStream& operator<< ( BITSOUTStream &s, FILETIME & filetime );
  199. BITSOUTStream& operator<< ( BITSOUTStream &s, BG_JOB_PROXY_USAGE ProxyUsage );
  200. ULONG InputULONG( WCHAR *pText );
  201. class PrintSidString
  202. {
  203. public:
  204. WCHAR *m_SidString;
  205. PrintSidString( WCHAR * SidString ) :
  206. m_SidString( SidString )
  207. {
  208. }
  209. };
  210. void BITSADMINSetThreadUILanguage();
  211. BOOL LocalConvertStringSidToSid( PWSTR StringSid, PSID *Sid, PWSTR *End );
  212. BOOL AltConvertStringSidToSid( LPCWSTR StringSid, PSID *Sid );
  213. BITSOUTStream& operator<< ( BITSOUTStream &s, PrintSidString SidString );
  214. void * _cdecl operator new( size_t Size );
  215. void _cdecl operator delete( void *Mem );
  216. void RestoreConsole();
  217. void PollShutdown();
  218. void ShutdownAPC( ULONG_PTR );
  219. void SignalShutdown( DWORD MilliTimeout );
  220. void CheckHR( const WCHAR *pFailTxt, HRESULT Hr );
  221. //
  222. // Code to handle console pretty printing mode changes
  223. //
  224. extern bool bConsoleInfoRetrieved;
  225. extern HANDLE hConsole;
  226. extern CRITICAL_SECTION CritSection;
  227. extern CONSOLE_SCREEN_BUFFER_INFO StartConsoleInfo;
  228. extern DWORD StartConsoleMode;
  229. void SetupConsole();
  230. void ChangeConsoleMode();
  231. void RestoreConsole();
  232. void ClearScreen();
  233. //
  234. // Classes set the intensity mode for the text. Use as follows
  235. // bcout << L"Some normal text " << AddIntensity();
  236. // bcout << L"Intense text" << ResetIntensity() << L"Normal";
  237. //
  238. class AddIntensity
  239. {
  240. };
  241. BITSOUTStream & operator<<( BITSOUTStream & s, AddIntensity );
  242. class ResetIntensity
  243. {
  244. };
  245. BITSOUTStream & operator<<( BITSOUTStream & s, ResetIntensity );