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.

446 lines
14 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "CWANCommonInterfaceConfigService.h"
  4. #include "StatisticsProviders.h"
  5. CWANCommonInterfaceConfigService::CWANCommonInterfaceConfigService()
  6. {
  7. m_pEventSink = NULL;
  8. m_pWANIPConnectionService = NULL;
  9. m_pWANPPPConnectionService = NULL;
  10. m_pWANPOTSLinkConfigService = NULL;
  11. m_pICSSupport = NULL;
  12. m_bFirewalled = FALSE;
  13. m_pStatisticsProvider = NULL;
  14. };
  15. HRESULT CWANCommonInterfaceConfigService::FinalConstruct()
  16. {
  17. HRESULT hr = S_OK;
  18. IHNetConnection* pPublicConnection;
  19. IHNetConnection* pPrivateConnection;
  20. hr = GetConnections(&pPublicConnection, &pPrivateConnection);
  21. if(SUCCEEDED(hr))
  22. {
  23. GUID* pGuid;
  24. hr = pPublicConnection->GetGuid(&pGuid);
  25. if(SUCCEEDED(hr))
  26. {
  27. INetConnection* pNetConnection;
  28. hr = pPublicConnection->GetINetConnection(&pNetConnection);
  29. if(SUCCEEDED(hr))
  30. {
  31. NETCON_PROPERTIES* pProperties;
  32. hr = pNetConnection->GetProperties(&pProperties);
  33. if(SUCCEEDED(hr))
  34. {
  35. // cache the firewall state, the beacon will be signaled (torn down and rebuilt) when the firewall status changes
  36. m_bFirewalled = (NCCF_FIREWALLED & pProperties->dwCharacter) == NCCF_FIREWALLED;
  37. m_MediaType = pProperties->MediaType;
  38. if(NCM_LAN == m_MediaType)
  39. {
  40. CComObject<CLANStatisticsProvider>* pLANStatisticsProvider;
  41. hr = CComObject<CLANStatisticsProvider>::CreateInstance(&pLANStatisticsProvider);
  42. if(SUCCEEDED(hr))
  43. {
  44. pLANStatisticsProvider->AddRef();
  45. hr = pLANStatisticsProvider->Initialize(pGuid);
  46. // pass the reference
  47. m_pStatisticsProvider = static_cast<IStatisticsProvider*>(pLANStatisticsProvider);
  48. }
  49. }
  50. else
  51. {
  52. CComObject<CRASStatisticsProvider>* pRASStatisticsProvider;
  53. hr = CComObject<CRASStatisticsProvider>::CreateInstance(&pRASStatisticsProvider);
  54. if(SUCCEEDED(hr))
  55. {
  56. pRASStatisticsProvider->AddRef();
  57. hr = pRASStatisticsProvider->Initialize(pNetConnection);
  58. // pass the reference
  59. m_pStatisticsProvider = static_cast<IStatisticsProvider*>(pRASStatisticsProvider);
  60. }
  61. }
  62. if(SUCCEEDED(hr))
  63. {
  64. if(NCM_LAN == m_MediaType)
  65. {
  66. hr = CComObject<CWANIPConnectionService>::CreateInstance(&m_pWANIPConnectionService);
  67. if(SUCCEEDED(hr))
  68. {
  69. m_pWANIPConnectionService->AddRef();
  70. hr = m_pWANIPConnectionService->Initialize(pGuid, pPublicConnection, m_pStatisticsProvider);
  71. }
  72. }
  73. else
  74. {
  75. hr = CComObject<CWANPPPConnectionService>::CreateInstance(&m_pWANPPPConnectionService);
  76. if(SUCCEEDED(hr))
  77. {
  78. m_pWANPPPConnectionService->AddRef();
  79. hr = m_pWANPPPConnectionService->Initialize(pGuid, pPublicConnection, m_pStatisticsProvider);
  80. }
  81. if(SUCCEEDED(hr))
  82. {
  83. hr = CComObject<CWANPOTSLinkConfigService>::CreateInstance(&m_pWANPOTSLinkConfigService);
  84. if(SUCCEEDED(hr))
  85. {
  86. m_pWANPOTSLinkConfigService->AddRef();
  87. hr = m_pWANPOTSLinkConfigService->Initialize(pNetConnection);
  88. }
  89. }
  90. }
  91. }
  92. NcFreeNetconProperties(pProperties);
  93. }
  94. pNetConnection->Release();
  95. }
  96. CoTaskMemFree(pGuid);
  97. }
  98. if(SUCCEEDED(hr))
  99. {
  100. hr = pPrivateConnection->GetGuid(&pGuid);
  101. if(SUCCEEDED(hr))
  102. {
  103. hr = CoCreateInstance(CLSID_UPnPDeviceHostICSSupport, NULL, CLSCTX_SERVER, IID_IUPnPDeviceHostICSSupport, reinterpret_cast<void**>(&m_pICSSupport));
  104. if(SUCCEEDED(hr))
  105. {
  106. hr = m_pICSSupport->SetICSInterfaces(1, pGuid);
  107. }
  108. CoTaskMemFree(pGuid);
  109. }
  110. }
  111. pPublicConnection->Release();
  112. pPrivateConnection->Release();
  113. }
  114. return hr;
  115. }
  116. HRESULT CWANCommonInterfaceConfigService::FinalRelease()
  117. {
  118. HRESULT hr = S_OK;
  119. if(NULL != m_pWANIPConnectionService)
  120. {
  121. m_pWANIPConnectionService->StopListening();
  122. m_pWANIPConnectionService->Release();
  123. }
  124. if(NULL != m_pWANPPPConnectionService)
  125. {
  126. m_pWANPPPConnectionService->StopListening();
  127. m_pWANPPPConnectionService->Release();
  128. }
  129. if(NULL != m_pWANPOTSLinkConfigService)
  130. {
  131. m_pWANPOTSLinkConfigService->Release();
  132. }
  133. if(NULL != m_pICSSupport)
  134. {
  135. m_pICSSupport->SetICSOff();
  136. m_pICSSupport->Release();
  137. }
  138. if(NULL != m_pStatisticsProvider)
  139. {
  140. m_pStatisticsProvider->Release();
  141. }
  142. return hr;
  143. }
  144. HRESULT CWANCommonInterfaceConfigService::GetConnections(IHNetConnection** ppPublicConnection, IHNetConnection** ppPrivateConnection)
  145. {
  146. HRESULT hr = S_OK;
  147. *ppPublicConnection = NULL;
  148. *ppPrivateConnection = NULL;
  149. IHNetIcsSettings* pIcsSettings;
  150. hr = CoCreateInstance(CLSID_HNetCfgMgr, NULL, CLSCTX_SERVER, IID_IHNetIcsSettings, reinterpret_cast<void**>(&pIcsSettings));
  151. if(SUCCEEDED(hr))
  152. {
  153. IHNetConnection* pHomenetConnection;
  154. IEnumHNetIcsPublicConnections* pEnumIcsPublicConnections;
  155. hr = pIcsSettings->EnumIcsPublicConnections(&pEnumIcsPublicConnections);
  156. if(SUCCEEDED(hr))
  157. {
  158. IHNetIcsPublicConnection* pPublicConnection;
  159. hr = pEnumIcsPublicConnections->Next(1, &pPublicConnection, NULL);
  160. if(S_OK == hr)
  161. {
  162. hr = pPublicConnection->QueryInterface(IID_IHNetConnection, reinterpret_cast<void**>(&pHomenetConnection));
  163. if(SUCCEEDED(hr))
  164. {
  165. *ppPublicConnection = pHomenetConnection;
  166. }
  167. pPublicConnection->Release();
  168. }
  169. else if(S_FALSE == hr)
  170. {
  171. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  172. }
  173. pEnumIcsPublicConnections->Release();
  174. }
  175. if(SUCCEEDED(hr))
  176. {
  177. IEnumHNetIcsPrivateConnections* pEnumIcsPrivateConnections;
  178. hr = pIcsSettings->EnumIcsPrivateConnections(&pEnumIcsPrivateConnections);
  179. if(SUCCEEDED(hr))
  180. {
  181. IHNetIcsPrivateConnection* pPrivateConnection;
  182. hr = pEnumIcsPrivateConnections->Next(1, &pPrivateConnection, NULL);
  183. if(S_OK == hr)
  184. {
  185. hr = pPrivateConnection->QueryInterface(IID_IHNetConnection, reinterpret_cast<void**>(&pHomenetConnection));
  186. if(SUCCEEDED(hr))
  187. {
  188. *ppPrivateConnection = pHomenetConnection;
  189. }
  190. pPrivateConnection->Release();
  191. }
  192. else if(S_FALSE == hr)
  193. {
  194. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  195. }
  196. pEnumIcsPrivateConnections->Release();
  197. }
  198. if(FAILED(hr))
  199. {
  200. if(NULL != *ppPublicConnection)
  201. {
  202. (*ppPublicConnection)->Release();
  203. *ppPublicConnection = NULL;
  204. }
  205. }
  206. }
  207. pIcsSettings->Release();
  208. }
  209. return hr;
  210. }
  211. // IUPnPEventSource methods
  212. HRESULT CWANCommonInterfaceConfigService::Advise(IUPnPEventSink *pesSubscriber)
  213. {
  214. HRESULT hr = S_OK;
  215. m_pEventSink = pesSubscriber;
  216. m_pEventSink->AddRef();
  217. return hr;
  218. }
  219. HRESULT CWANCommonInterfaceConfigService::Unadvise(IUPnPEventSink *pesSubscriber)
  220. {
  221. HRESULT hr = S_OK;
  222. if(NULL != m_pEventSink)
  223. {
  224. m_pEventSink->Release();
  225. m_pEventSink = NULL;
  226. }
  227. return hr;
  228. }
  229. // Functions for IWANCommonInterfaceConfig
  230. HRESULT CWANCommonInterfaceConfigService::get_WANAccessType(BSTR *pWANAccessType)
  231. {
  232. HRESULT hr = S_OK;
  233. *pWANAccessType = SysAllocString(NCM_LAN == m_MediaType ? L"Ethernet" : L"POTS");
  234. if(NULL == *pWANAccessType)
  235. {
  236. hr = E_OUTOFMEMORY;
  237. }
  238. return hr;
  239. }
  240. HRESULT CWANCommonInterfaceConfigService::get_Layer1UpstreamMaxBitRate(ULONG *pLayer1UpstreamMaxBitRate)
  241. {
  242. HRESULT hr = S_OK;
  243. hr = m_pStatisticsProvider->GetStatistics(NULL, NULL, NULL, NULL, pLayer1UpstreamMaxBitRate, NULL);
  244. return hr;
  245. }
  246. HRESULT CWANCommonInterfaceConfigService::get_Layer1DownstreamMaxBitRate(ULONG *pLayer1DownstreamMaxBitRate)
  247. {
  248. HRESULT hr = S_OK;
  249. hr = m_pStatisticsProvider->GetStatistics(NULL, NULL, NULL, NULL, pLayer1DownstreamMaxBitRate, NULL);
  250. return hr;
  251. }
  252. HRESULT CWANCommonInterfaceConfigService::get_PhysicalLinkStatus(BSTR *pPhysicalLinkStatus)
  253. {
  254. HRESULT hr = S_OK;
  255. *pPhysicalLinkStatus = SysAllocString(L"Up");
  256. return hr;
  257. }
  258. HRESULT CWANCommonInterfaceConfigService::get_TotalBytesSent(ULONG *pTotalBytesSent)
  259. {
  260. HRESULT hr = S_OK;
  261. hr = m_pStatisticsProvider->GetStatistics(pTotalBytesSent, NULL, NULL, NULL, NULL, NULL);
  262. return hr;
  263. }
  264. HRESULT CWANCommonInterfaceConfigService::get_TotalBytesReceived(ULONG *pTotalBytesReceived)
  265. {
  266. HRESULT hr = S_OK;
  267. hr = m_pStatisticsProvider->GetStatistics(NULL, pTotalBytesReceived, NULL, NULL, NULL, NULL);
  268. return hr;
  269. }
  270. HRESULT CWANCommonInterfaceConfigService::get_TotalPacketsSent(ULONG *pTotalPacketsSent)
  271. {
  272. HRESULT hr = S_OK;
  273. hr = m_pStatisticsProvider->GetStatistics(NULL, NULL, pTotalPacketsSent, NULL, NULL, NULL);
  274. return hr;
  275. }
  276. HRESULT CWANCommonInterfaceConfigService::get_TotalPacketsReceived(ULONG *pTotalPacketsReceived)
  277. {
  278. HRESULT hr = S_OK;
  279. hr = m_pStatisticsProvider->GetStatistics(NULL, NULL, NULL, pTotalPacketsReceived, NULL, NULL);
  280. return hr;
  281. }
  282. HRESULT CWANCommonInterfaceConfigService::get_WANAccessProvider(BSTR *pWANAccessProvider)
  283. {
  284. HRESULT hr = S_OK;
  285. *pWANAccessProvider = SysAllocString(L"");
  286. if(NULL == *pWANAccessProvider)
  287. {
  288. hr = E_OUTOFMEMORY;
  289. }
  290. return hr;
  291. }
  292. HRESULT CWANCommonInterfaceConfigService::get_MaximumActiveConnections(USHORT *pMaximumActiveConnections)
  293. {
  294. HRESULT hr = S_OK;
  295. *pMaximumActiveConnections = 0;
  296. return hr;
  297. }
  298. HRESULT CWANCommonInterfaceConfigService::get_X_PersonalFirewallEnabled(VARIANT_BOOL *pPersonalFirewallEnabled)
  299. {
  300. HRESULT hr = S_OK;
  301. *pPersonalFirewallEnabled = m_bFirewalled ? VARIANT_TRUE : VARIANT_FALSE;
  302. return hr;
  303. }
  304. HRESULT CWANCommonInterfaceConfigService::get_X_Uptime(ULONG *pUptime)
  305. {
  306. HRESULT hr = S_OK;
  307. hr = m_pStatisticsProvider->GetStatistics(NULL, NULL, NULL, NULL, NULL, pUptime);
  308. return hr;
  309. }
  310. HRESULT CWANCommonInterfaceConfigService::GetCommonLinkProperties(BSTR* pWANAccessType, ULONG* pLayer1UpstreamMaxBitRate, ULONG *pLayer1DownstreamMaxBitRate, BSTR *pPhysicalLinkStatus)
  311. {
  312. HRESULT hr = S_OK;
  313. SysFreeString(*pWANAccessType);
  314. SysFreeString(*pPhysicalLinkStatus);
  315. *pWANAccessType = NULL;
  316. *pPhysicalLinkStatus = NULL;
  317. hr = get_WANAccessType(pWANAccessType);
  318. if(SUCCEEDED(hr))
  319. {
  320. hr = get_Layer1UpstreamMaxBitRate(pLayer1UpstreamMaxBitRate);
  321. }
  322. if(SUCCEEDED(hr))
  323. {
  324. hr = get_Layer1DownstreamMaxBitRate(pLayer1DownstreamMaxBitRate);
  325. }
  326. if(SUCCEEDED(hr))
  327. {
  328. hr = get_PhysicalLinkStatus(pPhysicalLinkStatus);
  329. }
  330. if(FAILED(hr))
  331. {
  332. SysFreeString(*pWANAccessType);
  333. SysFreeString(*pPhysicalLinkStatus);
  334. *pWANAccessType = NULL;
  335. *pPhysicalLinkStatus = NULL;
  336. }
  337. return hr;
  338. }
  339. HRESULT CWANCommonInterfaceConfigService::GetTotalBytesSent(ULONG *pTotalBytesSent)
  340. {
  341. return get_TotalBytesSent(pTotalBytesSent);
  342. }
  343. HRESULT CWANCommonInterfaceConfigService::GetTotalBytesReceived(ULONG *pTotalBytesReceived)
  344. {
  345. return get_TotalBytesReceived(pTotalBytesReceived);
  346. }
  347. HRESULT CWANCommonInterfaceConfigService::GetTotalPacketsSent(ULONG *pTotalPacketsSent)
  348. {
  349. return get_TotalPacketsSent(pTotalPacketsSent);
  350. }
  351. HRESULT CWANCommonInterfaceConfigService::GetTotalPacketsReceived(ULONG *pTotalPacketsReceived)
  352. {
  353. return get_TotalPacketsReceived(pTotalPacketsReceived);
  354. }
  355. HRESULT CWANCommonInterfaceConfigService::X_GetICSStatistics(ULONG *pTotalBytesSent, ULONG *pTotalBytesReceived, ULONG *pTotalPacketsSent, ULONG *pTotalPacketsReceived, ULONG *pSpeed, ULONG *pUptime)
  356. {
  357. HRESULT hr = S_OK;
  358. hr = m_pStatisticsProvider->GetStatistics(pTotalBytesSent, pTotalBytesReceived, pTotalPacketsSent, pTotalPacketsReceived, pSpeed, pUptime);
  359. return hr;
  360. }