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.

228 lines
5.2 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "CWANPOTSLinkConfigService.h"
  4. #include "raserror.h"
  5. CWANPOTSLinkConfigService::CWANPOTSLinkConfigService()
  6. {
  7. m_pEventSink = NULL;
  8. m_pNetRasConnection = NULL;
  9. }
  10. HRESULT CWANPOTSLinkConfigService::Initialize(INetConnection* pNetConnection)
  11. {
  12. HRESULT hr = S_OK;
  13. hr = pNetConnection->QueryInterface(IID_INetRasConnection, reinterpret_cast<void**>(&m_pNetRasConnection));
  14. return hr;
  15. }
  16. HRESULT CWANPOTSLinkConfigService::FinalRelease(void)
  17. {
  18. HRESULT hr = S_OK;
  19. if(NULL != m_pNetRasConnection)
  20. {
  21. m_pNetRasConnection->Release();
  22. }
  23. return hr;
  24. }
  25. HRESULT CWANPOTSLinkConfigService::Advise(IUPnPEventSink* pesSubscriber)
  26. {
  27. HRESULT hr = S_OK;
  28. m_pEventSink = pesSubscriber;
  29. m_pEventSink->AddRef();
  30. return hr;
  31. }
  32. HRESULT CWANPOTSLinkConfigService::Unadvise(IUPnPEventSink *pesSubscriber)
  33. {
  34. HRESULT hr = S_OK;
  35. m_pEventSink->Release();
  36. m_pEventSink = NULL;
  37. return hr;
  38. }
  39. HRESULT CWANPOTSLinkConfigService::get_ISPPhoneNumber(BSTR* pISPPhoneNumber)
  40. {
  41. HRESULT hr = S_OK;
  42. *pISPPhoneNumber = NULL;
  43. RASENTRY* pRasEntry;
  44. hr = GetRasEntry(&pRasEntry);
  45. if(SUCCEEDED(hr))
  46. {
  47. *pISPPhoneNumber = SysAllocString(pRasEntry->szLocalPhoneNumber);
  48. if(NULL == *pISPPhoneNumber)
  49. {
  50. hr = E_OUTOFMEMORY;
  51. }
  52. CoTaskMemFree(pRasEntry);
  53. }
  54. return hr;
  55. }
  56. HRESULT CWANPOTSLinkConfigService::get_ISPInfo(BSTR *pISPInfo)
  57. {
  58. HRESULT hr = S_OK;
  59. *pISPInfo = SysAllocString(L"");
  60. if(NULL == *pISPInfo)
  61. {
  62. hr = E_OUTOFMEMORY;
  63. }
  64. return hr;
  65. }
  66. HRESULT CWANPOTSLinkConfigService::get_LinkType(BSTR *pLinkType)
  67. {
  68. HRESULT hr = S_OK;
  69. *pLinkType = SysAllocString(L"PPP_Dialup");
  70. if(NULL == *pLinkType)
  71. {
  72. hr = E_OUTOFMEMORY;
  73. }
  74. return hr;
  75. }
  76. HRESULT CWANPOTSLinkConfigService::get_NumberOfRetries(ULONG *pNumberOfRetries)
  77. {
  78. HRESULT hr = S_OK;
  79. RASENTRY* pRasEntry;
  80. hr = GetRasEntry(&pRasEntry);
  81. if(SUCCEEDED(hr))
  82. {
  83. *pNumberOfRetries = pRasEntry->dwRedialCount;
  84. CoTaskMemFree(pRasEntry);
  85. }
  86. return hr;
  87. }
  88. HRESULT CWANPOTSLinkConfigService::get_DelayBetweenRetries(ULONG *pDelayBetweenRetries)
  89. {
  90. HRESULT hr = S_OK;
  91. RASENTRY* pRasEntry;
  92. hr = GetRasEntry(&pRasEntry);
  93. if(SUCCEEDED(hr))
  94. {
  95. *pDelayBetweenRetries = pRasEntry->dwRedialPause;
  96. CoTaskMemFree(pRasEntry);
  97. }
  98. return hr;
  99. }
  100. HRESULT CWANPOTSLinkConfigService::GetISPInfo(BSTR* pISPPhoneNumber, BSTR *pISPInfo, BSTR *pLinkType)
  101. {
  102. HRESULT hr = S_OK;
  103. SysFreeString(*pISPPhoneNumber);
  104. SysFreeString(*pISPInfo);
  105. SysFreeString(*pLinkType);
  106. *pISPPhoneNumber = NULL;
  107. *pISPInfo = NULL;
  108. *pLinkType = NULL;
  109. hr = get_ISPPhoneNumber(pISPPhoneNumber);
  110. if(SUCCEEDED(hr))
  111. {
  112. hr = get_ISPInfo(pISPInfo);
  113. }
  114. if(SUCCEEDED(hr))
  115. {
  116. hr = get_LinkType(pLinkType);
  117. }
  118. if(FAILED(hr))
  119. {
  120. SysFreeString(*pISPPhoneNumber);
  121. SysFreeString(*pISPInfo);
  122. SysFreeString(*pLinkType);
  123. *pISPPhoneNumber = NULL;
  124. *pISPInfo = NULL;
  125. *pLinkType = NULL;
  126. }
  127. return hr;
  128. }
  129. HRESULT CWANPOTSLinkConfigService::GetCallRetryInfo(ULONG* pNumberOfRetries, ULONG *pDelayBetweenRetries)
  130. {
  131. HRESULT hr = S_OK;
  132. hr = get_NumberOfRetries(pNumberOfRetries);
  133. if(SUCCEEDED(hr))
  134. {
  135. hr = get_DelayBetweenRetries(pDelayBetweenRetries);
  136. }
  137. return hr;
  138. }
  139. HRESULT CWANPOTSLinkConfigService::GetRasEntry(RASENTRY** ppRasEntry)
  140. {
  141. HRESULT hr = S_OK;
  142. *ppRasEntry = NULL;
  143. RASCON_INFO RasConnectionInfo;
  144. hr = m_pNetRasConnection->GetRasConnectionInfo(&RasConnectionInfo);
  145. if(SUCCEEDED(hr))
  146. {
  147. RASENTRY DummyRasEntry;
  148. ZeroMemory(&DummyRasEntry, sizeof(DummyRasEntry));
  149. DummyRasEntry.dwSize = sizeof(DummyRasEntry);
  150. DWORD dwEntrySize = sizeof(DummyRasEntry);
  151. DWORD dwError = RasGetEntryProperties(RasConnectionInfo.pszwPbkFile, RasConnectionInfo.pszwEntryName, &DummyRasEntry, &dwEntrySize, NULL, NULL);
  152. if(0 == dwError || ERROR_BUFFER_TOO_SMALL == dwError)
  153. {
  154. RASENTRY* pRasEntry = reinterpret_cast<RASENTRY*>(CoTaskMemAlloc(dwEntrySize));
  155. if(NULL != pRasEntry)
  156. {
  157. ZeroMemory(pRasEntry, dwEntrySize);
  158. pRasEntry->dwSize = sizeof(RASENTRY);
  159. dwError = RasGetEntryProperties(RasConnectionInfo.pszwPbkFile, RasConnectionInfo.pszwEntryName, pRasEntry, &dwEntrySize, NULL, NULL);
  160. if(0 == dwError)
  161. {
  162. *ppRasEntry = pRasEntry;
  163. }
  164. else
  165. {
  166. hr = E_FAIL;
  167. }
  168. if(FAILED(hr))
  169. {
  170. CoTaskMemFree(pRasEntry);
  171. }
  172. }
  173. else
  174. {
  175. hr = E_OUTOFMEMORY;
  176. }
  177. }
  178. else
  179. {
  180. hr = E_FAIL;
  181. }
  182. CoTaskMemFree(RasConnectionInfo.pszwPbkFile);
  183. CoTaskMemFree(RasConnectionInfo.pszwEntryName);
  184. }
  185. return hr;
  186. }