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.

209 lines
5.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: schemacache.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #include "schemacache.h"
  12. //+--------------------------------------------------------------------------
  13. //
  14. // Member: CADSIEditSchemaCache::Lookup
  15. //
  16. // Synopsis: Gets the cache item identified by the given class name
  17. //
  18. // Arguments: [pszClass - IN] : the name of the class to retrieve the
  19. // cache information for
  20. // [refpItem - OUT] : reference to a pointer that will receive
  21. // the cached item
  22. //
  23. // Returns: bool : true if the cache contained the item
  24. //
  25. // History: 27-Nov-2000 JeffJon Created
  26. //
  27. //---------------------------------------------------------------------------
  28. CADSIEditClassCacheItemBase* CADSIEditSchemaCache::FindClassCacheItem(CCredentialObject* pCredObject,
  29. PCWSTR pszClass,
  30. PCWSTR pszSchemaPath)
  31. {
  32. _Lock();
  33. CADSIEditClassCacheItemBase* pCacheSchemaItem = 0;
  34. do // false while
  35. {
  36. BOOL bFound = m_Map.Lookup(pszClass, pCacheSchemaItem);
  37. if (!bFound)
  38. {
  39. TRACE(_T("Cache miss: %s\n"), pszClass);
  40. HRESULT hr = S_OK;
  41. CComPtr<IADsClass> spClass;
  42. hr = OpenObjectWithCredentials(pCredObject,
  43. pszSchemaPath,
  44. IID_IADsClass,
  45. (void**)&spClass);
  46. if ( FAILED(hr) )
  47. {
  48. TRACE(_T("Bind failed in IsContainer() because hr=0x%x\n"), hr);
  49. break;
  50. }
  51. short bContainer = 0;
  52. hr = spClass->get_Container( &bContainer );
  53. if (FAILED(hr))
  54. {
  55. TRACE(_T("IADsClass::get_Container() failed. hr=0x%x\n"), hr);
  56. }
  57. pCacheSchemaItem = new CADSIEditClassCacheItemBase(pszClass, bContainer ? true : false);
  58. if (pCacheSchemaItem)
  59. {
  60. //
  61. // set in the cache
  62. //
  63. m_Map.SetAt(pszClass, pCacheSchemaItem);
  64. }
  65. else
  66. {
  67. ASSERT(pCacheSchemaItem);
  68. break;
  69. }
  70. }
  71. } while (false);
  72. _Unlock();
  73. return pCacheSchemaItem;
  74. }
  75. //+--------------------------------------------------------------------------
  76. //
  77. // Member: CADSIEditSchemaCache::Lookup
  78. //
  79. // Synopsis: Gets the cache item identified by the given class name
  80. //
  81. // Arguments: [pszClass - IN] : the name of the class to retrieve the
  82. // cache information for
  83. // [refpItem - OUT] : reference to a pointer that will receive
  84. // the cached item
  85. //
  86. // Returns: bool : true if the cache contained the item
  87. //
  88. // History: 27-Nov-2000 JeffJon Created
  89. //
  90. //---------------------------------------------------------------------------
  91. BOOL CADSIEditSchemaCache::Lookup(PCWSTR pszClass, CADSIEditClassCacheItemBase*& refpItem)
  92. {
  93. _Lock();
  94. BOOL b = m_Map.Lookup(pszClass, refpItem);
  95. _Unlock();
  96. return b;
  97. }
  98. //+--------------------------------------------------------------------------
  99. //
  100. // Member: CADSIEditSchemaCache::Initialize
  101. //
  102. // Synopsis: Initializes the critical section and cleans out the cache
  103. //
  104. // Arguments:
  105. //
  106. // Returns: HRESULT : S_OK if initialization succeeded
  107. //
  108. // History: 27-Nov-2000 JeffJon Created
  109. //
  110. //---------------------------------------------------------------------------
  111. HRESULT CADSIEditSchemaCache::Initialize()
  112. {
  113. HRESULT hr = S_OK;
  114. ExceptionPropagatingInitializeCriticalSection(&m_cs);
  115. _Lock();
  116. _Cleanup();
  117. _Unlock();
  118. return hr;
  119. }
  120. //+--------------------------------------------------------------------------
  121. //
  122. // Member: CADSIEditSchemaCache::Destroy
  123. //
  124. // Synopsis: Cleans out the cache and deletes the critical section
  125. //
  126. // Arguments:
  127. //
  128. // Returns: HRESULT : S_OK if everything was deleted successfully
  129. //
  130. // History: 27-Nov-2000 JeffJon Created
  131. //
  132. //---------------------------------------------------------------------------
  133. HRESULT CADSIEditSchemaCache::Destroy()
  134. {
  135. HRESULT hr = S_OK;
  136. _Lock();
  137. _Cleanup();
  138. _Unlock();
  139. //
  140. // REVIEW_JEFFJON : need to add exception handling here
  141. //
  142. ::DeleteCriticalSection(&m_cs);
  143. return hr;
  144. }
  145. //+--------------------------------------------------------------------------
  146. //
  147. // Member: CADSIEditSchemaCache::Clear
  148. //
  149. // Synopsis: Cleans out the cache
  150. //
  151. // Arguments:
  152. //
  153. // Returns:
  154. //
  155. // History: 27-Nov-2000 JeffJon Created
  156. //
  157. //---------------------------------------------------------------------------
  158. void CADSIEditSchemaCache::Clear()
  159. {
  160. _Lock();
  161. _Cleanup();
  162. _Unlock();
  163. }
  164. //+--------------------------------------------------------------------------
  165. //
  166. // Member: CADSIEditSchemaCache::_Cleanup
  167. //
  168. // Synopsis: Removes all entries from the map and deletes them
  169. //
  170. // Arguments:
  171. //
  172. // Returns:
  173. //
  174. // History: 27-Nov-2000 JeffJon Created
  175. //
  176. //---------------------------------------------------------------------------
  177. void CADSIEditSchemaCache::_Cleanup()
  178. {
  179. CString Key;
  180. CADSIEditClassCacheItemBase* pCacheItem = NULL;
  181. POSITION pos = m_Map.GetStartPosition();
  182. while (!m_Map.IsEmpty())
  183. {
  184. m_Map.GetNextAssoc (pos, Key, pCacheItem);
  185. m_Map.RemoveKey (Key);
  186. delete pCacheItem;
  187. }
  188. }