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.

262 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: E N U M S A. C P P
  7. //
  8. // Contents: Implementation of Shared Access connection enumerator object
  9. //
  10. // Notes:
  11. //
  12. // Author: kenwic 8 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "enumsa.h"
  18. #include "saconob.h"
  19. LONG g_CountSharedAccessConnectionEnumerators;
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CSharedAccessConnectionManagerEnumConnection::~CSharedAccessConnectionManagerEnumConnection
  23. //
  24. // Purpose: Called when the enumeration object is released for the last
  25. // time.
  26. //
  27. // Arguments:
  28. // (none)
  29. //
  30. // Returns: Nothing
  31. //
  32. // Author: kenwic 8 Aug 2000
  33. //
  34. // Notes:
  35. //
  36. CSharedAccessConnectionManagerEnumConnection::~CSharedAccessConnectionManagerEnumConnection()
  37. {
  38. InterlockedDecrement(&g_CountSharedAccessConnectionEnumerators);
  39. }
  40. //+---------------------------------------------------------------------------
  41. // IEnumNetConnection
  42. //
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Member: CSharedAccessConnectionManagerEnumConnection::Next
  46. //
  47. // Purpose: Retrieves the next celt SharedAccess connection objects
  48. //
  49. // Arguments:
  50. // celt [in] Number to retrieve
  51. // rgelt [out] Array of INetConnection objects retrieved
  52. // pceltFetched [out] Returns Number in array
  53. //
  54. // Returns: S_OK if succeeded, OLE or Win32 error otherwise
  55. //
  56. // Author: kenwic 8 Aug 2000
  57. //
  58. // Notes:
  59. //
  60. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Next(ULONG celt,
  61. INetConnection **rgelt,
  62. ULONG *pceltFetched)
  63. {
  64. HRESULT hr = S_FALSE;
  65. // Validate parameters.
  66. //
  67. if (!rgelt || (!pceltFetched && (1 != celt)))
  68. {
  69. hr = E_POINTER;
  70. goto done;
  71. }
  72. // Initialize output parameters.
  73. //
  74. if (pceltFetched)
  75. {
  76. *pceltFetched = 0;
  77. }
  78. ZeroMemory(rgelt, sizeof (*rgelt) * celt);
  79. if(FALSE == m_bEnumerated)
  80. {
  81. m_bEnumerated = TRUE;
  82. INetConnectionUiUtilities* pNetConnUiUtil; // check group policy
  83. hr = CoCreateInstance(CLSID_NetConnectionUiUtilities, NULL, CLSCTX_INPROC, IID_INetConnectionUiUtilities, reinterpret_cast<void **>(&pNetConnUiUtil));
  84. if (SUCCEEDED(hr))
  85. {
  86. if (pNetConnUiUtil->UserHasPermission(NCPERM_ICSClientApp))
  87. {
  88. CComObject<CSharedAccessConnection>* pConnection;
  89. hr = CComObject<CSharedAccessConnection>::CreateInstance(&pConnection);
  90. if(SUCCEEDED(hr))
  91. {
  92. pConnection->AddRef();
  93. hr = pConnection->QueryInterface(IID_INetConnection, reinterpret_cast<void **>(rgelt));
  94. if(SUCCEEDED(hr))
  95. {
  96. if(NULL != pceltFetched)
  97. {
  98. *pceltFetched = 1;
  99. }
  100. }
  101. pConnection->Release();
  102. }
  103. else
  104. {
  105. hr = S_FALSE;
  106. }
  107. }
  108. else
  109. {
  110. hr = S_FALSE;
  111. }
  112. pNetConnUiUtil->Release();
  113. }
  114. if(SUCCEEDED(hr))
  115. {
  116. if(1 != celt)
  117. {
  118. hr = S_FALSE;
  119. }
  120. }
  121. }
  122. done:
  123. Assert (FImplies (S_OK == hr, (*pceltFetched == celt)));
  124. TraceError("CSharedAccessConnectionManagerEnumConnection::Next",
  125. (hr == S_FALSE || hr == HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED)) ? S_OK : hr);
  126. return hr;
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Member: CSharedAccessConnectionManagerEnumConnection::Skip
  131. //
  132. // Purpose: Skips over celt number of connections
  133. //
  134. // Arguments:
  135. // celt [in] Number of connections to skip
  136. //
  137. // Returns: S_OK if successful, otherwise Win32 error
  138. //
  139. // Author: kenwic 8 Aug 2000
  140. //
  141. // Notes:
  142. //
  143. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Skip(ULONG celt)
  144. {
  145. HRESULT hr = S_OK;
  146. if(0 != celt)
  147. {
  148. m_bEnumerated = TRUE;
  149. }
  150. TraceError("CSharedAccessConnectionManagerEnumConnection::Skip",
  151. (hr == S_FALSE) ? S_OK : hr);
  152. return hr;
  153. }
  154. //+---------------------------------------------------------------------------
  155. //
  156. // Member: CSharedAccessConnectionManagerEnumConnection::Reset
  157. //
  158. // Purpose: Resets the enumerator to the beginning
  159. //
  160. // Arguments:
  161. // (none)
  162. //
  163. // Returns: S_OK
  164. //
  165. // Author: kenwic 8 Aug 2000
  166. //
  167. // Notes:
  168. //
  169. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Reset()
  170. {
  171. HRESULT hr = S_OK;
  172. m_bEnumerated = FALSE;
  173. TraceError("CSharedAccessConnectionManagerEnumConnection::Reset", hr);
  174. return hr;
  175. }
  176. //+---------------------------------------------------------------------------
  177. //
  178. // Member: CSharedAccessConnectionManagerEnumConnection::Clone
  179. //
  180. // Purpose: Creates a new enumeration object pointing at the same location
  181. // as this object
  182. //
  183. // Arguments:
  184. // ppenum [out] New enumeration object
  185. //
  186. // Returns: S_OK if successful, otherwise OLE or Win32 error
  187. //
  188. // Author: kenwic 8 Aug 2000
  189. //
  190. // Notes:
  191. //
  192. STDMETHODIMP CSharedAccessConnectionManagerEnumConnection::Clone(IEnumNetConnection **ppenum)
  193. {
  194. HRESULT hr = E_OUTOFMEMORY;
  195. // Validate parameters.
  196. //
  197. if (!ppenum)
  198. {
  199. hr = E_POINTER;
  200. }
  201. else
  202. {
  203. CSharedAccessConnectionManagerEnumConnection * pObj;
  204. // Initialize output parameter.
  205. //
  206. *ppenum = NULL;
  207. pObj = new CComObject <CSharedAccessConnectionManagerEnumConnection>;
  208. if (pObj)
  209. {
  210. hr = S_OK;
  211. CExceptionSafeComObjectLock EsLock (this);
  212. // Copy our internal state.
  213. //
  214. pObj->m_bEnumerated = m_bEnumerated;
  215. // Return the object with a ref count of 1 on this
  216. // interface.
  217. pObj->m_dwRef = 1;
  218. *ppenum = pObj;
  219. }
  220. }
  221. TraceError ("CSharedAccessConnectionManagerEnumConnection::Clone", hr);
  222. return hr;
  223. }
  224. HRESULT CSharedAccessConnectionManagerEnumConnection::FinalRelease(void)
  225. {
  226. HRESULT hr = S_OK;
  227. return hr;
  228. }