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.

208 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. xmlupgrade.hxx
  5. Abstract:
  6. Classes that are used to upgrade the xml metabase and mbschema from
  7. one version to another
  8. Author:
  9. Christopher Achille (cachille)
  10. Project:
  11. Internet Services Setup
  12. Revision History:
  13. September 2001: Created
  14. --*/
  15. #define CFILEMODIFY_BLOCKSIZE 1024 * 4
  16. #define CXMLBASE_METABASEPATH _T("\\inetsrv\\metabase.xml")
  17. #define CXMLBASE_MBSCHEMAPATH _T("\\inetsrv\\mbschema.xml")
  18. // class: CFileModify
  19. //
  20. // This is a generic class, for reading through a file, while modifing its contents
  21. // based on what you find. It has an internal buffer, which keeps track of the
  22. // information you are currently editing
  23. //
  24. class CFileModify {
  25. private:
  26. HANDLE m_hReadFile; // Handle to read from file
  27. HANDLE m_hWriteFile; // Handle to write to file
  28. TCHAR m_szReadFileName[_MAX_PATH]; // Name of read from file
  29. TCHAR m_szWriteFileName[_MAX_PATH]; // Name of write to file
  30. BUFFER m_buffData; // Buffer for file io
  31. DWORD m_dwSizeofData; // Size of Data in Bytes
  32. LPBYTE m_szCurrentData; // Current location of data in block
  33. BOOL m_bUnicode;
  34. BOOL ResizeData(DWORD dwNewSize); // Resize the buffer size
  35. BOOL ResizeData(DWORD dwNewSize, LPBYTE *szString); // Resize the buffer size and move the string
  36. public:
  37. CFileModify();
  38. ~CFileModify();
  39. BOOL OpenFile(LPTSTR szFileName, BOOL bModify = FALSE);
  40. BOOL CloseFile();
  41. BOOL AbortFile();
  42. BOOL MoveCurrentPtr(LPBYTE szCurrent);
  43. LPBYTE GetCurrentLocation();
  44. LPBYTE GetBaseLocation();
  45. BOOL ReadNextChunk();
  46. BOOL MoveData(LPBYTE szCurrent, INT iBytes);
  47. BOOL IsUnicode();
  48. DWORD GetBufferSize();
  49. // Function for getting values, and updating pointer location
  50. DWORD GetNextChar(LPBYTE &szCurrent);
  51. DWORD GetNextWideChar(LPBYTE &szCurrent);
  52. DWORD GetPrevChar(LPBYTE &szCurrent);
  53. DWORD GetChar(LPBYTE szCurrent);
  54. WCHAR GetWideChar(LPBYTE szCurrent);
  55. void SetValue(LPBYTE szCurrent, DWORD dwValue, DWORD dwOffset = 0);
  56. void SetValue(PVOID szCurrent, DWORD dwValue, DWORD dwOffset = 0);
  57. void CopyString(LPBYTE szCurrent, LPTSTR szInsertString);
  58. LPBYTE MoveXChars(LPBYTE szCurrent, DWORD dwChars);
  59. LPBYTE MoveXChars(PVOID szCurrent, DWORD dwChars);
  60. };
  61. // class: CXMLEdit
  62. //
  63. // This is a class to help you modify an XML File. It allows you to move through
  64. // all of the items, with all of the properties in order to either remove or edit
  65. // and item. It also lets you add/remove a property or change the value
  66. //
  67. class CXMLEdit {
  68. private:
  69. CFileModify XMLFile;
  70. DWORD m_dwItemOffset;
  71. DWORD m_dwPropertyOffset;
  72. DWORD m_dwValueOffset;
  73. LPBYTE FindNextItem(BOOL bReturnName = TRUE); // Find the Next Item
  74. LPBYTE FindNextItem(LPBYTE szStartLocation, BOOL bReturnName = TRUE); // Find the Next Item
  75. LPBYTE FindNextProperty(LPBYTE &szValue); // Find the Next Property
  76. LPBYTE SkipString(LPBYTE szString, BOOL bSkipTrailingWhiteSpaces = TRUE);
  77. BOOL ReadNextChunk(); // Read the next chunk, and update pointers
  78. static BOOL IsWhiteSpace(DWORD ch); // Returns if the character is a white space equival
  79. static BOOL IsTerminator(DWORD ch); // Returns if the character is a xml string terminator
  80. BOOL IsEqual(LPCWSTR szWideString, LPCSTR szAnsiString); // Compare an unicode and ansi string
  81. BOOL IsEqual(LPBYTE szGenericString, LPCTSTR szTCHARString); // Compare a generic LPBYTE and LPTSTR
  82. BOOL IsEqual(LPCTSTR szString1, LPCTSTR szString2); // Compare two unicode strings or two ansi strings
  83. void LoadFullItem();
  84. BOOL MoveData(LPBYTE szCurrent, INT iBytes);
  85. BOOL ReplaceString(LPBYTE szLocation, LPTSTR szNewValue); // Replace any stirng at any location
  86. LPBYTE FindBeginingofItem(LPBYTE szInput); // Find the beginging of the last item
  87. public:
  88. CXMLEdit(); // Constructor
  89. ~CXMLEdit(); // Destructor
  90. // File open/closing
  91. BOOL Open(LPTSTR szName, BOOL bModify = FALSE); // Open the file for processing
  92. BOOL Close(); // Close the file for processing
  93. // Pointer movement
  94. BOOL MovetoNextItem(); // Move to the Next Item
  95. BOOL MovetoFirstProperty(); // Move to the First Property
  96. BOOL MovetoNextProperty(); // Move to the Next Property
  97. // file Modifications
  98. BOOL DeleteProperty(); // Delete the current Property
  99. BOOL DeleteItem(); // Delete the current Item
  100. BOOL DeleteValue(); // Delete the current Value
  101. BOOL ReplaceProperty(LPTSTR szNewProperty); // Replace the current property with this name
  102. BOOL ReplaceItem(LPTSTR szNewItem); // Replace the current item with this name
  103. BOOL ReplaceValue(LPTSTR szNewValue); // Replace the current value with this one
  104. // QueryValues
  105. LPBYTE GetCurrentItem(); // Get the Current Item
  106. LPBYTE GetCurrentProperty(); // Get the Current Property
  107. LPBYTE GetCurrentValue(); // Get the Current Property
  108. BOOL RetrieveCurrentValue( TSTR *pstrValue );
  109. void SetCurrentItem(LPBYTE szInput); // Set the location for the current Item
  110. void SetCurrentProperty(LPBYTE szInput);// Set the location for the current property
  111. void SetCurrentValue(LPBYTE szInput); // Set the location for the current value
  112. // Conditional (for ANSI 'compatable' strings)
  113. BOOL IsEqualItem(LPCTSTR szItemName); // Is the name of the item, and this item the same?
  114. BOOL IsEqualProperty(LPCTSTR szPropertyName); // Is the name of the property, and this property the same?
  115. BOOL IsEqualValue(LPCTSTR szValue); // Is the value equal to what we are sending in?
  116. // Others
  117. DWORD ExtractVersion(LPBYTE szVersion);
  118. };
  119. // class: CXML_Base
  120. //
  121. // This is the base class for the XML functions
  122. //
  123. class CXML_Base : public CBaseFunction {
  124. protected:
  125. BOOL GetMetabasePath(TSTR *pstrPath);
  126. BOOL GetSchemaPath(TSTR *pstrPath);
  127. BOOL IsFileWithinVersion(LPTSTR szFileName, LPTSTR szItemName, LPTSTR szPropName, DWORD dwMinVer, DWORD dwMaxVer);
  128. BOOL ParseFile(LPTSTR szFile, CItemList &ciList);
  129. };
  130. // class: CXML_VerifyValue
  131. //
  132. // This function will verify the version of either the
  133. // XML Metabase, or the XML Schema
  134. //
  135. class CXML_Metabase_VerifyVersion : public CXML_Base {
  136. private:
  137. virtual BOOL VerifyParameters(CItemList &ciParams);
  138. virtual BOOL DoInternalWork(CItemList &ciList);
  139. public:
  140. virtual LPTSTR GetMethodName();
  141. };
  142. // class: CXML_Metabase_Upgrade
  143. //
  144. // This function will upgrade the metabase
  145. //
  146. class CXML_Metabase_Upgrade : public CXML_Base {
  147. private:
  148. virtual BOOL DoInternalWork(CItemList &ciList);
  149. public:
  150. virtual LPTSTR GetMethodName();
  151. };
  152. // class: CXML_VerifyValue
  153. //
  154. // This function will verify the version of either the
  155. // XML Metabase, or the XML Schema
  156. //
  157. class CXML_MBSchema_VerifyVersion : public CXML_Base {
  158. private:
  159. virtual BOOL VerifyParameters(CItemList &ciParams);
  160. virtual BOOL DoInternalWork(CItemList &ciList);
  161. public:
  162. virtual LPTSTR GetMethodName();
  163. };
  164. // class: CXML_MBSchema_Upgrade
  165. //
  166. // This function will upgrade the metabase
  167. //
  168. class CXML_MBSchema_Upgrade : public CXML_Base {
  169. private:
  170. virtual BOOL DoInternalWork(CItemList &ciList);
  171. public:
  172. virtual LPTSTR GetMethodName();
  173. };