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.

279 lines
7.1 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. SAFReg.cpp
  5. Abstract:
  6. File for Implementation of CSAFReg
  7. Revision History:
  8. gschua created 3/22/2000
  9. ********************************************************************/
  10. #include "stdafx.h"
  11. static const WCHAR g_rgMutexName [] = L"PCH_SEARCHENGINECONFIG";
  12. static const WCHAR g_rgConfigFilename[] = HC_HCUPDATE_STORE_SE;
  13. /////////////////////////////////////////////////////////////////////
  14. CFG_BEGIN_FIELDS_MAP(SearchEngine::Config::Wrapper)
  15. CFG_ATTRIBUTE( L"SKU" , wstring, m_ths.m_strSKU ),
  16. CFG_ATTRIBUTE( L"LANGUAGE", long , m_ths.m_lLCID ),
  17. CFG_ATTRIBUTE( L"ID" , BSTR , m_bstrID ),
  18. CFG_ATTRIBUTE( L"OWNER" , BSTR , m_bstrOwner ),
  19. CFG_ATTRIBUTE( L"CLSID" , BSTR , m_bstrCLSID ),
  20. CFG_ATTRIBUTE( L"DATA" , BSTR , m_bstrData ),
  21. CFG_END_FIELDS_MAP()
  22. CFG_BEGIN_CHILD_MAP(SearchEngine::Config::Wrapper)
  23. CFG_END_CHILD_MAP()
  24. DEFINE_CFG_OBJECT(SearchEngine::Config::Wrapper,L"WRAPPER")
  25. DEFINE_CONFIG_METHODS__NOCHILD(SearchEngine::Config::Wrapper)
  26. /////////////////////////////////////////////////////////////////////
  27. CFG_BEGIN_FIELDS_MAP(SearchEngine::Config)
  28. CFG_ATTRIBUTE( L"VERSION", double, m_dVersion ),
  29. CFG_END_FIELDS_MAP()
  30. CFG_BEGIN_CHILD_MAP(SearchEngine::Config)
  31. CFG_CHILD(SearchEngine::Config::Wrapper)
  32. CFG_END_CHILD_MAP()
  33. DEFINE_CFG_OBJECT(SearchEngine::Config, L"SEARCHENGINES")
  34. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(SearchEngine::Config,tag,defSubType)
  35. if(tag == _cfg_table_tags[0])
  36. {
  37. defSubType = &(*(m_lstWrapper.insert( m_lstWrapper.end() )));
  38. return S_OK;
  39. }
  40. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(SearchEngine::Config,xdn)
  41. hr = MPC::Config::SaveList( m_lstWrapper, xdn );
  42. DEFINE_CONFIG_METHODS_END(SearchEngine::Config)
  43. /////////////////////////////////////////////////////////////////////
  44. /////////////////////////////////////////////////////////////////////
  45. SearchEngine::Config::Config() : MPC::NamedMutex( g_rgMutexName )
  46. {
  47. m_bLoaded = false; // double m_dVersion;
  48. m_dVersion = 1; // bool m_bLoaded;
  49. // WrapperList m_lstWrapper;
  50. MPC::NamedMutex::Acquire();
  51. }
  52. SearchEngine::Config::~Config()
  53. {
  54. MPC::NamedMutex::Release();
  55. }
  56. ////////////////////////////////////////////////////////////////////////////////
  57. HRESULT SearchEngine::Config::SyncConfiguration( /*[in]*/ bool fLoad )
  58. {
  59. __HCP_FUNC_ENTRY( "SearchEngine::Config::SyncConfiguration" );
  60. HRESULT hr;
  61. MPC::wstring strConfig( g_rgConfigFilename ); MPC::SubstituteEnvVariables( strConfig );
  62. if(fLoad)
  63. {
  64. if(m_bLoaded == false)
  65. {
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadFile( this, strConfig.c_str() ));
  67. m_bLoaded = true;
  68. }
  69. }
  70. else
  71. {
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::SaveFile( this, strConfig.c_str() ));
  73. m_bLoaded = true;
  74. }
  75. hr = S_OK;
  76. __MPC_FUNC_CLEANUP;
  77. __MPC_FUNC_EXIT(hr);
  78. }
  79. bool SearchEngine::Config::FindWrapper( /*[in]*/ const Taxonomy::HelpSet& ths, /*[in]*/ LPCWSTR szID, /*[out]*/ WrapperIter& it )
  80. {
  81. for(it = m_lstWrapper.begin(); it!= m_lstWrapper.end(); it++)
  82. {
  83. if(it->m_ths == ths && it->m_bstrID == szID) return true;
  84. }
  85. return false;
  86. }
  87. ////////////////////
  88. HRESULT SearchEngine::Config::RegisterWrapper( /*[in]*/ const Taxonomy::HelpSet& ths ,
  89. /*[in]*/ LPCWSTR szID ,
  90. /*[in]*/ LPCWSTR szOwner ,
  91. /*[in]*/ LPCWSTR szCLSID ,
  92. /*[in]*/ LPCWSTR szData )
  93. {
  94. __HCP_FUNC_ENTRY( "SearchEngine::Config::RegisterWrapper" );
  95. HRESULT hr;
  96. WrapperIter it;
  97. __MPC_PARAMCHECK_BEGIN(hr)
  98. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szID);
  99. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szOwner);
  100. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szCLSID);
  101. __MPC_PARAMCHECK_END();
  102. //
  103. // Make sure its loaded
  104. //
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/true ));
  106. //
  107. // Look for existing wrapper
  108. //
  109. if(FindWrapper( ths, szID, it ) == false)
  110. {
  111. //
  112. // Not found, so create a new Wrapper
  113. //
  114. it = m_lstWrapper.insert( m_lstWrapper.end() );
  115. }
  116. //
  117. // Stuff the values into the wrapper
  118. //
  119. it->m_ths = ths;
  120. it->m_bstrID = szID;
  121. it->m_bstrOwner = szOwner;
  122. it->m_bstrCLSID = szCLSID;
  123. it->m_bstrData = szData;
  124. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/false ));
  125. hr = S_OK;
  126. __HCP_FUNC_CLEANUP;
  127. __HCP_FUNC_EXIT(hr);
  128. }
  129. HRESULT SearchEngine::Config::UnRegisterWrapper( /*[in]*/ const Taxonomy::HelpSet& ths ,
  130. /*[in]*/ LPCWSTR szID ,
  131. /*[in]*/ LPCWSTR szOwner )
  132. {
  133. __HCP_FUNC_ENTRY( "SearchEngine::Config::UnRegisterWrapper" );
  134. HRESULT hr;
  135. WrapperIter it;
  136. __MPC_PARAMCHECK_BEGIN(hr)
  137. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szID);
  138. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szOwner);
  139. __MPC_PARAMCHECK_END();
  140. //
  141. // Make sure its loaded
  142. //
  143. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/true ));
  144. //
  145. // Look for existing wrapper
  146. //
  147. if(FindWrapper( ths, szID, it ))
  148. {
  149. //
  150. // Check if it is the correct owner
  151. //
  152. if(MPC::StrICmp( it->m_bstrOwner, szOwner ) != 0)
  153. {
  154. __MPC_SET_ERROR_AND_EXIT( hr, ERROR_ACCESS_DENIED );
  155. }
  156. //
  157. // If so, delete it
  158. //
  159. m_lstWrapper.erase( it );
  160. }
  161. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/false ));
  162. hr = S_OK;
  163. __MPC_FUNC_CLEANUP;
  164. __MPC_FUNC_EXIT(hr);
  165. }
  166. HRESULT SearchEngine::Config::ResetSKU( /*[in]*/ const Taxonomy::HelpSet& ths )
  167. {
  168. __HCP_FUNC_ENTRY( "SearchEngine::Config::ResetSKU" );
  169. HRESULT hr;
  170. WrapperIter it;
  171. //
  172. // Make sure its loaded
  173. //
  174. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/true ));
  175. //
  176. // Look for existing wrappers belonging to the same SKU.
  177. //
  178. for(it = m_lstWrapper.begin(); it!= m_lstWrapper.end(); )
  179. {
  180. WrapperIter it2 = it++;
  181. if(it2->m_ths == ths)
  182. {
  183. m_lstWrapper.erase( it2 );
  184. }
  185. }
  186. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/false ));
  187. hr = S_OK;
  188. __MPC_FUNC_CLEANUP;
  189. __MPC_FUNC_EXIT(hr);
  190. }
  191. ////////////////////////////////////////////////////////////////////////////////
  192. HRESULT SearchEngine::Config::GetWrappers( /*[out]*/ WrapperIter& itBegin, /*[out]*/ WrapperIter& itEnd )
  193. {
  194. __HCP_FUNC_ENTRY( "SearchEngine::Config::GetWrappers" );
  195. HRESULT hr;
  196. __MPC_EXIT_IF_METHOD_FAILS(hr, SyncConfiguration( /*fLoad*/true ));
  197. itBegin = m_lstWrapper.begin();
  198. itEnd = m_lstWrapper.end ();
  199. hr = S_OK;
  200. hr = S_OK;
  201. __HCP_FUNC_CLEANUP;
  202. __HCP_FUNC_EXIT(hr);
  203. }