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.

628 lines
14 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. vs_wmxml.hxx
  5. Abstract:
  6. Declaration of Writer Metadata XML wrapper classes
  7. Brian Berkowitz [brianb] 3/13/2000
  8. TBD:
  9. Add comments.
  10. Revision History:
  11. Name Date Comments
  12. brianb 03/13/2000 Created
  13. brianb 03/22/2000 Added CVssGatherWriterMetadata
  14. --*/
  15. ////////////////////////////////////////////////////////////////////////
  16. // Standard foo for file name aliasing. This code block must be after
  17. // all includes of VSS header files.
  18. //
  19. #ifdef VSS_FILE_ALIAS
  20. #undef VSS_FILE_ALIAS
  21. #endif
  22. #define VSS_FILE_ALIAS "INCWXMLH"
  23. //
  24. ////////////////////////////////////////////////////////////////////////
  25. // forward declarations
  26. class CVssWMFiledesc;
  27. class CVssWMComponent;
  28. // base class used by all writer and component metadata classes.
  29. class CVssMetadataHelper
  30. {
  31. protected:
  32. CXMLDocument m_doc;
  33. // protection for document
  34. CVssSafeCriticalSection m_csDOM;
  35. CVssMetadataHelper(IXMLDOMNode *pNode, IXMLDOMDocument *pDoc) :
  36. m_doc(pNode, pDoc)
  37. {
  38. }
  39. CVssMetadataHelper()
  40. {
  41. }
  42. // initialize critical section used to protect document
  43. void InitializeHelper(CVssFunctionTracer &ft)
  44. {
  45. try
  46. {
  47. m_csDOM.Init();
  48. }
  49. catch(...)
  50. {
  51. ft.Throw(VSSDBG_XML, E_OUTOFMEMORY, L"Cannot initialize critical section");
  52. }
  53. }
  54. // convert string value "yes, no" to boolean
  55. bool ConvertToBoolean
  56. (
  57. IN CVssFunctionTracer &ft,
  58. IN BSTR bstr
  59. ) throw(HRESULT);
  60. // get the value of a string valued attribute of the current element
  61. HRESULT GetStringAttributeValue
  62. (
  63. IN CVssFunctionTracer &ft,
  64. IN LPCWSTR wszAttrName,
  65. IN bool bAttrRequired,
  66. OUT BSTR *pbstrValue
  67. );
  68. // get the value of a boolean valued attribute of the current element
  69. HRESULT GetBooleanAttributeValue
  70. (
  71. IN CVssFunctionTracer &ft,
  72. IN LPCWSTR wszAttrName,
  73. IN bool bRequired,
  74. OUT bool *pbValue
  75. );
  76. // obtain the string value of an attribute
  77. bool get_stringValue
  78. (
  79. IN LPCWSTR wszAttrName,
  80. OUT BSTR *pbstr
  81. ) throw(HRESULT);
  82. // obtain the boolean value of an attribute
  83. bool get_boolValue
  84. (
  85. IN CVssFunctionTracer &ft,
  86. IN LPCWSTR wszAttrName,
  87. OUT bool *pb
  88. ) throw(HRESULT);
  89. void get_VSS_IDValue
  90. (
  91. IN CVssFunctionTracer &ft,
  92. IN LPCWSTR wszAttrName,
  93. OUT VSS_ID *pid
  94. ) throw(HRESULT);
  95. static void MissingElement
  96. (
  97. IN CVssFunctionTracer &ft,
  98. IN LPCWSTR wszElement
  99. );
  100. static void MissingAttribute
  101. (
  102. IN CVssFunctionTracer &ft,
  103. IN LPCWSTR wszAttribute
  104. );
  105. public:
  106. // convert a boolean value to a string ("yes", "no")
  107. static LPCWSTR WszFromBoolean(IN bool b);
  108. // convert a string to a GUID
  109. static void ConvertToVSS_ID
  110. (
  111. IN CVssFunctionTracer &ft,
  112. IN BSTR bstr,
  113. OUT VSS_ID *pId
  114. ) throw(HRESULT);
  115. // convert a VSS_USAGE_TYPE to a string
  116. static LPCWSTR WszFromUsageType
  117. (
  118. IN CVssFunctionTracer &ft,
  119. IN VSS_USAGE_TYPE ut
  120. ) throw(HRESULT);
  121. // convert a string to a VSS_USAGE_TYPE
  122. static VSS_USAGE_TYPE ConvertToUsageType
  123. (
  124. IN CVssFunctionTracer &ft,
  125. IN BSTR bstr
  126. ) throw(HRESULT);
  127. // convert a VSS_SOURCE_TYPE to a string
  128. static LPCWSTR WszFromSourceType
  129. (
  130. IN CVssFunctionTracer &ft,
  131. IN VSS_SOURCE_TYPE st
  132. ) throw(HRESULT);
  133. // convert a string to a VSS_SOURCE_TYPE
  134. static VSS_SOURCE_TYPE ConvertToSourceType
  135. (
  136. IN CVssFunctionTracer &ft,
  137. IN BSTR bstr
  138. ) throw(HRESULT);
  139. // convert a VSS_COMPONENT_TYPE to a string
  140. static LPCWSTR WszFromComponentType
  141. (
  142. IN CVssFunctionTracer &ft,
  143. IN VSS_COMPONENT_TYPE ct,
  144. IN bool bValue
  145. ) throw(HRESULT);
  146. // convert a string to a VSS_COMPONENT_TYPE
  147. static VSS_COMPONENT_TYPE ConvertToComponentType
  148. (
  149. IN CVssFunctionTracer &ft,
  150. IN BSTR bstr,
  151. IN bool bValue
  152. ) throw(HRESULT);
  153. // convert a VSS_RESTOREMETHOD_ENUM to a string
  154. static LPCWSTR WszFromRestoreMethod
  155. (
  156. IN CVssFunctionTracer &ft,
  157. IN VSS_RESTOREMETHOD_ENUM method
  158. ) throw(HRESULT);
  159. // convert a string to a VSS_RESTOREMETHOD_ENUM
  160. static VSS_RESTOREMETHOD_ENUM ConvertToRestoreMethod
  161. (
  162. IN CVssFunctionTracer &ft,
  163. IN BSTR bstr
  164. ) throw(HRESULT);
  165. // convert a VSS_WRITERRESTORE_ENUM to a string
  166. static LPCWSTR WszFromWriterRestore
  167. (
  168. IN CVssFunctionTracer &ft,
  169. IN VSS_WRITERRESTORE_ENUM writerRestore
  170. ) throw(HRESULT);
  171. // convert a string to a VSS_WRITERRESTORE_ENUM
  172. static VSS_WRITERRESTORE_ENUM ConvertToWriterRestore
  173. (
  174. IN CVssFunctionTracer &ft,
  175. IN BSTR bstr
  176. ) throw(HRESULT);
  177. // convert from a VSS_BACKUP_TYPE to a string
  178. static LPCWSTR WszFromBackupType
  179. (
  180. IN CVssFunctionTracer &ft,
  181. IN VSS_BACKUP_TYPE bt
  182. );
  183. // convert from string to VSS_BACKUP_TYPE
  184. static VSS_BACKUP_TYPE ConvertToBackupType
  185. (
  186. IN CVssFunctionTracer &ft,
  187. IN BSTR bstr
  188. );
  189. };
  190. // examine writer metadata
  191. class CVssExamineWriterMetadata :
  192. public IVssExamineWriterMetadata,
  193. public CVssMetadataHelper
  194. {
  195. public:
  196. CVssExamineWriterMetadata() :
  197. m_cRef(0)
  198. {
  199. }
  200. // initialize document from a string
  201. bool Initialize
  202. (
  203. IN BSTR bstrXML
  204. ) throw(HRESULT);
  205. // obtain identity of the writer
  206. STDMETHOD(GetIdentity)
  207. (
  208. OUT VSS_ID *pidInstance,
  209. OUT VSS_ID *pidWriter,
  210. OUT BSTR *pbstrWriterName,
  211. OUT VSS_USAGE_TYPE *pUsage,
  212. OUT VSS_SOURCE_TYPE *pSource
  213. );
  214. // obtain number of include files, exclude files, and components
  215. STDMETHOD(GetFileCounts)
  216. (
  217. OUT UINT *pcIncludeFiles,
  218. OUT UINT *pcExcludeFiles,
  219. OUT UINT *pcComponents
  220. );
  221. // obtain specific include files
  222. STDMETHOD(GetIncludeFile)
  223. (
  224. IN UINT iFile,
  225. OUT IVssWMFiledesc **ppFiledesc
  226. );
  227. // obtain specific exclude files
  228. STDMETHOD(GetExcludeFile)
  229. (
  230. IN UINT iFile,
  231. OUT IVssWMFiledesc **ppFiledesc
  232. );
  233. // obtain specific component
  234. STDMETHOD(GetComponent)
  235. (
  236. IN UINT iComponent,
  237. OUT IVssWMComponent **ppComponent
  238. );
  239. // obtain restoration method
  240. STDMETHOD(GetRestoreMethod)
  241. (
  242. OUT VSS_RESTOREMETHOD_ENUM *pMethod,
  243. OUT BSTR *pbstrService,
  244. OUT BSTR *pbstrUserProcedure,
  245. OUT VSS_WRITERRESTORE_ENUM *pwriterRestore,
  246. OUT bool *pbRebootRequired,
  247. UINT *pcMappings
  248. );
  249. // obtain a specific alternative location mapping
  250. STDMETHOD(GetAlternateLocationMapping)
  251. (
  252. IN UINT iMapping,
  253. OUT IVssWMFiledesc **ppFiledesc
  254. );
  255. // get the backup schema
  256. STDMETHOD(GetBackupSchema)
  257. (
  258. OUT DWORD *pdwSchemaMask
  259. );
  260. // obtain reference to actual XML document
  261. STDMETHOD(GetDocument)(IXMLDOMDocument **pDoc);
  262. // convert document to a XML string
  263. STDMETHOD(SaveAsXML)(BSTR *pbstrXML);
  264. // load document from an XML string
  265. STDMETHOD(LoadFromXML)(BSTR bstrXML);
  266. // IUnknown methods
  267. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  268. STDMETHOD_ (ULONG, AddRef)();
  269. STDMETHOD_ (ULONG, Release)();
  270. private:
  271. // load XML document saved using SaveAsXML
  272. bool LoadDocument(BSTR bstrXML);
  273. // used to load a specific kind of subcomponent of BACKUP_FILES
  274. // COMPONENT, DATABASE, or FILE_GROUP
  275. HRESULT GetFileType
  276. (
  277. IN CVssFunctionTracer &ft,
  278. IN UINT iFile,
  279. IN LPCWSTR wszFileType,
  280. OUT IVssWMFiledesc **ppFiledesc
  281. );
  282. // reference count
  283. LONG m_cRef;
  284. };
  285. // access a component
  286. class CVssWMComponent :
  287. public CVssMetadataHelper,
  288. public IVssWMComponent
  289. {
  290. friend class CVssExamineWriterMetadata;
  291. private:
  292. CVssWMComponent(IXMLDOMNode *pNode) :
  293. CVssMetadataHelper(pNode, NULL),
  294. m_cRef(0)
  295. {
  296. }
  297. // 2nd phase of construction
  298. void Initialize(CVssFunctionTracer &ft)
  299. {
  300. InitializeHelper(ft);
  301. }
  302. public:
  303. // get component information
  304. STDMETHOD(GetComponentInfo)(PVSSCOMPONENTINFO *ppInfo);
  305. // free component information
  306. STDMETHOD(FreeComponentInfo)(PVSSCOMPONENTINFO pInfo);
  307. // obtain a specific file in a file group
  308. STDMETHOD(GetFile)
  309. (
  310. IN UINT iFile,
  311. OUT IVssWMFiledesc **ppFiledesc
  312. );
  313. // obtain a specific physical database file for a database
  314. STDMETHOD(GetDatabaseFile)
  315. (
  316. IN UINT iDBFile,
  317. OUT IVssWMFiledesc **ppFiledesc
  318. );
  319. // obtain a specific physical log file for a database
  320. STDMETHOD(GetDatabaseLogFile)
  321. (
  322. IN UINT iDbLogFile,
  323. OUT IVssWMFiledesc **ppFiledesc
  324. );
  325. STDMETHOD(GetDependency)
  326. (
  327. IN UINT iDependency,
  328. OUT IVssWMDependency **ppDependency
  329. );
  330. // IUnknown methods
  331. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  332. STDMETHOD_ (ULONG, AddRef)();
  333. STDMETHOD_ (ULONG, Release)();
  334. private:
  335. // get a specific component file(file, database, log file)
  336. HRESULT GetComponentFile
  337. (
  338. IN CVssFunctionTracer &ft,
  339. IN LPCWSTR wszElementName,
  340. IN UINT iFile,
  341. OUT IVssWMFiledesc **ppFiledesc
  342. );
  343. LONG m_cRef;
  344. };
  345. // information about a file or set of files
  346. class CVssWMFiledesc :
  347. public IVssWMFiledesc,
  348. public CVssMetadataHelper
  349. {
  350. friend class CVssExamineWriterMetadata;
  351. friend class CVssWMComponent;
  352. friend class CVssComponent;
  353. private:
  354. CVssWMFiledesc(IXMLDOMNode *pNode) :
  355. CVssMetadataHelper(pNode, NULL),
  356. m_cRef(0)
  357. {
  358. }
  359. // 2nd phase of construction
  360. void Initialize(CVssFunctionTracer &ft)
  361. {
  362. InitializeHelper(ft);
  363. }
  364. public:
  365. // get path to toplevel directory
  366. STDMETHOD(GetPath)(OUT BSTR *pbstrPath);
  367. // get filespec (may include wildcards)
  368. STDMETHOD(GetFilespec)(OUT BSTR *pbstrFilespec);
  369. // is path a directory or root of a tree
  370. STDMETHOD(GetRecursive)(OUT bool *pbRecursive);
  371. // alternate location for files
  372. STDMETHOD(GetAlternateLocation)(OUT BSTR *pbstrAlternateLocation);
  373. // backup type flags
  374. STDMETHOD(GetBackupTypeMask)(OUT DWORD *pdwSchemaMask);
  375. // IUnknown methods
  376. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  377. STDMETHOD_ (ULONG, AddRef)();
  378. STDMETHOD_ (ULONG, Release)();
  379. private:
  380. LONG m_cRef;
  381. };
  382. class CVssCreateWriterMetadata : public CVssMetadataHelper
  383. {
  384. public:
  385. // create initial metadata document
  386. HRESULT Initialize
  387. (
  388. IN VSS_ID idInstance,
  389. IN VSS_ID idWriter,
  390. IN LPCWSTR wszFriendlyName,
  391. IN VSS_USAGE_TYPE usage,
  392. IN VSS_SOURCE_TYPE source
  393. );
  394. // add files to include to metadata document
  395. STDMETHOD(AddIncludeFiles)
  396. (
  397. IN LPCWSTR wszPath,
  398. IN LPCWSTR wszFilespec,
  399. IN bool bRecursive,
  400. IN LPCWSTR wszAlternateLocation
  401. );
  402. // add files to exclude to metadata document
  403. STDMETHOD(AddExcludeFiles)
  404. (
  405. IN LPCWSTR wszPath,
  406. IN LPCWSTR wszFilespec,
  407. IN bool bRecursive
  408. );
  409. // add component to metadata document
  410. STDMETHOD(AddComponent)
  411. (
  412. IN VSS_COMPONENT_TYPE ct,
  413. IN LPCWSTR wszLogicalPath,
  414. IN LPCWSTR wszComponentName,
  415. IN LPCWSTR wszCaption,
  416. IN const BYTE *pbIcon,
  417. IN UINT cbIcon,
  418. IN bool bRestoreMetadata,
  419. IN bool bNotifyOnBackupComplete,
  420. IN bool bSelectable,
  421. IN bool bSelectableForRestore = true,
  422. IN DWORD dwComponentFlags = 0
  423. );
  424. // add physical database files to a database component
  425. STDMETHOD(AddDatabaseFiles)
  426. (
  427. IN LPCWSTR wszLogicalPath,
  428. IN LPCWSTR wszDatabaseName,
  429. IN LPCWSTR wszPath,
  430. IN LPCWSTR wszFilespec,
  431. IN DWORD dwBackupTypeMask = (VSS_FSBT_ALL_BACKUP_REQUIRED |
  432. VSS_FSBT_ALL_SNAPSHOT_REQUIRED)
  433. );
  434. // add log files to a database component
  435. STDMETHOD(AddDatabaseLogFiles)
  436. (
  437. IN LPCWSTR wszLogicalPath,
  438. IN LPCWSTR wszDatabaseName,
  439. IN LPCWSTR wszPath,
  440. IN LPCWSTR wszFilespec,
  441. IN DWORD dwBackupTypeMask = (VSS_FSBT_ALL_BACKUP_REQUIRED |
  442. VSS_FSBT_ALL_SNAPSHOT_REQUIRED)
  443. );
  444. // add files to a FILE_GROUP component
  445. STDMETHOD(AddFilesToFileGroup)
  446. (
  447. IN LPCWSTR wszLogicalPath,
  448. IN LPCWSTR wszGroupName,
  449. IN LPCWSTR wszPath,
  450. IN LPCWSTR wszFilespec,
  451. IN bool bRecursive,
  452. IN LPCWSTR wszAlternateLocation,
  453. IN DWORD dwBackupTypeMask = (VSS_FSBT_ALL_BACKUP_REQUIRED |
  454. VSS_FSBT_ALL_SNAPSHOT_REQUIRED)
  455. );
  456. // create a restore method
  457. STDMETHOD(SetRestoreMethod)
  458. (
  459. IN VSS_RESTOREMETHOD_ENUM method,
  460. IN LPCWSTR wszService,
  461. IN LPCWSTR wszUserProcedure,
  462. IN VSS_WRITERRESTORE_ENUM writerRestore,
  463. IN bool bRebootRequired
  464. );
  465. // add alternative location mappings to the restore method
  466. STDMETHOD(AddAlternateLocationMapping)
  467. (
  468. IN LPCWSTR wszSourcePath,
  469. IN LPCWSTR wszSourceFilespec,
  470. IN bool bRecursive,
  471. IN LPCWSTR wszDestination
  472. );
  473. // add a dependency to another writer's component
  474. STDMETHOD(AddComponentDependency)
  475. (
  476. IN LPCWSTR wszForLogicalPath,
  477. IN LPCWSTR wszForComponentName,
  478. IN VSS_ID onWriterId,
  479. IN LPCWSTR wszOnLogicalPath,
  480. IN LPCWSTR wszOnComponentName
  481. );
  482. // set teh backup schema
  483. STDMETHOD(SetBackupSchema)
  484. (
  485. IN DWORD dwSchemaMask
  486. );
  487. // obtain reference to actual XML document
  488. STDMETHOD(GetDocument)(IXMLDOMDocument **pDoc);
  489. // save document as an XML string
  490. STDMETHOD(SaveAsXML)(BSTR *pbstrXML);
  491. private:
  492. // obtain BACKUP_LOCATIONS element
  493. CXMLNode GetBackupLocationsNode();
  494. // add files associated with DATABASE or FILE_GROUP component
  495. HRESULT CreateComponentFiles
  496. (
  497. IN CVssFunctionTracer &ft,
  498. IN LPCWSTR wszElement,
  499. IN LPCWSTR wszLogicalPath,
  500. IN LPCWSTR wszComponentName,
  501. IN LPCWSTR wszElementFile,
  502. IN LPCWSTR wszPath,
  503. IN LPCWSTR wszFilespec,
  504. IN bool bRecursive,
  505. IN LPCWSTR wszAlternateLocation
  506. );
  507. };