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.

237 lines
6.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C M U T I L . C P P
  7. //
  8. // Contents: Connection manager.
  9. //
  10. // Notes:
  11. //
  12. // Author: omiller 1 Jun 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "cmutil.h"
  18. #include <objbase.h>
  19. #include <ncmisc.h>
  20. // Create an instance of CMUTIL so that we can be global
  21. //
  22. CCMUtil CCMUtil::s_instance;
  23. CCMUtil::CCMUtil()
  24. {
  25. InitializeCriticalSection( &m_CriticalSection );
  26. }
  27. CCMUtil::~CCMUtil()
  28. {
  29. DeleteCriticalSection( &m_CriticalSection );
  30. }
  31. //+---------------------------------------------------------------------------
  32. //
  33. // Function: GetIteratorFromGuid
  34. //
  35. // Purpose: Retrive the guid, name and status of a Hidden connectiod
  36. //
  37. // Connection Manager has two stages: Dialup and VPN.
  38. // For the Dialup it creates a hidden connectoid that the
  39. // folder (netshell) does not see. However netman caches
  40. // the name, guid and status of this connectedoid. Both
  41. // the parent and child connectoid have the same name.
  42. //
  43. // Arguments:
  44. // guid [in] GUID of the hidden connectiod to search for
  45. // cm [out] A pointer to the hidden entry
  46. //
  47. // Returns: S_OK -- Found the hidden connectoid
  48. //
  49. // Author: omiller 1 Jun 2000
  50. //
  51. // Notes:
  52. //
  53. CCMUtil::CMEntryTable::iterator CCMUtil::GetIteratorFromGuid(const GUID & guid)
  54. {
  55. CMEntryTable::iterator iter;
  56. // Search through the list of hidden connections
  57. //
  58. for (iter = m_Table.begin(); iter != m_Table.end(); iter++)
  59. {
  60. if( iter->m_guid == guid )
  61. {
  62. // Found the hidden connection that maps to this guid
  63. //
  64. return iter;
  65. }
  66. }
  67. return NULL;
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // Function: HrGetEntry
  72. //
  73. // Purpose: Retrive the guid, name and status of a Hidden connectiod
  74. //
  75. // Connection Manager has two stages: Dialup and VPN.
  76. // For the Dialup it creates a hidden connectoid that the
  77. // folder (netshell) does not see. However netman caches
  78. // the name, guid and status of this connectedoid. Both
  79. // the parent and child connectoid have the same name.
  80. //
  81. // Arguments:
  82. // guid [in] GUID of the hidden connectiod to search for
  83. // cm [out] A copy to the hidden entry
  84. //
  85. // Returns: TRUE -- Found the hidden connectoid
  86. //
  87. // Author: omiller 1 Jun 2000
  88. //
  89. // Notes:
  90. //
  91. HRESULT CCMUtil::HrGetEntry(const GUID & guid, CMEntry & cm)
  92. {
  93. CMEntryTable::iterator iter;
  94. HRESULT hr = S_FALSE;
  95. CExceptionSafeLock esCritSec(&m_CriticalSection);
  96. iter = GetIteratorFromGuid(guid);
  97. if( iter )
  98. {
  99. cm = *iter;
  100. hr = S_OK;
  101. }
  102. return hr;
  103. }
  104. //+---------------------------------------------------------------------------
  105. //
  106. // Function: HrGetEntry
  107. //
  108. // Purpose: Retrive the guid, name and status of a Hidden connectiod
  109. //
  110. // Connection Manager has two stages: Dialup and VPN.
  111. // For the Dialup it creates a hidden connectoid that the
  112. // folder (netshell) does not see. However netman caches
  113. // the name, guid and status of this connectedoid. Both
  114. // the parent and child connectoid have the same name.
  115. //
  116. // Arguments:
  117. // szEntryName [in] Name of the connection to look for
  118. // cm [out] A copy to the hidden entry
  119. //
  120. // Returns: S_OK -- Found the hidden connectoid
  121. //
  122. // Author: omiller 1 Jun 2000
  123. //
  124. // Notes:
  125. //
  126. HRESULT CCMUtil::HrGetEntry(const WCHAR * szEntryName, CMEntry & cm)
  127. {
  128. CMEntryTable::iterator iter;
  129. CExceptionSafeLock esCritSec(&m_CriticalSection);
  130. for (iter = m_Table.begin(); iter != m_Table.end(); iter++)
  131. {
  132. if( lstrcmp(iter->m_szEntryName,szEntryName) == 0 )
  133. {
  134. // Found the Hidden connectoid that maps to that name
  135. //
  136. cm = *iter;
  137. return S_OK;
  138. }
  139. }
  140. return S_FALSE;
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Function: SetEntry
  145. //
  146. // Purpose: Stores or Updates the guid, name and status of a Hidden connectiod
  147. //
  148. // Connection Manager has two stages: Dialup and VPN.
  149. // For the Dialup it creates a hidden connectoid that the
  150. // folder (netshell) does not see. However netman caches
  151. // the name, guid and status of this connectedoid. Both
  152. // the parent and child connectoid have the same name.
  153. //
  154. // Arguments:
  155. // guid [in] Guid of the Hidden connectiod
  156. // szEntryName [in] Name of the Hidden connectiod
  157. // ncs [in] Status of the hidden connectiod
  158. //
  159. // Returns: nothing
  160. //
  161. // Author: omiller 1 Jun 2000
  162. //
  163. // Notes:
  164. //
  165. void CCMUtil::SetEntry(const GUID & guid, const WCHAR * szEntryName, const NETCON_STATUS ncs)
  166. {
  167. CMEntryTable::iterator iter;
  168. CExceptionSafeLock esCritSec(&m_CriticalSection);
  169. iter = GetIteratorFromGuid(guid);
  170. if( iter )
  171. {
  172. iter->Set(guid,szEntryName,ncs);
  173. }
  174. else
  175. {
  176. m_Table.push_back( CMEntry(guid,szEntryName,ncs) );
  177. }
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Function: RemoveEntry
  182. //
  183. // Purpose: Removes a hidden connectiod from the list
  184. //
  185. // Connection Manager has two stages: Dialup and VPN.
  186. // For the Dialup it creates a hidden connectoid that the
  187. // folder (netshell) does not see. However netman caches
  188. // the name, guid and status of this connectedoid. Both
  189. // the parent and child connectoid have the same name.
  190. //
  191. // Arguments:
  192. // guid [in] Guid of the Hidden connectiod
  193. //
  194. // Returns: S_OK -- Found the hidden connectoid
  195. //
  196. // Author: omiller 1 Jun 2000
  197. //
  198. // Notes:
  199. //
  200. void CCMUtil::RemoveEntry(const GUID & guid)
  201. {
  202. /*
  203. CMEntryTable::iterator iter;
  204. EnterCriticalSection(&m_CriticalSection);
  205. iter = GetIteratorFromGuid(guid);
  206. if( iter )
  207. {
  208. m_Table.erase(iter);
  209. }
  210. LeaveCriticalSection(&m_CriticalSection);
  211. */
  212. }