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.

550 lines
15 KiB

  1. /************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. bitsext.h
  5. Abstract :
  6. Main file for snapin.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. #ifndef _BITSEXT_H_
  11. #define _BITSEXT_H_
  12. class ComError
  13. {
  14. public:
  15. const HRESULT m_Hr;
  16. ComError( HRESULT Hr ) :
  17. m_Hr( Hr )
  18. {
  19. }
  20. };
  21. inline void THROW_COMERROR( HRESULT Hr )
  22. {
  23. if ( FAILED( Hr ) )
  24. throw ComError( Hr );
  25. }
  26. // Event Log Source
  27. const WCHAR * const EVENT_LOG_SOURCE_NAME=L"BITS Extensions";
  28. const WCHAR * const EVENT_LOG_KEY_NAME=L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\BITS Extensions";
  29. #include "beventlog.h"
  30. // IIS MMC node types
  31. const GUID g_IISInstanceNode = {0xa841b6c7, 0x7577, 0x11d0, {0xbb, 0x1f, 0x00, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  32. const GUID g_IISChildNode = {0xa841b6c8, 0x7577, 0x11d0, {0xbb, 0x1f, 0x00, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  33. class CBITSExtensionSetup;
  34. class CNonDelegatingIUnknown : public IUnknown
  35. {
  36. ULONG m_cref;
  37. CBITSExtensionSetup *m_DelegatingIUnknown;
  38. public:
  39. CNonDelegatingIUnknown( CBITSExtensionSetup * DelegatingIUnknown );
  40. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject);
  41. STDMETHODIMP_(ULONG) AddRef(void);
  42. STDMETHODIMP_(ULONG) Release(void);
  43. };
  44. class CBITSExtensionSetup : public IBITSExtensionSetup, public IADsExtension
  45. {
  46. private:
  47. IUnknown* m_pOuter;
  48. IDispatch* m_OuterDispatch;
  49. ITypeInfo* m_TypeInfo;
  50. IUnknown* m_pObject;
  51. BSTR m_ADSIPath;
  52. IBITSExtensionSetup* m_RemoteInterface;
  53. WCHAR * m_Path;
  54. bool m_InitComplete;
  55. CNonDelegatingIUnknown m_DelegationIUnknown;
  56. PropertyIDManager* m_PropertyMan;
  57. LONG m_Lock;
  58. HRESULT LoadPath();
  59. HRESULT ConnectToRemoteExtension();
  60. HRESULT LoadTypeInfo();
  61. public:
  62. CBITSExtensionSetup( IUnknown *Outer, IUnknown *Object );
  63. virtual ~CBITSExtensionSetup();
  64. IUnknown *GetNonDelegationIUknown()
  65. {
  66. return &m_DelegationIUnknown;
  67. }
  68. ///////////////////////////////
  69. // Interface IUnknown
  70. ///////////////////////////////
  71. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  72. STDMETHODIMP_(ULONG) AddRef();
  73. STDMETHODIMP_(ULONG) Release();
  74. // IADsExtension methods
  75. STDMETHOD(Operate)(ULONG dwCode, VARIANT varData1, VARIANT varData2, VARIANT varData3);
  76. STDMETHOD(PrivateGetIDsOfNames)(
  77. REFIID riid,
  78. OLECHAR FAR* FAR* rgszNames,
  79. unsigned int cNames,
  80. LCID lcid,
  81. DISPID FAR*
  82. rgDispId );
  83. STDMETHOD(PrivateGetTypeInfo)(
  84. unsigned int iTInfo,
  85. LCID lcid,
  86. ITypeInfo FAR* FAR* ppTInfo );
  87. STDMETHOD(PrivateGetTypeInfoCount)(
  88. unsigned int FAR* pctinfo );
  89. STDMETHOD(PrivateInvoke)(
  90. DISPID dispIdMember,
  91. REFIID riid, LCID lcid,
  92. WORD wFlags,
  93. DISPPARAMS FAR* pDispParams,
  94. VARIANT FAR* pVarResult,
  95. EXCEPINFO FAR* pExcepInfo,
  96. unsigned int FAR* puArgErr );
  97. // IDispatch Methods
  98. STDMETHOD(GetIDsOfNames)(
  99. REFIID riid,
  100. OLECHAR FAR* FAR* rgszNames,
  101. unsigned int cNames,
  102. LCID lcid,
  103. DISPID FAR*
  104. rgDispId );
  105. STDMETHOD(GetTypeInfo)(
  106. unsigned int iTInfo,
  107. LCID lcid,
  108. ITypeInfo FAR* FAR* ppTInfo );
  109. STDMETHOD(GetTypeInfoCount)(
  110. unsigned int FAR* pctinfo );
  111. STDMETHOD(Invoke)(
  112. DISPID dispIdMember,
  113. REFIID riid, LCID lcid,
  114. WORD wFlags,
  115. DISPPARAMS FAR* pDispParams,
  116. VARIANT FAR* pVarResult,
  117. EXCEPINFO FAR* pExcepInfo,
  118. unsigned int FAR* puArgErr );
  119. // IBITSExtensionSetup methods
  120. STDMETHODIMP EnableBITSUploads();
  121. STDMETHODIMP DisableBITSUploads();
  122. STDMETHODIMP GetCleanupTaskName( BSTR *pTaskName );
  123. STDMETHODIMP GetCleanupTask( REFIID riid, IUnknown **ppUnk );
  124. };
  125. class CBITSExtensionSetupFactory : public IBITSExtensionSetupFactory
  126. {
  127. long m_cref;
  128. ITypeInfo *m_TypeInfo;
  129. public:
  130. CBITSExtensionSetupFactory();
  131. virtual ~CBITSExtensionSetupFactory();
  132. HRESULT LoadTypeInfo();
  133. STDMETHODIMP GetObject( BSTR Path, IBITSExtensionSetup **ppExtensionSetup );
  134. ///////////////////////////////
  135. // Interface IUnknown
  136. ///////////////////////////////
  137. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  138. STDMETHODIMP_(ULONG) AddRef();
  139. STDMETHODIMP_(ULONG) Release();
  140. STDMETHOD(GetIDsOfNames)(
  141. REFIID riid,
  142. OLECHAR FAR* FAR* rgszNames,
  143. unsigned int cNames,
  144. LCID lcid,
  145. DISPID FAR*
  146. rgDispId );
  147. STDMETHOD(GetTypeInfo)(
  148. unsigned int iTInfo,
  149. LCID lcid,
  150. ITypeInfo FAR* FAR* ppTInfo );
  151. STDMETHOD(GetTypeInfoCount)(
  152. unsigned int FAR* pctinfo );
  153. STDMETHOD(Invoke)(
  154. DISPID dispIdMember,
  155. REFIID riid, LCID lcid,
  156. WORD wFlags,
  157. DISPPARAMS FAR* pDispParams,
  158. VARIANT FAR* pVarResult,
  159. EXCEPINFO FAR* pExcepInfo,
  160. unsigned int FAR* puArgErr );
  161. STDMETHODIMP EnableBITSUploads();
  162. STDMETHODIMP DisableBITSUploads();
  163. };
  164. class CPropSheetExtension : public IExtendPropertySheet
  165. {
  166. private:
  167. ULONG m_cref;
  168. // clipboard format
  169. static bool s_bStaticInitialized;
  170. static UINT s_cfDisplayName;
  171. static UINT s_cfSnapInCLSID;
  172. static UINT s_cfNodeType;
  173. static UINT s_cfSnapInMetapath;
  174. static UINT s_cfSnapInMachineName;
  175. static const UINT s_MaxUploadUnits[];
  176. static const UINT s_NumberOfMaxUploadUnits;
  177. static const UINT64 s_MaxUploadUnitsScales[];
  178. static const UINT s_NumberOfMaxUploadUnitsScales;
  179. static const UINT64 s_MaxUploadLimits[];
  180. static const UINT s_NumberOfMaxUploadLimits;
  181. static const UINT s_TimeoutUnits[];
  182. static const UINT s_NumberOfTimeoutUnits;
  183. static const DWORD s_TimeoutUnitsScales[];
  184. static const UINT s_NumberOfTimeoutUnitsScales;
  185. static const UINT64 s_TimeoutLimits[];
  186. static const UINT s_NumberOfTimeoutLimits;
  187. static const UINT s_NotificationTypes[];
  188. static const UINT s_NumberOfNotificationTypes;
  189. public:
  190. CPropSheetExtension();
  191. ~CPropSheetExtension();
  192. static HRESULT InitializeStatic();
  193. ///////////////////////////////
  194. // Interface IUnknown
  195. ///////////////////////////////
  196. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  197. STDMETHODIMP_(ULONG) AddRef();
  198. STDMETHODIMP_(ULONG) Release();
  199. ///////////////////////////////
  200. // Interface IExtendPropertySheet
  201. ///////////////////////////////
  202. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE CreatePropertyPages(
  203. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  204. /* [in] */ LONG_PTR handle,
  205. /* [in] */ LPDATAOBJECT lpIDataObject);
  206. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryPagesFor(
  207. /* [in] */ LPDATAOBJECT lpDataObject);
  208. private:
  209. TCHAR * m_MetabasePath;
  210. TCHAR * m_MetabaseParent;
  211. TCHAR * m_ComputerName;
  212. TCHAR * m_UNCComputerName;
  213. GUID m_NodeGuid;
  214. IMSAdminBase* m_IISAdminBase;
  215. IBITSExtensionSetup* m_IBITSSetup;
  216. WCHAR m_NodeTypeName[MAX_PATH];
  217. PropertyIDManager* m_PropertyMan;
  218. HWND m_hwnd;
  219. bool m_SettingsChanged; // true if any settings changed
  220. bool m_EnabledSettingChanged; // true if the vdir was enabled or disabled
  221. struct InheritedValues
  222. {
  223. UINT64 MaxUploadSize;
  224. DWORD SessionTimeout;
  225. BITS_SERVER_NOTIFICATION_TYPE NotificationType;
  226. WCHAR * NotificationURL;
  227. WCHAR * HostId;
  228. DWORD FallbackTimeout;
  229. InheritedValues();
  230. ~InheritedValues();
  231. } m_InheritedValues;
  232. ITaskScheduler* m_TaskSched;
  233. ITask* m_CleanupTask;
  234. bool m_CleanupInProgress;
  235. FILETIME m_PrevCleanupStartTime;
  236. HCURSOR m_CleanupCursor;
  237. bool m_CleanupMinWaitTimerFired;
  238. static const UINT s_CleanupMinWaitTimerID = 1;
  239. static const UINT s_CleanupPollTimerID = 2;
  240. static const UINT s_CleanupMinWaitTimerInterval = 2000; // two seconds
  241. static const UINT s_CleanupPollTimerInterval = 1000; // one second
  242. static INT_PTR CALLBACK DialogProcExternal(
  243. HWND hwndDlg, // handle to dialog box
  244. UINT uMsg, // message
  245. WPARAM wParam, // first message parameter
  246. LPARAM lParam // second message parameter
  247. )
  248. {
  249. CPropSheetExtension *pThis;
  250. if ( WM_INITDIALOG == uMsg )
  251. {
  252. pThis = reinterpret_cast<CPropSheetExtension *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  253. SetWindowLongPtr( hwndDlg, DWLP_USER, reinterpret_cast<LONG_PTR>( pThis ) );
  254. }
  255. else
  256. {
  257. pThis = reinterpret_cast<CPropSheetExtension*>( GetWindowLongPtr( hwndDlg, DWLP_USER ) );
  258. }
  259. if ( !pThis )
  260. return FALSE;
  261. pThis->m_hwnd = hwndDlg;
  262. return pThis->DialogProc(
  263. uMsg,
  264. wParam,
  265. lParam );
  266. }
  267. INT_PTR DialogProc(
  268. UINT uMsg, // message
  269. WPARAM wParam, // first message parameter
  270. LPARAM lParam // second message parameter
  271. );
  272. HRESULT ComputeMetabaseParent();
  273. HRESULT ComputeUNCComputerName();
  274. HRESULT OpenSetupInterface();
  275. HRESULT LoadInheritedDWORD(
  276. METADATA_HANDLE mdHandle,
  277. WCHAR * pKeyName,
  278. DWORD PropId,
  279. DWORD * pReturn );
  280. HRESULT LoadInheritedString(
  281. METADATA_HANDLE mdHandle,
  282. WCHAR * pKeyName,
  283. DWORD PropId,
  284. WCHAR ** pReturn );
  285. void LoadInheritedValues( );
  286. void LoadValues( );
  287. void MergeError( HRESULT Hr, HRESULT * LastHr );
  288. HRESULT SaveSimpleString( METADATA_HANDLE mdHandle, DWORD PropId, DWORD EditId );
  289. HRESULT SaveTimeoutValue(
  290. METADATA_HANDLE mdHandle,
  291. DWORD PropId,
  292. DWORD CheckId,
  293. DWORD EditId,
  294. DWORD UnitId );
  295. void SetValues( );
  296. bool ValidateValues( );
  297. bool WarnAboutAccessFlags( );
  298. void AddComboBoxItems( UINT Combo, const UINT *Items, UINT NumberOfItems );
  299. void DisplayError( UINT StringId );
  300. void DisplayError( UINT StringId, HRESULT Hr );
  301. bool DisplayWarning( UINT StringId );
  302. void SetDlgItemTextAsInteger( UINT Id, UINT64 Value );
  303. bool GetDlgItemTextAsInteger( UINT Id, UINT MaxString, UINT64 & Value );
  304. void DisplayHelp( );
  305. void UpdateMaxUploadGroupState( bool IsEnabled );
  306. void UpdateTimeoutGroupState( bool IsEnabled );
  307. void UpdateNotificationsGroupState( bool IsEnabled );
  308. void UpdateConfigGroupState( bool IsEnabled );
  309. void UpdateServerFarmFallbackGroupState( bool IsEnabled );
  310. void UpdateServerFarmGroupState( bool IsEnabled );
  311. void UpdateUploadGroupState( );
  312. void UpdateCleanupState( );
  313. void CloseCleanupItems();
  314. void ScheduleCleanup();
  315. void CleanupNow();
  316. void CleanupTimer( UINT TimerID );
  317. void LoadMaxUploadValue( UINT64 MaxValue );
  318. void LoadTimeoutValue(
  319. DWORD CheckId,
  320. DWORD EditId,
  321. DWORD UnitId,
  322. DWORD Value );
  323. void LoadTimeoutValue( DWORD SessionTimeout );
  324. void LoadNotificationValues( BITS_SERVER_NOTIFICATION_TYPE NotificationType, WCHAR *NotificationURL );
  325. void LoadServerFarmSettings( WCHAR *HostId, DWORD FallbackTimeout );
  326. HRESULT ExtractData(
  327. IDataObject* piDataObject,
  328. CLIPFORMAT cfClipFormat,
  329. BYTE* pbData,
  330. DWORD cbData );
  331. HRESULT ExtractString( IDataObject *piDataObject,
  332. CLIPFORMAT cfClipFormat,
  333. _TCHAR *pstr,
  334. DWORD cchMaxLength)
  335. {
  336. return ExtractData( piDataObject, cfClipFormat, (PBYTE)pstr, cchMaxLength );
  337. }
  338. HRESULT ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  339. {
  340. return ExtractData( piDataObject, (CLIPFORMAT)s_cfSnapInCLSID, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  341. }
  342. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  343. {
  344. return ExtractData( piDataObject, (CLIPFORMAT)s_cfNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  345. }
  346. HRESULT ExtractSnapInString( IDataObject * piDataObject,
  347. WCHAR * & String,
  348. UINT Format );
  349. HRESULT ExtractSnapInGUID( IDataObject * piDataObject,
  350. GUID & Guid,
  351. UINT Format );
  352. HRESULT SaveMetadataString(
  353. METADATA_HANDLE mdHandle,
  354. DWORD PropId,
  355. WCHAR *Value );
  356. HRESULT SaveMetadataDWORD(
  357. METADATA_HANDLE mdHandle,
  358. DWORD PropId,
  359. DWORD Value );
  360. };
  361. class CSnapinAbout : public ISnapinAbout
  362. {
  363. private:
  364. ULONG m_cref;
  365. HBITMAP m_hSmallImage;
  366. HBITMAP m_hLargeImage;
  367. HBITMAP m_hSmallImageOpen;
  368. HICON m_hAppIcon;
  369. public:
  370. CSnapinAbout();
  371. ~CSnapinAbout();
  372. ///////////////////////////////
  373. // Interface IUnknown
  374. ///////////////////////////////
  375. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  376. STDMETHODIMP_(ULONG) AddRef();
  377. STDMETHODIMP_(ULONG) Release();
  378. ///////////////////////////////
  379. // Interface ISnapinAbout
  380. ///////////////////////////////
  381. STDMETHODIMP GetSnapinDescription(
  382. /* [out] */ LPOLESTR *lpDescription);
  383. STDMETHODIMP GetProvider(
  384. /* [out] */ LPOLESTR *lpName);
  385. STDMETHODIMP GetSnapinVersion(
  386. /* [out] */ LPOLESTR *lpVersion);
  387. STDMETHODIMP GetSnapinImage(
  388. /* [out] */ HICON *hAppIcon);
  389. STDMETHODIMP GetStaticFolderImage(
  390. /* [out] */ HBITMAP *hSmallImage,
  391. /* [out] */ HBITMAP *hSmallImageOpen,
  392. /* [out] */ HBITMAP *hLargeImage,
  393. /* [out] */ COLORREF *cMask);
  394. ///////////////////////////////
  395. // Private Interface
  396. ///////////////////////////////
  397. private:
  398. HRESULT LoadStringHelper(
  399. LPOLESTR *lpDest,
  400. UINT Id );
  401. };
  402. WCHAR *
  403. ConvertObjectPathToADSI(
  404. const WCHAR *ObjectPath );
  405. HRESULT
  406. ConnectToTaskScheduler(
  407. LPWSTR ComputerName,
  408. ITaskScheduler ** TaskScheduler );
  409. HRESULT
  410. FindWorkItemForVDIR(
  411. ITaskScheduler *TaskScheduler,
  412. LPCWSTR Key,
  413. ITask **ReturnedTask,
  414. LPWSTR *ReturnedTaskName );
  415. HRESULT
  416. IsBITSEnabledOnVDir(
  417. PropertyIDManager *PropertyManager,
  418. IMSAdminBase *IISAdminBase,
  419. LPWSTR VirtualDirectory,
  420. BOOL *IsEnabled );
  421. HRESULT
  422. EnableBITSForVDIR(
  423. PropertyIDManager *PropertyManager,
  424. IMSAdminBase *IISAdminBase,
  425. LPCWSTR Path );
  426. HRESULT
  427. DisableBITSForVDIR(
  428. PropertyIDManager *PropertyManager,
  429. IMSAdminBase *IISAdminBase,
  430. LPCWSTR Path,
  431. bool DisableForEnable );
  432. void CleanupForRemoval( LPCWSTR Path );
  433. #endif _BITSEXT_H_