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.

395 lines
8.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: I N B U I . C P P
  7. //
  8. // Contents: Inbound Connection UI object.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 15 Nov 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "inbui.h"
  18. #include "nccom.h"
  19. #include "rasui.h"
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CInboundConnectionUi::CInboundConnectionUi
  23. //
  24. // Purpose: Constructor/Destructor
  25. //
  26. // Arguments:
  27. // (none)
  28. //
  29. // Returns:
  30. //
  31. // Author: shaunco 20 Oct 1997
  32. //
  33. // Notes:
  34. //
  35. CInboundConnectionUi::CInboundConnectionUi ()
  36. {
  37. m_pCon = NULL;
  38. m_hRasSrvConn = NULL;
  39. m_pvContext = NULL;
  40. m_dwRasWizType = RASWIZ_TYPE_INCOMING;
  41. }
  42. CInboundConnectionUi::~CInboundConnectionUi ()
  43. {
  44. ReleaseObj (m_pCon);
  45. }
  46. //+---------------------------------------------------------------------------
  47. // INetConnectionPropertyUi2
  48. //
  49. STDMETHODIMP
  50. CInboundConnectionUi::SetConnection (
  51. INetConnection* pCon)
  52. {
  53. // Enter our critical section to protect the use of m_pCon.
  54. //
  55. CExceptionSafeComObjectLock EsLock (this);
  56. HRESULT hr = S_OK;
  57. HRASSRVCONN hRasSrvConn = NULL;
  58. // If we were given a connection, verify it by QI'ing for
  59. // INetInboundConnection and calling the GetServerConnectionHandle method.
  60. // This also gives us m_hRasSrvConn which we need later anyway.
  61. //
  62. if (pCon)
  63. {
  64. INetInboundConnection* pInboundCon;
  65. hr = HrQIAndSetProxyBlanket(pCon, &pInboundCon);
  66. if (SUCCEEDED(hr))
  67. {
  68. hr = pInboundCon->GetServerConnectionHandle (
  69. reinterpret_cast<ULONG_PTR*>(&hRasSrvConn));
  70. ReleaseObj (pInboundCon);
  71. }
  72. else if (E_NOINTERFACE == hr)
  73. {
  74. // If the connection object, doesn't support the interface, it's
  75. // not our object. The client has messed up and passed us a bogus
  76. // argument.
  77. //
  78. hr = E_INVALIDARG;
  79. }
  80. }
  81. // Only change our state if the above succeeded.
  82. //
  83. if (SUCCEEDED(hr))
  84. {
  85. ReleaseObj (m_pCon);
  86. m_pCon = pCon;
  87. AddRefObj (m_pCon);
  88. m_hRasSrvConn = hRasSrvConn;
  89. }
  90. TraceError ("CInboundConnectionUi::SetConnection", hr);
  91. return hr;
  92. }
  93. STDMETHODIMP
  94. CInboundConnectionUi::AddPages (
  95. HWND hwndParent,
  96. LPFNADDPROPSHEETPAGE pfnAddPage,
  97. LPARAM lParam)
  98. {
  99. HRESULT hr;
  100. // Validate parameters.
  101. //
  102. if (!pfnAddPage)
  103. {
  104. hr = E_POINTER;
  105. }
  106. // Must have called SetConnection prior to this.
  107. //
  108. else if (!m_pCon)
  109. {
  110. hr = E_UNEXPECTED;
  111. }
  112. else
  113. {
  114. DWORD dwErr = RasSrvAddPropPages (
  115. m_hRasSrvConn,
  116. hwndParent,
  117. pfnAddPage,
  118. lParam,
  119. &m_pvContext);
  120. hr = HRESULT_FROM_WIN32 (dwErr);
  121. TraceError ("RasSrvAddPropPages", hr);
  122. }
  123. TraceError ("CInboundConnectionUi::AddPages (INetConnectionPropertyUi)", hr);
  124. return hr;
  125. }
  126. STDMETHODIMP
  127. CInboundConnectionUi::GetIcon (
  128. DWORD dwSize,
  129. HICON *phIcon )
  130. {
  131. HRESULT hr;
  132. Assert (phIcon);
  133. hr = HrGetIconFromMediaType(dwSize, NCM_NONE, NCSM_NONE, 7, 0, phIcon);
  134. TraceError ("CLanConnectionUi::GetIcon (INetConnectionPropertyUi2)", hr);
  135. return hr;
  136. }
  137. //+---------------------------------------------------------------------------
  138. // INetConnectionWizardUi
  139. //
  140. STDMETHODIMP
  141. CInboundConnectionUi::QueryMaxPageCount (
  142. INetConnectionWizardUiContext* pContext,
  143. DWORD* pcMaxPages)
  144. {
  145. HRESULT hr = S_OK;
  146. // Validate parameters.
  147. //
  148. if (!pcMaxPages)
  149. {
  150. hr = E_POINTER;
  151. }
  152. else
  153. {
  154. *pcMaxPages = RasWizQueryMaxPageCount (m_dwRasWizType);
  155. }
  156. TraceError ("CInboundConnectionUi::QueryMaxPageCount", hr);
  157. return hr;
  158. }
  159. STDMETHODIMP
  160. CInboundConnectionUi::AddPages (
  161. INetConnectionWizardUiContext* pContext,
  162. LPFNADDPROPSHEETPAGE pfnAddPage,
  163. LPARAM lParam)
  164. {
  165. HRESULT hr;
  166. // Validate parameters.
  167. //
  168. if (!pfnAddPage)
  169. {
  170. hr = E_POINTER;
  171. }
  172. else
  173. {
  174. DWORD dwErr = RasSrvAddWizPages (pfnAddPage, lParam, &(m_pvContext));
  175. hr = HRESULT_FROM_WIN32 (dwErr);
  176. TraceError ("RasSrvAddWizPages", hr);
  177. }
  178. TraceError ("CInboundConnectionUi::AddPages (INetConnectionWizardUi)", hr);
  179. return hr;
  180. }
  181. STDMETHODIMP
  182. CInboundConnectionUi::GetSuggestedConnectionName (
  183. PWSTR* ppszwSuggestedName)
  184. {
  185. HRESULT hr;
  186. // Validate parameters.
  187. //
  188. if (!ppszwSuggestedName)
  189. {
  190. hr = E_POINTER;
  191. }
  192. else
  193. {
  194. *ppszwSuggestedName = NULL;
  195. WCHAR pszName[MAX_PATH];
  196. DWORD dwErr;
  197. dwErr = RasWizGetSuggestedEntryName (
  198. m_dwRasWizType, m_pvContext, pszName);
  199. hr = HRESULT_FROM_WIN32 (dwErr);
  200. TraceError ("RasWizGetSuggestedEntryName", hr);
  201. if (SUCCEEDED(hr))
  202. {
  203. hr = HrCoTaskMemAllocAndDupSz (
  204. pszName,
  205. ppszwSuggestedName);
  206. }
  207. }
  208. TraceError ("CInboundConnectionUi::GetSuggestedConnectionName", hr);
  209. return hr;
  210. }
  211. STDMETHODIMP
  212. CInboundConnectionUi::GetNewConnectionInfo (
  213. DWORD* pdwFlags,
  214. NETCON_MEDIATYPE* pMediaType)
  215. {
  216. HRESULT hr = S_OK;
  217. *pMediaType = NCM_NONE;
  218. if (!pdwFlags)
  219. {
  220. hr = E_POINTER;
  221. }
  222. else
  223. {
  224. *pdwFlags = 0;
  225. Assert (m_pvContext);
  226. DWORD dwRasFlags;
  227. DWORD dwErr = RasWizGetNCCFlags (
  228. m_dwRasWizType,
  229. m_pvContext,
  230. &dwRasFlags);
  231. hr = HRESULT_FROM_WIN32 (dwErr);
  232. TraceError ("RasWizGetNCCFlags", hr);
  233. if (SUCCEEDED(hr))
  234. {
  235. if (dwRasFlags & NCC_FLAG_CREATE_INCOMING)
  236. {
  237. *pdwFlags |= NCWF_INCOMINGCONNECTION;
  238. }
  239. if (dwRasFlags & NCC_FLAG_FIREWALL)
  240. {
  241. *pdwFlags |= NCWF_FIREWALLED;
  242. }
  243. if (dwRasFlags & NCC_FLAG_SHARED)
  244. {
  245. *pdwFlags |= NCWF_SHARED;
  246. }
  247. if (dwRasFlags & NCC_FLAG_ALL_USERS)
  248. {
  249. *pdwFlags |= NCWF_ALLUSER_CONNECTION;
  250. }
  251. if (dwRasFlags & NCC_FLAG_GLOBALCREDS)
  252. {
  253. *pdwFlags |= NCWF_GLOBAL_CREDENTIALS;
  254. }
  255. if (dwRasFlags & NCC_FLAG_DEFAULT_INTERNET)
  256. {
  257. *pdwFlags |= NCWF_DEFAULT;
  258. }
  259. }
  260. else if (E_INVALIDARG == hr)
  261. {
  262. hr = E_UNEXPECTED;
  263. }
  264. }
  265. BOOL fAllowRename;
  266. DWORD dwErr = RasWizIsEntryRenamable (
  267. m_dwRasWizType,
  268. m_pvContext,
  269. &fAllowRename);
  270. hr = HRESULT_FROM_WIN32 (dwErr);
  271. TraceError ("RasWizIsEntryRenamable", hr);
  272. if (SUCCEEDED(hr))
  273. {
  274. if (!fAllowRename)
  275. {
  276. *pdwFlags |= NCWF_RENAME_DISABLE;
  277. }
  278. }
  279. TraceError ("CInboundConnectionUi::GetNewConnectionInfo", hr);
  280. return hr;
  281. }
  282. STDMETHODIMP
  283. CInboundConnectionUi::SetConnectionName (
  284. PCWSTR pszwConnectionName)
  285. {
  286. HRESULT hr;
  287. // Validate parameters.
  288. //
  289. if (!pszwConnectionName)
  290. {
  291. hr = E_POINTER;
  292. }
  293. else
  294. {
  295. DWORD dwErr = RasWizSetEntryName (
  296. m_dwRasWizType,
  297. m_pvContext,
  298. pszwConnectionName);
  299. hr = HRESULT_FROM_WIN32 (dwErr);
  300. TraceError ("RasWizSetEntryName", hr);
  301. }
  302. TraceError ("CInboundConnectionUi::SetConnectionName", hr);
  303. return hr;
  304. }
  305. STDMETHODIMP
  306. CInboundConnectionUi::GetNewConnection (
  307. INetConnection** ppCon)
  308. {
  309. HRESULT hr;
  310. // Validate parameters.
  311. //
  312. if (!ppCon)
  313. {
  314. hr = E_POINTER;
  315. }
  316. /*
  317. // Must have called SetConnectionName prior to this.
  318. //
  319. else if (m_strConnectionName.empty())
  320. {
  321. hr = E_UNEXPECTED;
  322. }
  323. */
  324. else
  325. {
  326. *ppCon = NULL;
  327. // Commit the settings made in the wizard.
  328. //
  329. DWORD dwErr = RasWizCreateNewEntry (
  330. m_dwRasWizType,
  331. m_pvContext, NULL, NULL, NULL);
  332. hr = HRESULT_FROM_WIN32 (dwErr);
  333. TraceError ("RasWizCreateNewEntry", hr);
  334. if (SUCCEEDED(hr))
  335. {
  336. hr = HrCreateInboundConfigConnection (ppCon);
  337. }
  338. }
  339. TraceError ("CInboundConnectionUi::GetNewConnection", hr);
  340. return hr;
  341. }