Source code of Windows XP (NT5)
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.

263 lines
5.2 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ISAPIconfig.cpp
  5. Abstract:
  6. This file contains the implementation of the CISAPIconfig class,
  7. the support class for accessing and modifying the configuration of the
  8. ISAPI extension used by the Upload Library.
  9. Revision History:
  10. Davide Massarenti (Dmassare) 04/28/99
  11. created
  12. ******************************************************************************/
  13. #include "stdafx.h"
  14. CISAPIconfig::CISAPIconfig()
  15. {
  16. __ULT_FUNC_ENTRY( "CISAPIconfig::CISAPIconfig" );
  17. }
  18. /////////////////////////////////////////////////////////////////////////////
  19. HRESULT CISAPIconfig::ConnectToRegistry( /*[out]*/ MPC::RegKey& rkRoot ,
  20. /*[in] */ bool fWriteAccess )
  21. {
  22. __ULT_FUNC_ENTRY( "CISAPIconfig::ConnectToRegistry" );
  23. _ASSERT(m_szRoot.length() != 0);
  24. HRESULT hr;
  25. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.SetRoot( HKEY_LOCAL_MACHINE, fWriteAccess ? KEY_ALL_ACCESS : KEY_READ, m_szMachine.c_str() ));
  26. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.Attach( m_szRoot.c_str() ));
  27. hr = S_OK;
  28. __ULT_FUNC_CLEANUP;
  29. __ULT_FUNC_EXIT(hr);
  30. }
  31. /////////////////////////////////////////////////////////////////////////////
  32. HRESULT CISAPIconfig::SetRoot( /*[in]*/ LPCWSTR szRoot ,
  33. /*[in]*/ LPCWSTR szMachine )
  34. {
  35. __ULT_FUNC_ENTRY( "CISAPIconfig::SetRoot" );
  36. m_szRoot = szRoot;
  37. if(szMachine)
  38. {
  39. m_szMachine = szMachine;
  40. }
  41. __ULT_FUNC_EXIT(S_OK);
  42. }
  43. HRESULT CISAPIconfig::Install()
  44. {
  45. __ULT_FUNC_ENTRY( "CISAPIconfig::Install" );
  46. HRESULT hr;
  47. MPC::RegKey rkRoot;
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, ConnectToRegistry( rkRoot, true ));
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.Create());
  50. hr = S_OK;
  51. __ULT_FUNC_CLEANUP;
  52. __ULT_FUNC_EXIT(hr);
  53. }
  54. HRESULT CISAPIconfig::Uninstall()
  55. {
  56. __ULT_FUNC_ENTRY( "CISAPIconfig::Uninstall" );
  57. HRESULT hr;
  58. MPC::RegKey rkRoot;
  59. __MPC_EXIT_IF_METHOD_FAILS(hr, ConnectToRegistry( rkRoot, true ));
  60. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.Delete( true ));
  61. hr = S_OK;
  62. __ULT_FUNC_CLEANUP;
  63. __ULT_FUNC_EXIT(hr);
  64. }
  65. HRESULT CISAPIconfig::Load()
  66. {
  67. __ULT_FUNC_ENTRY( "CISAPIconfig::Load" );
  68. HRESULT hr;
  69. MPC::RegKey rkRoot;
  70. MPC::WStringList lstKeys;
  71. MPC::WStringIter itKey;
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, ConnectToRegistry( rkRoot, false ));
  73. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.EnumerateSubKeys( lstKeys ));
  74. m_lstInstances.clear();
  75. for(itKey=lstKeys.begin(); itKey != lstKeys.end(); itKey++)
  76. {
  77. CISAPIinstance isapiInstance( *itKey );
  78. __MPC_EXIT_IF_METHOD_FAILS(hr, isapiInstance.Load( rkRoot ));
  79. m_lstInstances.push_back( isapiInstance );
  80. }
  81. hr = S_OK;
  82. __ULT_FUNC_CLEANUP;
  83. __ULT_FUNC_EXIT(hr);
  84. }
  85. HRESULT CISAPIconfig::Save()
  86. {
  87. __ULT_FUNC_ENTRY( "CISAPIconfig::Save" );
  88. HRESULT hr;
  89. MPC::RegKey rkRoot;
  90. Iter itInstance;
  91. __MPC_EXIT_IF_METHOD_FAILS(hr, ConnectToRegistry( rkRoot, true ));
  92. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.DeleteSubKeys());
  93. for(itInstance=m_lstInstances.begin(); itInstance != m_lstInstances.end(); itInstance++)
  94. {
  95. __MPC_EXIT_IF_METHOD_FAILS(hr, (*itInstance).Save( rkRoot ));
  96. }
  97. hr = S_OK;
  98. __ULT_FUNC_CLEANUP;
  99. __ULT_FUNC_EXIT(hr);
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. HRESULT CISAPIconfig::GetInstances( /*[out]*/ Iter& itBegin ,
  103. /*[out]*/ Iter& itEnd )
  104. {
  105. __ULT_FUNC_ENTRY( "CISAPIconfig::GetInstances" );
  106. HRESULT hr;
  107. itBegin = m_lstInstances.begin();
  108. itEnd = m_lstInstances.end ();
  109. hr = S_OK;
  110. __ULT_FUNC_EXIT(hr);
  111. }
  112. HRESULT CISAPIconfig::NewInstance( /*[out]*/ Iter& itNew ,
  113. /*[in]*/ const MPC::wstring& szURL )
  114. {
  115. __ULT_FUNC_ENTRY( "CISAPIconfig::NewInstance" );
  116. HRESULT hr;
  117. bool fFound;
  118. //
  119. // First of all, check if the given URL already exists.
  120. //
  121. __MPC_EXIT_IF_METHOD_FAILS(hr, GetInstance( itNew, fFound, szURL ));
  122. if(fFound == false)
  123. {
  124. //
  125. // If not, create it.
  126. //
  127. itNew = m_lstInstances.insert( m_lstInstances.end(), CISAPIinstance( szURL ) );
  128. }
  129. hr = S_OK;
  130. __ULT_FUNC_CLEANUP;
  131. __ULT_FUNC_EXIT(hr);
  132. }
  133. HRESULT CISAPIconfig::GetInstance( /*[out]*/ Iter& itOld ,
  134. /*[out]*/ bool& fFound ,
  135. /*[in] */ const MPC::wstring& szURL )
  136. {
  137. __ULT_FUNC_ENTRY( "CISAPIconfig::GetInstance" );
  138. HRESULT hr;
  139. fFound = false;
  140. itOld = m_lstInstances.begin();
  141. while(itOld != m_lstInstances.end())
  142. {
  143. if(*itOld == szURL)
  144. {
  145. fFound = true;
  146. break;
  147. }
  148. ++itOld;
  149. }
  150. hr = S_OK;
  151. __ULT_FUNC_EXIT(hr);
  152. }
  153. HRESULT CISAPIconfig::DelInstance( /*[in]*/ Iter& itOld )
  154. {
  155. __ULT_FUNC_ENTRY( "CISAPIconfig::DelInstances" );
  156. HRESULT hr;
  157. m_lstInstances.erase( itOld );
  158. hr = S_OK;
  159. __ULT_FUNC_EXIT(hr);
  160. }