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.

240 lines
8.9 KiB

  1. /*******************************************************************************/
  2. /* */
  3. /* Copyright - Microsoft Corporation. All rights reserved. */
  4. /* */
  5. /*******************************************************************************/
  6. #include <persistcfg.h>
  7. class CDbVerRead : public CPersistentConfig
  8. {
  9. public:
  10. BOOL ReadDbVer(DWORD &dwVal)
  11. {
  12. return GetPersistentCfgValue(PERSIST_CFGVAL_CORE_FSREP_VERSION, dwVal);
  13. }
  14. };
  15. class CUniqueStringPair
  16. {
  17. private:
  18. CFlexArray m_array;
  19. class CStringPair
  20. {
  21. public:
  22. wchar_t *m_wsz1;
  23. wchar_t *m_wsz2;
  24. CStringPair(const wchar_t *wsz1, const wchar_t *wsz2)
  25. {
  26. m_wsz1 = new wchar_t [wcslen(wsz1)+1];
  27. m_wsz2 = new wchar_t [wcslen(wsz2)+1];
  28. if (m_wsz1 && m_wsz2)
  29. {
  30. StringCchCopyW(m_wsz1, wcslen(wsz1)+1, wsz1);
  31. StringCchCopyW(m_wsz2, wcslen(wsz2)+1, wsz2);
  32. }
  33. else
  34. {
  35. delete [] m_wsz1;
  36. delete [] m_wsz2;
  37. m_wsz1 = NULL;
  38. m_wsz2 = NULL;
  39. throw CX_MemoryException();
  40. }
  41. }
  42. ~CStringPair()
  43. {
  44. delete [] m_wsz1;
  45. delete [] m_wsz2;
  46. }
  47. };
  48. public:
  49. CUniqueStringPair() {}
  50. ~CUniqueStringPair()
  51. {
  52. for (unsigned int i = 0; i != m_array.Size(); i++)
  53. {
  54. CStringPair *pEntry = (CStringPair*)m_array[i];
  55. delete pEntry;
  56. m_array[i] = NULL;
  57. }
  58. m_array.Empty();
  59. }
  60. HRESULT AddStrings(const wchar_t *wszKey, const wchar_t *wsz)
  61. {
  62. wchar_t *wszExisting = NULL;
  63. HRESULT hRes = FindStrings(wszKey, &wszExisting);
  64. if (hRes == WBEM_E_NOT_FOUND)
  65. {
  66. CStringPair *pEntry = new CStringPair(wszKey, wsz);
  67. if (pEntry)
  68. {
  69. if (m_array.Add(pEntry) != 0)
  70. hRes = WBEM_E_OUT_OF_MEMORY;
  71. else
  72. hRes = WBEM_NO_ERROR;
  73. }
  74. else
  75. {
  76. hRes = WBEM_E_OUT_OF_MEMORY;
  77. }
  78. }
  79. return hRes;
  80. }
  81. HRESULT FindStrings(const wchar_t *wszKey, wchar_t **wsz)
  82. {
  83. HRESULT hRes = WBEM_E_NOT_FOUND;
  84. for (unsigned int i = 0; i != m_array.Size(); i++)
  85. {
  86. CStringPair *pEntry = (CStringPair*) m_array[i];
  87. if (wcscmp(wszKey, pEntry->m_wsz1) == 0)
  88. {
  89. *wsz = pEntry->m_wsz2;
  90. hRes = WBEM_NO_ERROR;
  91. break;
  92. }
  93. }
  94. return hRes;
  95. }
  96. HRESULT RemoveString(const wchar_t *wszKey)
  97. {
  98. HRESULT hRes = WBEM_E_NOT_FOUND;
  99. for (unsigned int i = 0; i != m_array.Size(); i++)
  100. {
  101. CStringPair *pEntry = (CStringPair*) m_array[i];
  102. if (wcscmp(wszKey, pEntry->m_wsz1) == 0)
  103. {
  104. delete pEntry;
  105. m_array.RemoveAt(i);
  106. hRes = WBEM_NO_ERROR;
  107. break;
  108. }
  109. }
  110. return hRes;
  111. }
  112. CStringPair* operator [] (int nSubscript)
  113. {
  114. if (nSubscript >= Size())
  115. return (CStringPair*)NULL;
  116. else
  117. return (CStringPair*)m_array[nSubscript];
  118. }
  119. size_t Size() { return m_array.Size(); }
  120. };
  121. class CLocalizationUpgrade
  122. {
  123. public:
  124. CLocalizationUpgrade(CLifeControl* pControl, CRepository * pRepository);
  125. ~CLocalizationUpgrade();
  126. HRESULT DoUpgrade();
  127. private:
  128. CRepository * m_pRepository;
  129. CLifeControl* m_pControl;
  130. CUniqueStringPair m_keyHash; //Keyed on: OLD HASH
  131. CUniqueStringPair m_pathHash; //Keyed on: OLD PATH HASH
  132. CUniqueStringPair m_namespaces; //Keyed on: Namespace Path
  133. wchar_t m_namespaceClassHash[MAX_HASH_LEN+1];
  134. wchar_t m_emptyClassHash[MAX_HASH_LEN+1];
  135. wchar_t m_systemNamespaceHash[MAX_HASH_LEN+1];
  136. int m_pass;
  137. HRESULT ProcessSystemClassesRecursively(CNamespaceHandle *pNs,
  138. const wchar_t *namespaceHash,
  139. const wchar_t *parentClassHash);
  140. HRESULT EnumerateChildNamespaces(const wchar_t *wsRootNamespace);
  141. HRESULT ProcessClassesRecursively(CNamespaceHandle *pNs,const wchar_t *namespaceHash, const wchar_t *classHash);
  142. HRESULT ProcessClass(CNamespaceHandle *pNs,
  143. const wchar_t *namespaceHash,
  144. const wchar_t *parentClassHash,
  145. const wchar_t *childClassHash);
  146. HRESULT EnumerateInstances(CNamespaceHandle *pNs, const wchar_t *wszNewNamespaceHash);
  147. HRESULT ProcessNamespaceCollisions();
  148. HRESULT DeleteNamespaceRecursive(const wchar_t *wszFullNamespacePath);
  149. HRESULT DeleteNamespace(const wchar_t *wszNamespaceName, const wchar_t *wszNamespaceHash);
  150. HRESULT DeleteClass(CNamespaceHandle *pNs, CFileName &wszClassDefinitionPath);
  151. HRESULT DeleteChildClasses(CNamespaceHandle *pNs, const wchar_t *wszParentClassDefinition);
  152. HRESULT DeleteInstances(CNamespaceHandle *pNs, const wchar_t *wszClassDefinition, CFileName &wszKeyRootClass);
  153. HRESULT DeleteInstance(CNamespaceHandle *pNs, const wchar_t *wszClassInstanceLink, CFileName &wszKeyRoot);
  154. HRESULT DeleteInstanceReferences(CFileName &wszInstLink);
  155. HRESULT DeleteParentChildLink(wchar_t *wszClassDefinition);
  156. HRESULT DeleteClassRelationships(CFileName &wszClassDefinitionPath, const wchar_t wszParentClassHash[MAX_HASH_LEN+1]);
  157. HRESULT RetrieveKeyRootClass(CFileName &wszClassDefinitionPath, CFileName &wszKeyRootClass);
  158. HRESULT RetrieveParentClassHash(CFileName &wszClassDefinitionPath,
  159. wchar_t wszParentClassHash[MAX_HASH_LEN+1]);
  160. HRESULT DeleteInstanceAsNamespace(CNamespaceHandle *pNs, const wchar_t *wszClassInstanceLink);
  161. HRESULT ProcessHash(const wchar_t *wszName, bool *bDifferent);
  162. HRESULT ProcessFullPath(CFileName &wszName, const wchar_t *wszNewNamespaceHash);
  163. HRESULT FixupBTree();
  164. HRESULT FixupNamespace(const wchar_t *wszNamespace);
  165. HRESULT FixupIndex(CFileName &oldIndexEntry, CFileName &newIndexEntry, bool &bChanged);
  166. HRESULT FixupIndexConflict(CFileName &wszOldIndex);
  167. HRESULT FixupIndexReferenceBlob(CFileName &wszReferenceIndex);
  168. HRESULT FixupInstanceBlob(CFileName &wszInstanceIndex);
  169. HRESULT WriteIndex(CFileName &wszOldIndex, const wchar_t *wszNewIndex);
  170. HRESULT WriteClassIndex(CNamespaceHandle *pNs, CFileName &wszOldIndex, const wchar_t *wszNewIndex, bool *bClassDeleted);
  171. HRESULT IndexExists(const wchar_t *wszIndex);
  172. bool IsClassDefinitionPath(const wchar_t *wszPath);
  173. bool IsKeyRootInstancePath(const wchar_t *wszPath);
  174. bool IsInstanceReference(const wchar_t *wszPath);
  175. HRESULT OldHash(const wchar_t *wszName, wchar_t *wszHash);
  176. HRESULT NewHash(const wchar_t *wszName, wchar_t *wszHash);
  177. HRESULT GetNewHash(const wchar_t *wszOldHash, wchar_t **pNewHash);
  178. HRESULT GetNewPath(const wchar_t *wszOldHash, wchar_t **pNewHash);
  179. void OldStringToUpper(wchar_t* pwcTo, const wchar_t* pwcFrom)
  180. {
  181. while(*pwcFrom)
  182. {
  183. if(*pwcFrom >= 'a' && *pwcFrom <= 'z')
  184. *pwcTo = *pwcFrom + ('A'-'a');
  185. else
  186. *pwcTo = *pwcFrom;
  187. pwcTo++;
  188. pwcFrom++;
  189. }
  190. *pwcTo = 0;
  191. }
  192. void NewStringToUpper(wchar_t* pwcTo, const wchar_t* pwcFrom)
  193. {
  194. while(*pwcFrom)
  195. {
  196. if(*pwcFrom >= 'a' && *pwcFrom <= 'z')
  197. *pwcTo = *pwcFrom + ('A'-'a');
  198. else if(*pwcFrom < 128)
  199. *pwcTo = *pwcFrom;
  200. else
  201. if (LCMapStringW(LOCALE_INVARIANT, LCMAP_UPPERCASE, pwcFrom, 1, pwcTo, 1) == 0)
  202. {
  203. *pwcTo = *pwcFrom;
  204. DEBUGTRACE((LOG_REPDRV, "Failed to convert %C to upper case\n", *pwcFrom));
  205. }
  206. pwcTo++;
  207. pwcFrom++;
  208. }
  209. *pwcTo = 0;
  210. }
  211. };