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.

391 lines
8.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2000
  5. //
  6. // File: H N A P I E N . C P P
  7. //
  8. // Contents: OEM API
  9. //
  10. // Notes:
  11. //
  12. // Author: billi 21 Nov 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. /*++
  18. CNetSharingManager::EnumEveryConnections
  19. Routine Description:
  20. Return an IEnumNetEveryConnection interface used to enumerate all of
  21. the contained INetConnections configured as a public adapter
  22. Arguments:
  23. none
  24. Return Value:
  25. none
  26. --*/
  27. STDMETHODIMP
  28. CNetSharingManager::get_EnumEveryConnection(
  29. INetSharingEveryConnectionCollection** ppColl)
  30. {
  31. HNET_OEM_API_ENTER
  32. IEnumNetSharingEveryConnection * pENEC = NULL;
  33. // idea: use existing code below to fill out pENPC,
  34. // then convert to collection
  35. HRESULT hr = S_OK;
  36. if ( NULL == ppColl )
  37. {
  38. hr = E_POINTER;
  39. }
  40. else if ( !IsSecureContext() )
  41. {
  42. *ppColl = NULL;
  43. hr = E_ACCESSDENIED;
  44. }
  45. else
  46. {
  47. *ppColl = NULL;
  48. INetConnectionManager* pManager = NULL;
  49. hr = CoCreateInstance( CLSID_ConnectionManager,
  50. NULL,
  51. CLSCTX_ALL,
  52. IID_PPV_ARG(INetConnectionManager, &pManager) );
  53. if ( SUCCEEDED(hr) )
  54. {
  55. IEnumNetConnection* pNetEnum = NULL;
  56. SetProxyBlanket(pManager);
  57. hr = pManager->EnumConnections(NCME_DEFAULT, &pNetEnum);
  58. if ( SUCCEEDED(hr) )
  59. {
  60. CComObject<CSharingManagerEnumEveryConnection>* pEnum;
  61. hr = CComObject<CSharingManagerEnumEveryConnection>::CreateInstance(&pEnum);
  62. if ( SUCCEEDED(hr) )
  63. {
  64. pEnum->AddRef();
  65. hr = pEnum->Initialize( pNetEnum, ICSSC_DEFAULT );
  66. if ( SUCCEEDED(hr) )
  67. {
  68. hr = pEnum->QueryInterface(
  69. IID_PPV_ARG(IEnumNetSharingEveryConnection, &pENEC)
  70. );
  71. }
  72. ReleaseObj(pEnum);
  73. }
  74. ReleaseObj(pNetEnum);
  75. }
  76. ReleaseObj(pManager);
  77. }
  78. }
  79. // create collection:
  80. if (pENEC) {
  81. if (hr == S_OK) {
  82. CComObject<CNetSharingEveryConnectionCollection>* pNECC = NULL;
  83. hr = CComObject<CNetSharingEveryConnectionCollection>::CreateInstance (&pNECC);
  84. if (pNECC) {
  85. pNECC->AddRef();
  86. pNECC->Initialize (pENEC);
  87. hr = pNECC->QueryInterface (__uuidof(INetSharingEveryConnectionCollection), (void**)ppColl);
  88. pNECC->Release();
  89. }
  90. }
  91. pENEC->Release();
  92. }
  93. return hr;
  94. HNET_OEM_API_LEAVE
  95. }
  96. /*++
  97. CNetSharingManager::EnumPublicConnections
  98. Routine Description:
  99. Return an IEnumNetPublicConnection interface used to enumerate all of
  100. the contained INetConnections configured as a public adapter
  101. Arguments:
  102. none
  103. Return Value:
  104. none
  105. --*/
  106. STDMETHODIMP
  107. CNetSharingManager::get_EnumPublicConnections(
  108. SHARINGCONNECTION_ENUM_FLAGS Flags,
  109. // IEnumNetPublicConnection** ppEnum
  110. INetSharingPublicConnectionCollection** ppColl)
  111. {
  112. HNET_OEM_API_ENTER
  113. IEnumNetSharingPublicConnection * pENPC = NULL;
  114. // idea: use existing code below to fill out pENPC,
  115. // then convert to collection
  116. HRESULT hr = S_OK;
  117. if ( NULL == ppColl )
  118. {
  119. hr = E_POINTER;
  120. }
  121. else if ( !IsSecureContext() )
  122. {
  123. hr = E_ACCESSDENIED;
  124. }
  125. else
  126. {
  127. IEnumHNetIcsPublicConnections* pHNetEnum;
  128. hr = m_pIcsSettings->EnumIcsPublicConnections( &pHNetEnum );
  129. if ( SUCCEEDED(hr) )
  130. {
  131. CComObject<CSharingManagerEnumPublicConnection>* pEnum;
  132. hr = CComObject<CSharingManagerEnumPublicConnection>::CreateInstance(&pEnum);
  133. if ( SUCCEEDED(hr) )
  134. {
  135. pEnum->AddRef();
  136. hr = pEnum->Initialize( pHNetEnum, Flags );
  137. if ( SUCCEEDED(hr) )
  138. {
  139. hr = pEnum->QueryInterface(
  140. IID_PPV_ARG(IEnumNetSharingPublicConnection, &pENPC)
  141. );
  142. }
  143. ReleaseObj(pEnum);
  144. }
  145. ReleaseObj(pHNetEnum);
  146. }
  147. }
  148. // create collection:
  149. if (pENPC) {
  150. if (hr == S_OK) {
  151. CComObject<CNetSharingPublicConnectionCollection>* pNPCC = NULL;
  152. hr = CComObject<CNetSharingPublicConnectionCollection>::CreateInstance (&pNPCC);
  153. if (pNPCC) {
  154. pNPCC->AddRef();
  155. pNPCC->Initialize (pENPC);
  156. hr = pNPCC->QueryInterface (__uuidof(INetSharingPublicConnectionCollection), (void**)ppColl);
  157. pNPCC->Release();
  158. }
  159. }
  160. pENPC->Release();
  161. }
  162. return hr;
  163. HNET_OEM_API_LEAVE
  164. }
  165. /*++
  166. CNetSharingManager::EnumPrivateConnections
  167. Routine Description:
  168. Return an IEnumNetPrivateConnection interface used to enumerate all of
  169. the contained INetConnections configured as a private adapter
  170. Arguments:
  171. none
  172. Return Value:
  173. none
  174. --*/
  175. STDMETHODIMP
  176. CNetSharingManager::get_EnumPrivateConnections(
  177. SHARINGCONNECTION_ENUM_FLAGS Flags,
  178. // IEnumNetPrivateConnection** ppEnum)
  179. INetSharingPrivateConnectionCollection** ppColl)
  180. {
  181. HNET_OEM_API_ENTER
  182. IEnumNetSharingPrivateConnection * pENPC = NULL;
  183. // idea: use existing code below to fill out pENPC,
  184. // then convert to collection
  185. HRESULT hr = S_OK;
  186. if ( NULL == ppColl )
  187. {
  188. hr = E_POINTER;
  189. }
  190. else if ( !IsSecureContext() )
  191. {
  192. hr = E_ACCESSDENIED;
  193. }
  194. else
  195. {
  196. IEnumHNetIcsPrivateConnections* pHNetEnum;
  197. hr = m_pIcsSettings->EnumIcsPrivateConnections( &pHNetEnum );
  198. if ( SUCCEEDED(hr) )
  199. {
  200. CComObject<CSharingManagerEnumPrivateConnection>* pEnum;
  201. hr = CComObject<CSharingManagerEnumPrivateConnection>::CreateInstance(&pEnum);
  202. if ( SUCCEEDED(hr) )
  203. {
  204. pEnum->AddRef();
  205. hr = pEnum->Initialize( pHNetEnum, Flags );
  206. if ( SUCCEEDED(hr) )
  207. {
  208. hr = pEnum->QueryInterface(
  209. IID_PPV_ARG(IEnumNetSharingPrivateConnection, &pENPC)
  210. );
  211. }
  212. ReleaseObj(pEnum);
  213. }
  214. ReleaseObj(pHNetEnum);
  215. }
  216. }
  217. // create collection:
  218. if (pENPC) {
  219. if (hr == S_OK) {
  220. CComObject<CNetSharingPrivateConnectionCollection>* pNPCC = NULL;
  221. hr = CComObject<CNetSharingPrivateConnectionCollection>::CreateInstance (&pNPCC);
  222. if (pNPCC) {
  223. pNPCC->AddRef();
  224. pNPCC->Initialize (pENPC);
  225. hr = pNPCC->QueryInterface (__uuidof(INetSharingPrivateConnectionCollection), (void**)ppColl);
  226. pNPCC->Release();
  227. }
  228. }
  229. pENPC->Release();
  230. }
  231. return hr;
  232. HNET_OEM_API_LEAVE
  233. }
  234. STDMETHODIMP
  235. CNetSharingConfiguration::get_EnumPortMappings(
  236. SHARINGCONNECTION_ENUM_FLAGS Flags,
  237. // IEnumSharingPortMapping** ppEnum)
  238. INetSharingPortMappingCollection** ppColl)
  239. {
  240. HNET_OEM_API_ENTER
  241. IEnumNetSharingPortMapping * pESPM = NULL;
  242. // idea: use existing code below to fill out pESPM,
  243. // then convert to collection
  244. HRESULT hr = S_OK;
  245. IHNetProtocolSettings *pProtocolSettings;
  246. if ( NULL == ppColl )
  247. {
  248. hr = E_POINTER;
  249. }
  250. else if ( !IsSecureContext() )
  251. {
  252. hr = E_ACCESSDENIED;
  253. }
  254. else if ( NULL == m_pHNetConnection )
  255. {
  256. hr = E_UNEXPECTED;
  257. }
  258. else
  259. {
  260. IEnumHNetPortMappingBindings *pHNetEnum;
  261. hr = m_pHNetConnection->EnumPortMappings( Flags & ICSSC_ENABLED, &pHNetEnum );
  262. if ( SUCCEEDED(hr) )
  263. {
  264. CComObject<CSharingManagerEnumPortMapping>* pEnum;
  265. hr = CComObject<CSharingManagerEnumPortMapping>::CreateInstance(&pEnum);
  266. if ( SUCCEEDED(hr) )
  267. {
  268. pEnum->AddRef();
  269. hr = pEnum->Initialize( pHNetEnum, Flags );
  270. if ( SUCCEEDED(hr) )
  271. {
  272. hr = pEnum->QueryInterface(
  273. IID_PPV_ARG(IEnumNetSharingPortMapping, &pESPM)
  274. );
  275. }
  276. ReleaseObj(pEnum);
  277. }
  278. ReleaseObj(pHNetEnum);
  279. }
  280. }
  281. // create collection:
  282. if (pESPM) {
  283. if (hr == S_OK) {
  284. CComObject<CNetSharingPortMappingCollection>* pNPCC = NULL;
  285. hr = CComObject<CNetSharingPortMappingCollection>::CreateInstance (&pNPCC);
  286. if (pNPCC) {
  287. pNPCC->AddRef();
  288. pNPCC->Initialize (pESPM);
  289. hr = pNPCC->QueryInterface (__uuidof(INetSharingPortMappingCollection), (void**)ppColl);
  290. pNPCC->Release();
  291. }
  292. }
  293. pESPM->Release();
  294. }
  295. return hr;
  296. HNET_OEM_API_LEAVE
  297. }