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.

2155 lines
57 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // MSOBCOMM.CPP - Implementation of CObCommunicationManager
  7. //
  8. // HISTORY:
  9. //
  10. // 1/27/99 a-jaswed Created.
  11. //
  12. // Class which will manage all communication functions
  13. #include "msobcomm.h"
  14. #include "dispids.h"
  15. #include "CntPoint.h" // ConnectionPoint Component
  16. #include <ocidl.h> //For IConnectionPoint and IEnumConnectionPoints
  17. #include <olectl.h>
  18. #include <shlwapi.h>
  19. #include <util.h>
  20. #include "enumodem.h"
  21. #include "commerr.h"
  22. #include "homenet.h"
  23. extern DWORD
  24. IsMouseOrKeyboardPresent(HWND HWnd,
  25. PBOOL pbKeyboardPresent,
  26. PBOOL pbMousePresent);
  27. CObCommunicationManager* gpCommMgr = NULL;
  28. ///////////////////////////////////////////////////////////
  29. //
  30. // Creation function used by CFactory.
  31. //
  32. HRESULT CObCommunicationManager::CreateInstance(IUnknown* pOuterUnknown,
  33. CUnknown** ppNewComponent)
  34. {
  35. if (pOuterUnknown != NULL)
  36. {
  37. // Don't allow aggregation. Just for the heck of it.
  38. return CLASS_E_NOAGGREGATION;
  39. }
  40. *ppNewComponent = new CObCommunicationManager(pOuterUnknown);
  41. return S_OK;
  42. }
  43. ///////////////////////////////////////////////////////////
  44. //
  45. // NondelegatingQueryInterface
  46. //
  47. HRESULT __stdcall
  48. CObCommunicationManager::NondelegatingQueryInterface(const IID& iid, void** ppv)
  49. {
  50. if (iid == IID_IObCommunicationManager2 || iid == IID_IObCommunicationManager)
  51. {
  52. return FinishQI(static_cast<IObCommunicationManager*>(this), ppv);
  53. }
  54. else
  55. {
  56. return CUnknown::NondelegatingQueryInterface(iid, ppv);
  57. }
  58. }
  59. ///////////////////////////////////////////////////////////
  60. //
  61. // Constructor
  62. //
  63. CObCommunicationManager::CObCommunicationManager(IUnknown* pOuterUnknown)
  64. : CUnknown(pOuterUnknown)
  65. {
  66. m_pConnectionPoint = NULL;
  67. m_pWebGate = NULL;
  68. m_hwndCallBack = NULL;
  69. m_pRefDial = NULL;
  70. m_InsHandler = NULL;
  71. m_pDisp = NULL;
  72. m_IcsMgr = NULL;
  73. m_bIsIcsUsed = FALSE;
  74. ZeroMemory(m_szExternalConnectoid, sizeof(m_szExternalConnectoid));
  75. m_bFirewall = FALSE;
  76. m_bAutodialCleanup = FALSE;
  77. }
  78. ///////////////////////////////////////////////////////////
  79. //
  80. // Destructor
  81. //
  82. CObCommunicationManager::~CObCommunicationManager()
  83. {
  84. if (m_pDisp)
  85. m_pDisp->Release();
  86. if (m_InsHandler)
  87. delete m_InsHandler;
  88. if (m_pRefDial)
  89. delete m_pRefDial;
  90. if (m_pWebGate)
  91. delete m_pWebGate;
  92. if (m_pConnectionPoint)
  93. delete m_pConnectionPoint;
  94. if (m_IcsMgr)
  95. delete m_IcsMgr;
  96. OobeAutodialHangup();
  97. }
  98. ///////////////////////////////////////////////////////////
  99. //
  100. // FinalRelease -- Clean up the aggreated objects.
  101. //
  102. void CObCommunicationManager::FinalRelease()
  103. {
  104. CUnknown::FinalRelease();
  105. }
  106. ///////////////////////////////////////////////////////////
  107. // IObCommunicationManager Implementation
  108. ///////////////////////////////////////////////////////////
  109. INT CObCommunicationManager::m_nNumListener = 0;
  110. ///////////////////////////////////////////////////////////
  111. // ListenToCommunicationEvents
  112. HRESULT CObCommunicationManager::ListenToCommunicationEvents(IUnknown* pUnk)
  113. {
  114. DObCommunicationEvents* pCommEvent = NULL;
  115. m_pDisp = NULL;
  116. CObCommunicationManager::m_nNumListener ++;
  117. //first things first
  118. if (!pUnk)
  119. return E_FAIL;
  120. //So somebody want to register to listen to our ObWebBrowser events
  121. //Ok, let's get sneaky and reverse QI them to see if they even say they
  122. //support the right interfaces
  123. //if (FAILED(pUnk->QueryInterface(DIID_DObCommunicationEvents, (LPVOID*)&pCommEvent)) || !pCommEvent)
  124. // return E_UNEXPECTED;
  125. // ListenToCommunicationEvents treats CConnectionPoint as a C++ object and not like a COM object.
  126. // Everyone else deals with CConnectionPoint through COM interfaces.
  127. if (!m_pConnectionPoint)
  128. m_pConnectionPoint = new CConnectionPoint(this, &IID_IDispatch) ;
  129. if (FAILED(pUnk->QueryInterface(IID_IDispatch, (LPVOID*)&m_pDisp)) || !m_pDisp)
  130. return E_UNEXPECTED;
  131. gpCommMgr = this;
  132. m_pRefDial = new CRefDial();
  133. m_pWebGate = new CWebGate();
  134. //Ok, everything looks OK, try to setup a connection point.
  135. // Setup to get WebBrowserEvents
  136. return ConnectToConnectionPoint(pUnk,
  137. DIID_DObCommunicationEvents,
  138. TRUE,
  139. (IObCommunicationManager*)this,
  140. &m_dwcpCookie,
  141. NULL);
  142. }
  143. HRESULT CObCommunicationManager::ConnectToConnectionPoint( IUnknown* punkThis,
  144. REFIID riidEvent,
  145. BOOL fConnect,
  146. IUnknown* punkTarget,
  147. DWORD* pdwCookie,
  148. IConnectionPoint** ppcpOut)
  149. {
  150. HRESULT hr = E_FAIL;
  151. IConnectionPointContainer* pcpContainer = NULL;
  152. // We always need punkTarget, we only need punkThis on connect
  153. if (!punkTarget || (fConnect && !punkThis))
  154. {
  155. return E_FAIL;
  156. }
  157. if (ppcpOut)
  158. *ppcpOut = NULL;
  159. IConnectionPoint *pcp;
  160. if(SUCCEEDED(hr = FindConnectionPoint(riidEvent, &pcp)))
  161. {
  162. if(fConnect)
  163. {
  164. // Add us to the list of people interested...
  165. hr = pcp->Advise(punkThis, pdwCookie);
  166. if (FAILED(hr))
  167. *pdwCookie = 0;
  168. }
  169. else
  170. {
  171. // Remove us from the list of people interested...
  172. hr = pcp->Unadvise(*pdwCookie);
  173. *pdwCookie = 0;
  174. }
  175. if (ppcpOut && SUCCEEDED(hr))
  176. *ppcpOut = pcp;
  177. else
  178. pcp->Release();
  179. pcp = NULL;
  180. }
  181. return hr;
  182. }
  183. ///////////////////////////////////////////////////////////
  184. //
  185. // IConnectionPointContainer
  186. //
  187. ///////////////////////////////////////////////////////////
  188. //
  189. // EnumConnectionPoints
  190. //
  191. HRESULT CObCommunicationManager::EnumConnectionPoints(IEnumConnectionPoints **ppEnum)
  192. {
  193. // Construct the enumerator object.
  194. //IEnumConnectionPoints* pEnum = new CEnumConnectionPoints(m_pConnectionPoint) ;
  195. // The contructor AddRefs for us.
  196. //*ppEnum = pEnum ;
  197. return S_OK ;
  198. }
  199. ///////////////////////////////////////////////////////////
  200. //
  201. // FindConnectionPoint
  202. //
  203. HRESULT CObCommunicationManager::FindConnectionPoint(REFIID riid, IConnectionPoint **ppCP)
  204. {
  205. // Model only supports a single connection point.
  206. if (riid != DIID_DObCommunicationEvents)
  207. {
  208. *ppCP = NULL ;
  209. return CONNECT_E_NOCONNECTION ;
  210. }
  211. if (m_pConnectionPoint == NULL)
  212. {
  213. return E_FAIL ;
  214. }
  215. // Get the interface point to the connection point object.
  216. IConnectionPoint* pIConnectionPoint = m_pConnectionPoint ;
  217. // AddRef the interface.
  218. pIConnectionPoint->AddRef() ;
  219. // Return the interface to the client.
  220. *ppCP = pIConnectionPoint ;
  221. return S_OK ;
  222. }
  223. ///////////////////////////////////////////////////////////
  224. // DWebBrowserEvents2 / IDispatch implementation
  225. ///////////////////////////////////////////////////////////
  226. STDMETHODIMP CObCommunicationManager::GetTypeInfoCount(UINT* pcInfo)
  227. {
  228. return E_NOTIMPL;
  229. }
  230. STDMETHODIMP CObCommunicationManager::GetTypeInfo(UINT, LCID, ITypeInfo** )
  231. {
  232. return E_NOTIMPL;
  233. }
  234. // COleSite::GetIDsOfNames
  235. STDMETHODIMP CObCommunicationManager::GetIDsOfNames(
  236. /* [in] */ REFIID riid,
  237. /* [size_is][in] */ OLECHAR** rgszNames,
  238. /* [in] */ UINT cNames,
  239. /* [in] */ LCID lcid,
  240. /* [size_is][out] */ DISPID* rgDispId)
  241. {
  242. return ResultFromScode(DISP_E_UNKNOWNNAME);
  243. }
  244. /////////////////////////////////////////////////////////////
  245. // COleSite::Invoke
  246. HRESULT CObCommunicationManager::Invoke
  247. (
  248. DISPID dispidMember,
  249. REFIID riid,
  250. LCID lcid,
  251. WORD wFlags,
  252. DISPPARAMS FAR* pdispparams,
  253. VARIANT FAR* pvarResult,
  254. EXCEPINFO FAR* pexcepinfo,
  255. UINT FAR* puArgErr
  256. )
  257. {
  258. HRESULT hr = DISP_E_MEMBERNOTFOUND;
  259. /*
  260. switch(dispidMember)
  261. {
  262. default:
  263. break;
  264. }
  265. */
  266. return hr;
  267. }
  268. /////////////////////////////////////////////////////////////
  269. /////////////////////////////////////////////////////////////
  270. /////////////////////////////////////////////////////////////
  271. ////// Methods
  272. //////
  273. //////
  274. //////
  275. ///////////////////////////////////////////////////////////
  276. //
  277. // IMsobComm Interface
  278. //
  279. ///////////////////////////////////////////////////////////
  280. //
  281. // CheckDialReady
  282. //
  283. HRESULT CObCommunicationManager::CheckDialReady(DWORD *pdwRetVal)
  284. {
  285. HINSTANCE hinst = NULL;
  286. FARPROC fp;
  287. HRESULT hr = E_FAIL;
  288. if (NULL == pdwRetVal)
  289. return ERR_COMM_UNKNOWN;
  290. *pdwRetVal = ERR_COMM_OOBE_COMP_MISSING;
  291. if (IsNT())
  292. {
  293. hinst = LoadLibrary(L"ICFGNT5.DLL");
  294. }
  295. else
  296. {
  297. hinst = LoadLibrary(L"ICFG95.DLL");
  298. }
  299. if (hinst)
  300. {
  301. fp = GetProcAddress(hinst, "IcfgNeedInetComponents");
  302. if (fp)
  303. {
  304. DWORD dwfInstallOptions = ICFG_INSTALLTCP;
  305. dwfInstallOptions |= ICFG_INSTALLRAS;
  306. dwfInstallOptions |= ICFG_INSTALLDIALUP;
  307. //dwfInstallOptions |= ICFG_INSTALLMAIL;
  308. BOOL fNeedSysComponents = FALSE;
  309. DWORD dwRet = ((ICFGNEEDSYSCOMPONENTS)fp)(dwfInstallOptions, &fNeedSysComponents);
  310. if (ERROR_SUCCESS == dwRet)
  311. {
  312. // We don't have RAS or TCPIP
  313. if (fNeedSysComponents)
  314. {
  315. *pdwRetVal = ERR_COMM_RAS_TCP_NOTINSTALL;
  316. TRACE(L"RAS or TCPIP not install");
  317. }
  318. else
  319. {
  320. // check modem
  321. // The does does not exist, we failed.
  322. m_EnumModem.ReInit();
  323. if (NULL != m_EnumModem.GetDeviceNameFromType(RASDT_Modem))
  324. {
  325. if (NULL == m_EnumModem.GetDeviceNameFromType(RASDT_Isdn))
  326. {
  327. *pdwRetVal = ERR_COMM_NO_ERROR;
  328. }
  329. else
  330. {
  331. *pdwRetVal = ERR_COMM_PHONE_AND_ISDN;
  332. }
  333. }
  334. else if (NULL != m_EnumModem.GetDeviceNameFromType(RASDT_Isdn))
  335. {
  336. *pdwRetVal = ERR_COMM_ISDN;
  337. }
  338. else
  339. {
  340. *pdwRetVal = ERR_COMM_NOMODEM;
  341. }
  342. }
  343. }
  344. hr = S_OK;
  345. }
  346. FreeLibrary(hinst);
  347. }
  348. return hr ;
  349. }
  350. //////////////////////////////////////////////////////////////////////////////
  351. //
  352. // GetConnectionCapabilities
  353. //
  354. // Retrieves LAN connection capabilities.
  355. //
  356. // For Whistler we rely on the modem path through EnumModem and RAS to
  357. // determine whether a modem is installed.
  358. //
  359. //
  360. // parameters:
  361. // _parm_ _description_
  362. //
  363. // returns:
  364. // _description_
  365. //
  366. //////////////////////////////////////////////////////////////////////////////
  367. HRESULT
  368. CObCommunicationManager::GetConnectionCapabilities(
  369. DWORD* pdwConnectionCapabilities
  370. )
  371. {
  372. TRACE(L"CObCommunicationManager::GetConnectionCapabilities\n");
  373. return m_ConnectionManager.GetCapabilities(pdwConnectionCapabilities);
  374. } // CObCommunicationManager::GetConnectionCapabilities
  375. //////////////////////////////////////////////////////////////////////////////
  376. //
  377. // GetPreferredConnection
  378. //
  379. // _abstract_
  380. //
  381. // parameters:
  382. // _parm_ _description_
  383. //
  384. // returns:
  385. // _description_
  386. //
  387. //////////////////////////////////////////////////////////////////////////////
  388. HRESULT
  389. CObCommunicationManager::GetPreferredConnection(
  390. DWORD* pdwPreferredConnection
  391. )
  392. {
  393. return m_ConnectionManager.GetPreferredConnection(pdwPreferredConnection);
  394. } // CObCommunicationManager::GetPreferredConnection
  395. //////////////////////////////////////////////////////////////////////////////
  396. //
  397. // SetPreferredConnection
  398. //
  399. // _abstract_
  400. //
  401. // parameters:
  402. // _parm_ _description_
  403. //
  404. // returns:
  405. // _description_
  406. //
  407. //////////////////////////////////////////////////////////////////////////////
  408. HRESULT
  409. CObCommunicationManager::SetPreferredConnection(
  410. const DWORD dwPreferredConnection,
  411. BOOL* pfSupportedType
  412. )
  413. {
  414. return m_ConnectionManager.SetPreferredConnection(dwPreferredConnection,
  415. pfSupportedType
  416. );
  417. } // CObCommunicationManager::SetPreferredConnection
  418. //////////////////////////////////////////////////////////////////////////////
  419. //
  420. // ConnectedToInternet
  421. //
  422. // _abstract_
  423. //
  424. // parameters:
  425. // _parm_ _description_
  426. //
  427. // returns:
  428. // _description_
  429. //
  430. //////////////////////////////////////////////////////////////////////////////
  431. HRESULT
  432. CObCommunicationManager::ConnectedToInternet(
  433. BOOL* pfConnected
  434. )
  435. {
  436. return m_ConnectionManager.ConnectedToInternet(pfConnected);
  437. } // CObCommunicationManager::ConnectedToInternet
  438. //////////////////////////////////////////////////////////////////////////////
  439. //
  440. // ConnectedToInternetEx
  441. //
  442. // _abstract_
  443. //
  444. // parameters:
  445. // _parm_ _description_
  446. //
  447. // returns:
  448. // _description_
  449. //
  450. //////////////////////////////////////////////////////////////////////////////
  451. HRESULT
  452. CObCommunicationManager::ConnectedToInternetEx(
  453. BOOL* pfConnected
  454. )
  455. {
  456. return m_ConnectionManager.ConnectedToInternetEx(pfConnected);
  457. } // CObCommunicationManager::ConnectedToInternetEx
  458. //////////////////////////////////////////////////////////////////////////////
  459. //
  460. // AsyncConnectedToInternetEx
  461. //
  462. // _abstract_
  463. //
  464. // parameters:
  465. // _parm_ _description_
  466. //
  467. // returns:
  468. // _description_
  469. //
  470. //////////////////////////////////////////////////////////////////////////////
  471. HRESULT
  472. CObCommunicationManager::AsyncConnectedToInternetEx(
  473. const HWND hwnd
  474. )
  475. {
  476. return m_ConnectionManager.AsyncConnectedToInternetEx(hwnd);
  477. } // CObCommunicationManager::AsyncConnectedToInternetEx
  478. ///////////////////////////////////////////////////////////
  479. //
  480. // SetPreferredConnectionTcpipProperties
  481. //
  482. STDMETHODIMP CObCommunicationManager::SetPreferredConnectionTcpipProperties(
  483. BOOL fAutoIPAddress,
  484. DWORD StaticIp_A,
  485. DWORD StaticIp_B,
  486. DWORD StaticIp_C,
  487. DWORD StaticIp_D,
  488. DWORD SubnetMask_A,
  489. DWORD SubnetMask_B,
  490. DWORD SubnetMask_C,
  491. DWORD SubnetMask_D,
  492. DWORD DefGateway_A,
  493. DWORD DefGateway_B,
  494. DWORD DefGateway_C,
  495. DWORD DefGateway_D,
  496. BOOL fAutoDNS,
  497. DWORD DnsPref_A,
  498. DWORD DnsPref_B,
  499. DWORD DnsPref_C,
  500. DWORD DnsPref_D,
  501. DWORD DnsAlt_A,
  502. DWORD DnsAlt_B,
  503. DWORD DnsAlt_C,
  504. DWORD DnsAlt_D,
  505. BOOL fFirewallRequired
  506. )
  507. {
  508. HRESULT hr;
  509. hr = m_ConnectionManager.SetPreferredConnectionTcpipProperties(
  510. fAutoIPAddress,
  511. StaticIp_A,
  512. StaticIp_B,
  513. StaticIp_C,
  514. StaticIp_D,
  515. SubnetMask_A,
  516. SubnetMask_B,
  517. SubnetMask_C,
  518. SubnetMask_D,
  519. DefGateway_A,
  520. DefGateway_B,
  521. DefGateway_C,
  522. DefGateway_D,
  523. fAutoDNS,
  524. DnsPref_A,
  525. DnsPref_B,
  526. DnsPref_C,
  527. DnsPref_D,
  528. DnsAlt_A,
  529. DnsAlt_B,
  530. DnsAlt_C,
  531. DnsAlt_D
  532. );
  533. if (SUCCEEDED(hr) && fFirewallRequired)
  534. {
  535. // Save the connectoid name so it can be firewalled by the HomeNet
  536. // Wizard.
  537. m_ConnectionManager.GetPreferredConnectionName(
  538. m_szExternalConnectoid,
  539. sizeof(m_szExternalConnectoid)/sizeof(WCHAR)
  540. );
  541. }
  542. return hr;
  543. } // CObCommunicationManager::SetPreferredConnectionTcpipProperties
  544. ///////////////////////////////////////////////////////////
  545. //
  546. // FirewallPreferredConnection
  547. //
  548. HRESULT CObCommunicationManager::FirewallPreferredConnection(BOOL bFirewall)
  549. {
  550. m_bFirewall = bFirewall;
  551. if (bFirewall)
  552. {
  553. // Save the connectoid name so it can be firewalled by the HomeNet
  554. // Wizard.
  555. return m_ConnectionManager.GetPreferredConnectionName(
  556. m_szExternalConnectoid,
  557. sizeof(m_szExternalConnectoid)/sizeof(WCHAR)
  558. );
  559. }
  560. else
  561. {
  562. m_szExternalConnectoid[0] = TEXT('\0');
  563. return S_OK;
  564. }
  565. } // CObCommunicationManager::FirewallPreferredConnection
  566. ///////////////////////////////////////////////////////////
  567. //
  568. // SetupForDialing
  569. //
  570. HRESULT CObCommunicationManager::SetupForDialing(UINT nType, BSTR bstrISPFile, DWORD dwCountry, BSTR bstrAreaCode, DWORD dwFlag, DWORD dwAppMode, DWORD dwMigISPIdx)
  571. {
  572. HRESULT hr = E_FAIL;
  573. if (m_pRefDial)
  574. {
  575. BSTR bstrDeviceName = GetPreferredModem();
  576. if (bstrDeviceName)
  577. {
  578. hr = m_pRefDial->SetupForDialing(
  579. nType,
  580. bstrISPFile,
  581. dwCountry,
  582. bstrAreaCode,
  583. dwFlag,
  584. dwAppMode,
  585. dwMigISPIdx,
  586. bstrDeviceName);
  587. SysFreeString(bstrDeviceName);
  588. }
  589. }
  590. return hr;
  591. }
  592. ///////////////////////////////////////////////////////////
  593. //
  594. // DoConnect
  595. //
  596. HRESULT CObCommunicationManager::DoConnect(BOOL *pbRetVal)
  597. {
  598. if (m_pRefDial)
  599. {
  600. return m_pRefDial->DoConnect(pbRetVal);
  601. }
  602. return E_FAIL ;
  603. }
  604. ///////////////////////////////////////////////////////////
  605. //
  606. // SetRASCallbackHwnd
  607. //
  608. HRESULT CObCommunicationManager::SetRASCallbackHwnd(HWND hwndCallback)
  609. {
  610. m_hwndCallBack = hwndCallback;
  611. return S_OK;
  612. }
  613. ///////////////////////////////////////////////////////////
  614. //
  615. // DoHangup
  616. //
  617. HRESULT CObCommunicationManager::DoHangup()
  618. {
  619. if (m_pRefDial)
  620. {
  621. m_pRefDial->m_bUserInitiateHangup = TRUE;
  622. m_pRefDial->DoHangup();
  623. }
  624. return S_OK ;
  625. }
  626. ///////////////////////////////////////////////////////////
  627. //
  628. // GetDialPhoneNumber
  629. //
  630. HRESULT CObCommunicationManager::GetDialPhoneNumber(BSTR *pVal)
  631. {
  632. if (m_pRefDial)
  633. {
  634. m_pRefDial->GetDialPhoneNumber(pVal);
  635. }
  636. return S_OK ;
  637. }
  638. ///////////////////////////////////////////////////////////
  639. //
  640. // GetPhoneBookNumber
  641. //
  642. HRESULT CObCommunicationManager::GetPhoneBookNumber(BSTR *pVal)
  643. {
  644. if (m_pRefDial)
  645. {
  646. m_pRefDial->GetPhoneBookNumber(pVal);
  647. }
  648. return S_OK ;
  649. }
  650. ///////////////////////////////////////////////////////////
  651. //
  652. // PutDialPhoneNumber
  653. //
  654. HRESULT CObCommunicationManager::PutDialPhoneNumber(BSTR newVal)
  655. {
  656. if (m_pRefDial)
  657. {
  658. m_pRefDial->PutDialPhoneNumber(newVal);
  659. }
  660. return S_OK ;
  661. }
  662. ///////////////////////////////////////////////////////////
  663. //
  664. // SetDialAlternative
  665. //
  666. HRESULT CObCommunicationManager::SetDialAlternative(BOOL bVal)
  667. {
  668. if (m_pRefDial)
  669. {
  670. m_pRefDial->SetDialAlternative(bVal);
  671. }
  672. return S_OK;
  673. }
  674. ///////////////////////////////////////////////////////////
  675. //
  676. // GetDialErrorMsg
  677. //
  678. HRESULT CObCommunicationManager::GetDialErrorMsg(BSTR *pVal)
  679. {
  680. return S_OK ;
  681. }
  682. ///////////////////////////////////////////////////////////
  683. //
  684. // GetSupportNumber
  685. //
  686. HRESULT CObCommunicationManager::GetSupportNumber(BSTR *pVal)
  687. {
  688. return S_OK ;
  689. }
  690. ///////////////////////////////////////////////////////////
  691. //
  692. // RemoveConnectoid
  693. //
  694. HRESULT CObCommunicationManager::RemoveConnectoid(BOOL *pbRetVal)
  695. {
  696. return S_OK ;
  697. }
  698. ///////////////////////////////////////////////////////////
  699. //
  700. // GetSignupURL
  701. //
  702. HRESULT CObCommunicationManager::GetSignupURL(BSTR *pVal)
  703. {
  704. if (m_pRefDial)
  705. {
  706. m_pRefDial->get_SignupURL(pVal);
  707. }
  708. return S_OK ;
  709. }
  710. ///////////////////////////////////////////////////////////
  711. //
  712. // GetReconnectURL
  713. //
  714. HRESULT CObCommunicationManager::GetReconnectURL(BSTR *pVal)
  715. {
  716. if (m_pRefDial)
  717. {
  718. m_pRefDial->get_ReconnectURL(pVal);
  719. }
  720. return S_OK ;
  721. }
  722. ///////////////////////////////////////////////////////////
  723. //
  724. // GetConnectionType
  725. //
  726. HRESULT CObCommunicationManager::GetConnectionType(DWORD *pdwVal)
  727. {
  728. if (m_pRefDial)
  729. {
  730. m_pRefDial->GetConnectionType(pdwVal);
  731. }
  732. return S_OK ;
  733. }
  734. ///////////////////////////////////////////////////////////
  735. //
  736. // FetchPage
  737. //
  738. HRESULT CObCommunicationManager::FetchPage(BSTR bstrURL, BSTR* pbstrLocalFile)
  739. {
  740. BOOL bRetVal = 0;
  741. if (m_pWebGate && pbstrLocalFile)
  742. {
  743. BSTR bstrFileName = NULL;
  744. m_pWebGate->put_Path(bstrURL);
  745. m_pWebGate->FetchPage(1, &bRetVal);
  746. m_pWebGate->get_DownloadFname(&bstrFileName);
  747. *pbstrLocalFile = SysAllocString(bstrFileName);
  748. TRACE2(L"CObCommunicationManager::FetchPage(%s, %s)\n",
  749. bstrURL ? bstrURL : NULL,
  750. bstrFileName ? bstrFileName : NULL
  751. );
  752. }
  753. if (bRetVal)
  754. return S_OK ;
  755. return E_FAIL;
  756. }
  757. ///////////////////////////////////////////////////////////
  758. //
  759. // GetFile
  760. //
  761. HRESULT CObCommunicationManager::GetFile(BSTR bstrURL, BSTR bstrFileFullName)
  762. {
  763. if (m_pWebGate && bstrURL)
  764. {
  765. // Check for HTTP prefix
  766. if (PathIsURL(bstrURL))
  767. {
  768. BOOL bRetVal = FALSE;
  769. m_pWebGate->put_Path(bstrURL);
  770. m_pWebGate->FetchPage(1, &bRetVal);
  771. if (bRetVal && bstrFileFullName)
  772. {
  773. BSTR bstrTempFile = NULL;
  774. m_pWebGate->get_DownloadFname(&bstrTempFile);
  775. // Make sure we have a valid file name
  776. if (bstrTempFile)
  777. {
  778. if (CopyFile(bstrTempFile, bstrFileFullName, FALSE))
  779. {
  780. // Delete the temp file
  781. DeleteFile(bstrTempFile);
  782. return S_OK;
  783. }
  784. }
  785. }
  786. }
  787. }
  788. return E_FAIL ;
  789. }
  790. ///////////////////////////////////////////////////////////
  791. //
  792. // CheckPhoneBook
  793. //
  794. HRESULT CObCommunicationManager::CheckPhoneBook(BSTR bstrISPFile, DWORD dwCountry, BSTR bstrAreaCode, DWORD dwFlag, BOOL *pbRetVal)
  795. {
  796. if (m_pRefDial)
  797. {
  798. return m_pRefDial->CheckPhoneBook(bstrISPFile, dwCountry, bstrAreaCode, dwFlag, pbRetVal);
  799. }
  800. return E_FAIL ;
  801. }
  802. ///////////////////////////////////////////////////////////
  803. //
  804. // RestoreConnectoidInfo
  805. //
  806. HRESULT CObCommunicationManager::RestoreConnectoidInfo()
  807. {
  808. if (!m_InsHandler)
  809. m_InsHandler = new CINSHandler;
  810. if (m_InsHandler)
  811. {
  812. return m_InsHandler->RestoreConnectoidInfo();
  813. }
  814. return E_FAIL ;
  815. }
  816. ///////////////////////////////////////////////////////////
  817. //
  818. // SetPreloginMode
  819. //
  820. HRESULT CObCommunicationManager::SetPreloginMode(BOOL bVal)
  821. {
  822. m_pbPreLogin = bVal;
  823. return S_OK ;
  824. }
  825. ///////////////////////////////////////////////////////////
  826. //
  827. // DownloadFileBuffer
  828. //
  829. HRESULT CObCommunicationManager::DownloadFileBuffer(BSTR *pVal)
  830. {
  831. return S_OK ;
  832. }
  833. ///////////////////////////////////////////////////////////
  834. //
  835. // ProcessINS
  836. //
  837. HRESULT CObCommunicationManager::ProcessINS(BSTR bstrINSFilePath, BOOL *pbRetVal)
  838. {
  839. HRESULT hr = E_FAIL;
  840. if (!m_InsHandler)
  841. {
  842. m_InsHandler = new CINSHandler;
  843. if (m_InsHandler == NULL)
  844. {
  845. return hr;
  846. }
  847. }
  848. if (NULL == bstrINSFilePath)
  849. {
  850. *pbRetVal = m_InsHandler->ProcessOEMBrandINS(NULL,
  851. m_szExternalConnectoid
  852. );
  853. hr = S_OK;
  854. }
  855. else
  856. {
  857. // Download the ins file, then merge it with oembrnd.ins
  858. // Check for HTTP prefix
  859. if (PathIsURL(bstrINSFilePath))
  860. {
  861. if (m_pWebGate)
  862. {
  863. BOOL bRetVal;
  864. m_pWebGate->put_Path(bstrINSFilePath);
  865. m_pWebGate->FetchPage(1, &bRetVal);
  866. if (bRetVal)
  867. {
  868. BSTR bstrINSTempFile = NULL;
  869. if (S_OK == m_pWebGate->get_DownloadFname(&bstrINSTempFile))
  870. {
  871. if (bstrINSTempFile)
  872. {
  873. *pbRetVal = m_InsHandler->ProcessOEMBrandINS(
  874. bstrINSTempFile,
  875. m_szExternalConnectoid
  876. );
  877. hr = S_OK;
  878. }
  879. DeleteFile(bstrINSTempFile);
  880. }
  881. }
  882. }
  883. }
  884. else
  885. {
  886. *pbRetVal = m_InsHandler->ProcessOEMBrandINS(
  887. bstrINSFilePath,
  888. m_szExternalConnectoid
  889. );
  890. hr = S_OK;
  891. }
  892. }
  893. HKEY hKey;
  894. if ((S_OK == hr) && *pbRetVal)
  895. {
  896. if((ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  897. REG_KEY_OOBE_TEMP,
  898. 0,
  899. KEY_WRITE,
  900. &hKey)) && hKey)
  901. {
  902. hr = RegSetValueEx(hKey,
  903. REG_VAL_ISPSIGNUP,
  904. 0,
  905. REG_DWORD,
  906. (BYTE*)pbRetVal,
  907. sizeof(*pbRetVal));
  908. RegCloseKey(hKey);
  909. }
  910. else
  911. {
  912. DWORD dwDisposition = 0;
  913. if ( ERROR_SUCCESS == RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  914. REG_KEY_OOBE_TEMP,
  915. 0,
  916. NULL,
  917. REG_OPTION_NON_VOLATILE,
  918. KEY_ALL_ACCESS,
  919. NULL,
  920. &hKey,
  921. &dwDisposition))
  922. {
  923. hr = RegSetValueEx(hKey,
  924. REG_VAL_ISPSIGNUP,
  925. 0,
  926. REG_DWORD,
  927. (BYTE*)pbRetVal,
  928. sizeof(*pbRetVal));
  929. RegCloseKey(hKey);
  930. }
  931. }
  932. }
  933. return hr ;
  934. }
  935. ///////////////////////////////////////////////////////////
  936. //
  937. // CheckKbdMouse
  938. //
  939. HRESULT CObCommunicationManager::CheckKbdMouse(DWORD *pdwRetVal)
  940. {
  941. BOOL bkeyboard, bmouse;
  942. *pdwRetVal = 0;
  943. // summary: *pdwRetVal returns
  944. // 0 = Success (keyboard and mouse present
  945. // 1 = Keyboard is missing
  946. // 2 = Mouse is missing
  947. // 3 = Keyboard and mouse are missing
  948. IsMouseOrKeyboardPresent(m_hwndCallBack,
  949. &bkeyboard,
  950. &bmouse);
  951. // If there is a keyboard, set the first bit to 1
  952. if (bkeyboard)
  953. *pdwRetVal |= 0x01;
  954. // If there is a mouse, set the first bit to 1
  955. if (bmouse)
  956. *pdwRetVal |= 0x02;
  957. return S_OK;
  958. }
  959. ///////////////////////////////////////////////////////////
  960. //
  961. // Fire_Dialing
  962. //
  963. HRESULT CObCommunicationManager::Fire_Dialing(DWORD dwDialStatus)
  964. {
  965. VARIANTARG varg;
  966. VariantInit(&varg);
  967. varg.vt = VT_I4;
  968. varg.lVal= dwDialStatus;
  969. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  970. m_pDisp->Invoke(DISPID_DIALING, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  971. return S_OK ;
  972. }
  973. ///////////////////////////////////////////////////////////
  974. //
  975. // Fire_Connecting
  976. //
  977. HRESULT CObCommunicationManager::Fire_Connecting()
  978. {
  979. VARIANTARG varg;
  980. VariantInit(&varg);
  981. varg.vt = VT_I4;
  982. varg.lVal= 0;
  983. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  984. m_pDisp->Invoke(DISPID_CONNECTING, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  985. return S_OK ;
  986. }
  987. ///////////////////////////////////////////////////////////
  988. //
  989. // Fire_DialError
  990. //
  991. HRESULT CObCommunicationManager::Fire_DialError(DWORD dwErrorCode)
  992. {
  993. VARIANTARG varg;
  994. VariantInit(&varg);
  995. varg.vt = VT_I4;
  996. varg.lVal= dwErrorCode;
  997. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  998. m_pDisp->Invoke(DISPID_DIALINGERROR, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  999. return S_OK ;
  1000. }
  1001. ///////////////////////////////////////////////////////////
  1002. //
  1003. // Fire_ConnectionComplete
  1004. //
  1005. HRESULT CObCommunicationManager::Fire_ConnectionComplete()
  1006. {
  1007. VARIANTARG varg;
  1008. VariantInit(&varg);
  1009. varg.vt = VT_I4;
  1010. varg.lVal= 0;
  1011. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  1012. m_pDisp->Invoke(DISPIP_CONNECTIONCOMPLETE, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  1013. return S_OK ;
  1014. }
  1015. ///////////////////////////////////////////////////////////
  1016. //
  1017. // Fire_DownloadComplete
  1018. //
  1019. HRESULT CObCommunicationManager::Fire_DownloadComplete(BSTR pVal)
  1020. {
  1021. VARIANTARG varg;
  1022. VariantInit(&varg);
  1023. varg.vt = VT_BSTR;
  1024. varg.bstrVal= pVal;
  1025. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  1026. m_pDisp->Invoke(DISPIP_DOWNLOADCOMPLETE, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  1027. return S_OK ;
  1028. }
  1029. ///////////////////////////////////////////////////////////
  1030. //
  1031. // OnDownloadEvent
  1032. //
  1033. HRESULT CObCommunicationManager::OnDownloadEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled)
  1034. {
  1035. return m_pRefDial->OnDownloadEvent(uMsg, wParam, lParam, bHandled);
  1036. }
  1037. ///////////////////////////////////////////////////////////
  1038. //
  1039. // GetISPList
  1040. //
  1041. HRESULT CObCommunicationManager::GetISPList(BSTR* pVal)
  1042. {
  1043. return m_pRefDial->GetISPList(pVal);
  1044. }
  1045. ///////////////////////////////////////////////////////////
  1046. //
  1047. // GetISPList
  1048. //
  1049. HRESULT CObCommunicationManager::Set_SelectISP(UINT nVal)
  1050. {
  1051. return m_pRefDial->Set_SelectISP(nVal);
  1052. }
  1053. ///////////////////////////////////////////////////////////
  1054. //
  1055. // Set_ConnectionMode
  1056. //
  1057. HRESULT CObCommunicationManager::Set_ConnectionMode(UINT nVal)
  1058. {
  1059. return m_pRefDial->Set_ConnectionMode(nVal);
  1060. }
  1061. ///////////////////////////////////////////////////////////
  1062. //
  1063. // Get_ConnectionMode
  1064. //
  1065. HRESULT CObCommunicationManager::Get_ConnectionMode(UINT* pnVal)
  1066. {
  1067. return m_pRefDial->Get_ConnectionMode(pnVal);
  1068. }
  1069. ///////////////////////////////////////////////////////////
  1070. //
  1071. // DownloadReferralOffer
  1072. //
  1073. HRESULT CObCommunicationManager::DownloadReferralOffer(BOOL *pbVal)
  1074. {
  1075. if (pbVal)
  1076. {
  1077. // Start the download now!!!
  1078. m_pRefDial->DoOfferDownload(pbVal);
  1079. if (!*pbVal)
  1080. m_pRefDial->DoHangup();
  1081. return S_OK;
  1082. }
  1083. return E_FAIL;
  1084. }
  1085. ///////////////////////////////////////////////////////////
  1086. //
  1087. // DownloadISPOffer
  1088. //
  1089. HRESULT CObCommunicationManager::DownloadISPOffer(BOOL *pbVal, BSTR *pVal)
  1090. {
  1091. if (pbVal && pVal)
  1092. {
  1093. // Start the download now!!!
  1094. m_pRefDial->DownloadISPOffer(pbVal, pVal);
  1095. if (!*pbVal)
  1096. m_pRefDial->DoHangup();
  1097. return S_OK;
  1098. }
  1099. return E_FAIL;
  1100. }
  1101. ///////////////////////////////////////////////////////////
  1102. //
  1103. // Get_ISPName
  1104. //
  1105. HRESULT CObCommunicationManager::Get_ISPName(BSTR *pVal)
  1106. {
  1107. if (pVal)
  1108. {
  1109. // Start the download now!!!
  1110. return m_pRefDial->get_ISPName(pVal);
  1111. }
  1112. return E_FAIL;
  1113. }
  1114. ///////////////////////////////////////////////////////////
  1115. //
  1116. // RemoveDownloadDir
  1117. //
  1118. HRESULT CObCommunicationManager::RemoveDownloadDir()
  1119. {
  1120. return m_pRefDial->RemoveDownloadDir();
  1121. }
  1122. ///////////////////////////////////////////////////////////
  1123. //
  1124. // PostRegData
  1125. //
  1126. HRESULT CObCommunicationManager::PostRegData(DWORD dwSrvType, BSTR bstrRegUrl)
  1127. {
  1128. return m_pRefDial->PostRegData(dwSrvType, bstrRegUrl);
  1129. }
  1130. ///////////////////////////////////////////////////////////
  1131. //
  1132. // AllowSingleCall
  1133. //
  1134. HRESULT CObCommunicationManager::CheckStayConnected(BSTR bstrISPFile, BOOL *pbVal)
  1135. {
  1136. return m_pRefDial->CheckStayConnected(bstrISPFile, pbVal);
  1137. }
  1138. ///////////////////////////////////////////////////////////
  1139. //
  1140. // Connect
  1141. //
  1142. HRESULT CObCommunicationManager::Connect(UINT nType, BSTR bstrISPFile, DWORD dwCountry, BSTR bstrAreaCode, DWORD dwFlag, DWORD dwAppMode)
  1143. {
  1144. if (m_pRefDial)
  1145. {
  1146. return m_pRefDial->Connect(nType, bstrISPFile, dwCountry, bstrAreaCode, dwFlag, dwAppMode);
  1147. }
  1148. return E_FAIL ;
  1149. }
  1150. ///////////////////////////////////////////////////////////
  1151. //
  1152. // CheckStayConnected
  1153. //
  1154. HRESULT CObCommunicationManager::CheckOnlineStatus(BOOL *pbVal)
  1155. {
  1156. if (pbVal)
  1157. {
  1158. BOOL bIcs = FALSE;
  1159. BOOL bModem = FALSE;
  1160. IsIcsAvailable (&bIcs); // we don't care about the return value here
  1161. m_pRefDial->CheckOnlineStatus(&bModem);
  1162. *pbVal = (bIcs || bModem); // we are online if we have ICS or if the modem is connected.
  1163. return S_OK;
  1164. }
  1165. return E_FAIL;
  1166. }
  1167. HRESULT CObCommunicationManager::CreateIcsBot(DWORD *pdwRetVal)
  1168. {
  1169. if (!m_IcsMgr) {
  1170. if (!(m_IcsMgr = new CIcsMgr())) {
  1171. return ERROR_NOT_ENOUGH_MEMORY;
  1172. }
  1173. }
  1174. if (!pdwRetVal) {
  1175. return ERROR_INVALID_PARAMETER;
  1176. }
  1177. *pdwRetVal = m_IcsMgr->CreateIcsDialMgr();
  1178. return ERROR_SUCCESS;
  1179. }
  1180. HRESULT CObCommunicationManager::IsIcsAvailable(BOOL *bRetVal)
  1181. {
  1182. if (!bRetVal) {
  1183. return ERROR_INVALID_PARAMETER;
  1184. }
  1185. if (!m_IcsMgr) {
  1186. *bRetVal = FALSE;
  1187. } else {
  1188. *bRetVal = m_IcsMgr->IsIcsAvailable();
  1189. }
  1190. return S_OK;
  1191. }
  1192. HRESULT CObCommunicationManager::IsCallbackUsed(BOOL *bRetVal)
  1193. {
  1194. if (!bRetVal) {
  1195. return E_FAIL;
  1196. }
  1197. if (!m_IcsMgr) {
  1198. *bRetVal = FALSE;
  1199. } else {
  1200. *bRetVal = m_IcsMgr->IsCallbackUsed();
  1201. }
  1202. return S_OK;
  1203. }
  1204. HRESULT CObCommunicationManager::NotifyIcsMgr(UINT msg, WPARAM wParam, LPARAM lParam)
  1205. {
  1206. if ( !m_IcsMgr )
  1207. return E_FAIL;
  1208. else
  1209. m_IcsMgr->NotifyIcsMgr(msg, wParam, lParam);
  1210. return S_OK;
  1211. }
  1212. HRESULT CObCommunicationManager::NotifyIcsUsage(BOOL bParam)
  1213. {
  1214. m_bIsIcsUsed = bParam;
  1215. return S_OK;
  1216. }
  1217. HRESULT CObCommunicationManager::TriggerIcsCallback(BOOL bParam)
  1218. {
  1219. if (!m_IcsMgr)
  1220. {
  1221. return E_FAIL;
  1222. }
  1223. else
  1224. {
  1225. // The Dial Manager is initialized only once, even if
  1226. // TriggerIcsCallback is called several times.
  1227. // m_IcsMgr->CreateIcsDialMgr();
  1228. m_IcsMgr->TriggerIcsCallback(bParam);
  1229. return S_OK;
  1230. }
  1231. }
  1232. HRESULT CObCommunicationManager::IsIcsHostReachable(BOOL *bRetVal)
  1233. {
  1234. if (!bRetVal) {
  1235. return E_FAIL;
  1236. }
  1237. if (!m_IcsMgr) {
  1238. *bRetVal = FALSE;
  1239. } else {
  1240. *bRetVal = m_IcsMgr->IsIcsHostReachable();
  1241. }
  1242. return S_OK;
  1243. }
  1244. ///////////////////////////////////////////////////////////
  1245. //
  1246. // CreateModemConnectoid
  1247. //
  1248. STDMETHODIMP CObCommunicationManager::CreateModemConnectoid(
  1249. BSTR bstrPhoneBook,
  1250. BSTR bstrConnectionName,
  1251. DWORD dwCountryID,
  1252. DWORD dwCountryCode,
  1253. BSTR bstrAreaCode,
  1254. BSTR bstrPhoneNumber,
  1255. BOOL fAutoIPAddress,
  1256. DWORD ipaddr_A,
  1257. DWORD ipaddr_B,
  1258. DWORD ipaddr_C,
  1259. DWORD ipaddr_D,
  1260. BOOL fAutoDNS,
  1261. DWORD ipaddrDns_A,
  1262. DWORD ipaddrDns_B,
  1263. DWORD ipaddrDns_C,
  1264. DWORD ipaddrDns_D,
  1265. DWORD ipaddrDnsAlt_A,
  1266. DWORD ipaddrDnsAlt_B,
  1267. DWORD ipaddrDnsAlt_C,
  1268. DWORD ipaddrDnsAlt_D,
  1269. BSTR bstrUserName,
  1270. BSTR bstrPassword)
  1271. {
  1272. DWORD dwRet = ERROR_SUCCESS;
  1273. dwRet = m_EnumModem.ReInit();
  1274. if (ERROR_SUCCESS != dwRet)
  1275. {
  1276. return dwRet;
  1277. }
  1278. LPWSTR szDeviceName = m_EnumModem.GetDeviceNameFromType(RASDT_Modem);
  1279. if (NULL == szDeviceName)
  1280. {
  1281. return ERROR_DEVICE_DOES_NOT_EXIST;
  1282. }
  1283. BSTR bstrDeviceName = SysAllocString(szDeviceName);
  1284. BSTR bstrDeviceType = SysAllocString(RASDT_Modem);
  1285. if (NULL == bstrDeviceName || NULL == bstrDeviceType)
  1286. {
  1287. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  1288. }
  1289. else
  1290. {
  1291. DWORD dwEntryOptions = RASEO_UseCountryAndAreaCodes
  1292. | RASEO_IpHeaderCompression
  1293. | RASEO_RemoteDefaultGateway
  1294. | RASEO_SwCompression
  1295. | RASEO_ShowDialingProgress
  1296. | RASEO_ModemLights;
  1297. dwRet = CreateConnectoid(bstrPhoneBook,
  1298. bstrConnectionName,
  1299. dwCountryID,
  1300. dwCountryCode,
  1301. bstrAreaCode,
  1302. bstrPhoneNumber,
  1303. fAutoIPAddress,
  1304. ipaddr_A,
  1305. ipaddr_B,
  1306. ipaddr_C,
  1307. ipaddr_D,
  1308. fAutoDNS,
  1309. ipaddrDns_A,
  1310. ipaddrDns_B,
  1311. ipaddrDns_C,
  1312. ipaddrDns_D,
  1313. ipaddrDnsAlt_A,
  1314. ipaddrDnsAlt_B,
  1315. ipaddrDnsAlt_C,
  1316. ipaddrDnsAlt_D,
  1317. bstrUserName,
  1318. bstrPassword,
  1319. bstrDeviceName,
  1320. bstrDeviceType,
  1321. dwEntryOptions,
  1322. RASET_Phone
  1323. );
  1324. }
  1325. if (bstrDeviceName) SysFreeString(bstrDeviceName);
  1326. if (bstrDeviceType) SysFreeString(bstrDeviceType);
  1327. // BUGBUG: Mixing HRESULT and WIN32 error code
  1328. return dwRet;
  1329. }
  1330. ///////////////////////////////////////////////////////////
  1331. //
  1332. // CreatePppoeConnectoid
  1333. //
  1334. STDMETHODIMP CObCommunicationManager::CreatePppoeConnectoid(
  1335. BSTR bstrPhoneBook,
  1336. BSTR bstrConnectionName,
  1337. BSTR bstrBroadbandService,
  1338. BOOL fAutoIPAddress,
  1339. DWORD ipaddr_A,
  1340. DWORD ipaddr_B,
  1341. DWORD ipaddr_C,
  1342. DWORD ipaddr_D,
  1343. BOOL fAutoDNS,
  1344. DWORD ipaddrDns_A,
  1345. DWORD ipaddrDns_B,
  1346. DWORD ipaddrDns_C,
  1347. DWORD ipaddrDns_D,
  1348. DWORD ipaddrDnsAlt_A,
  1349. DWORD ipaddrDnsAlt_B,
  1350. DWORD ipaddrDnsAlt_C,
  1351. DWORD ipaddrDnsAlt_D,
  1352. BSTR bstrUserName,
  1353. BSTR bstrPassword)
  1354. {
  1355. DWORD dwRet = ERROR_SUCCESS;
  1356. dwRet = m_EnumModem.ReInit();
  1357. if (ERROR_SUCCESS != dwRet)
  1358. {
  1359. return dwRet;
  1360. }
  1361. LPWSTR szDeviceName = m_EnumModem.GetDeviceNameFromType(RASDT_PPPoE);
  1362. if (NULL == szDeviceName)
  1363. {
  1364. return ERROR_DEVICE_DOES_NOT_EXIST;
  1365. }
  1366. BSTR bstrDeviceName = SysAllocString(szDeviceName);
  1367. BSTR bstrDeviceType = SysAllocString(RASDT_PPPoE);
  1368. if (NULL == bstrDeviceName || NULL == bstrDeviceType)
  1369. {
  1370. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  1371. }
  1372. else
  1373. {
  1374. DWORD dwEntryOptions = RASEO_IpHeaderCompression
  1375. | RASEO_RemoteDefaultGateway
  1376. | RASEO_SwCompression
  1377. | RASEO_ShowDialingProgress
  1378. | RASEO_ModemLights;
  1379. // Note that bstrBroadbandService is passed as the bstrPhoneNumber param to
  1380. // CreateConnectoid. This is correct per PMay. bstrBroadbandService may
  1381. // contain the name of a broadband service or may be an empty string.
  1382. //
  1383. dwRet = CreateConnectoid(bstrPhoneBook,
  1384. bstrConnectionName,
  1385. 0, // dwCountryID unused
  1386. 0, // dwCountryCode unused
  1387. NULL, // area code
  1388. bstrBroadbandService,
  1389. fAutoIPAddress,
  1390. ipaddr_A,
  1391. ipaddr_B,
  1392. ipaddr_C,
  1393. ipaddr_D,
  1394. fAutoDNS,
  1395. ipaddrDns_A,
  1396. ipaddrDns_B,
  1397. ipaddrDns_C,
  1398. ipaddrDns_D,
  1399. ipaddrDnsAlt_A,
  1400. ipaddrDnsAlt_B,
  1401. ipaddrDnsAlt_C,
  1402. ipaddrDnsAlt_D,
  1403. bstrUserName,
  1404. bstrPassword,
  1405. bstrDeviceName,
  1406. bstrDeviceType,
  1407. dwEntryOptions,
  1408. RASET_Broadband
  1409. );
  1410. }
  1411. if (bstrDeviceName) SysFreeString(bstrDeviceName);
  1412. if (bstrDeviceType) SysFreeString(bstrDeviceType);
  1413. // BUGBUG: Mixing HRESULT and WIN32 error code
  1414. return dwRet;
  1415. }
  1416. ///////////////////////////////////////////////////////////
  1417. //
  1418. // CreateConnectoid
  1419. //
  1420. STDMETHODIMP CObCommunicationManager::CreateConnectoid(
  1421. BSTR bstrPhoneBook,
  1422. BSTR bstrConnectionName,
  1423. DWORD dwCountryID,
  1424. DWORD dwCountryCode,
  1425. BSTR bstrAreaCode,
  1426. BSTR bstrPhoneNumber,
  1427. BOOL fAutoIPAddress,
  1428. DWORD ipaddr_A,
  1429. DWORD ipaddr_B,
  1430. DWORD ipaddr_C,
  1431. DWORD ipaddr_D,
  1432. BOOL fAutoDNS,
  1433. DWORD ipaddrDns_A,
  1434. DWORD ipaddrDns_B,
  1435. DWORD ipaddrDns_C,
  1436. DWORD ipaddrDns_D,
  1437. DWORD ipaddrDnsAlt_A,
  1438. DWORD ipaddrDnsAlt_B,
  1439. DWORD ipaddrDnsAlt_C,
  1440. DWORD ipaddrDnsAlt_D,
  1441. BSTR bstrUserName,
  1442. BSTR bstrPassword,
  1443. BSTR bstrDeviceName,
  1444. BSTR bstrDeviceType,
  1445. DWORD dwEntryOptions,
  1446. DWORD dwEntryType)
  1447. {
  1448. RNAAPI rnaapi;
  1449. HRESULT hr;
  1450. RASENTRY rasentry;
  1451. WCHAR wsz[MAX_ISP_NAME + 1];
  1452. // Set up the RASENTRY
  1453. memset(&rasentry, 0, sizeof(RASENTRY));
  1454. rasentry.dwSize = sizeof(RASENTRY);
  1455. rasentry.dwfOptions = dwEntryOptions;
  1456. //
  1457. // Location/phone number.
  1458. //
  1459. rasentry.dwCountryID = dwCountryID;
  1460. rasentry.dwCountryCode = dwCountryCode;
  1461. TRACE2(L"Connectoid %d %d", dwCountryID, dwCountryCode);
  1462. // bstrAreaCode will be NULL when creating a PPPOE connectoid
  1463. //
  1464. if (NULL != bstrAreaCode)
  1465. {
  1466. lstrcpyn(rasentry.szAreaCode, bstrAreaCode, RAS_MaxAreaCode + 1);
  1467. TRACE1(L"Connectoid AreaCode %s", rasentry.szAreaCode);
  1468. }
  1469. // bstrPhoneNumber should contain either a phone number or a broadband
  1470. // service name.
  1471. //
  1472. MYASSERT(NULL != bstrPhoneNumber);
  1473. if (NULL != bstrPhoneNumber)
  1474. {
  1475. lstrcpyn(rasentry.szLocalPhoneNumber,
  1476. bstrPhoneNumber,
  1477. RAS_MaxPhoneNumber + 1
  1478. );
  1479. TRACE1(L"Connectoid LocalPhoneNumber %s", rasentry.szLocalPhoneNumber);
  1480. }
  1481. // dwAlternateOffset; No alternate numbers
  1482. //
  1483. // PPP/Ip
  1484. //
  1485. if (!fAutoIPAddress)
  1486. {
  1487. rasentry.dwfOptions |= RASEO_SpecificIpAddr;
  1488. rasentry.ipaddr.a = (BYTE)ipaddr_A;
  1489. rasentry.ipaddr.b = (BYTE)ipaddr_B;
  1490. rasentry.ipaddr.c = (BYTE)ipaddr_C;
  1491. rasentry.ipaddr.d = (BYTE)ipaddr_D;
  1492. TRACE4(L"Connectoid ipaddr %d.%d.%d.%d",
  1493. ipaddr_A, ipaddr_B, ipaddr_C, ipaddr_D);
  1494. }
  1495. if (!fAutoDNS)
  1496. {
  1497. rasentry.dwfOptions |= RASEO_SpecificNameServers;
  1498. rasentry.ipaddrDns.a = (BYTE)ipaddrDns_A;
  1499. rasentry.ipaddrDns.b = (BYTE)ipaddrDns_B;
  1500. rasentry.ipaddrDns.c = (BYTE)ipaddrDns_C;
  1501. rasentry.ipaddrDns.d = (BYTE)ipaddrDns_D;
  1502. TRACE4(L"Connectoid ipaddrDns %d.%d.%d.%d",
  1503. ipaddrDns_A, ipaddrDns_B, ipaddrDns_C, ipaddrDns_D);
  1504. rasentry.ipaddrDnsAlt.a = (BYTE)ipaddrDnsAlt_A;
  1505. rasentry.ipaddrDnsAlt.b = (BYTE)ipaddrDnsAlt_B;
  1506. rasentry.ipaddrDnsAlt.c = (BYTE)ipaddrDnsAlt_C;
  1507. rasentry.ipaddrDnsAlt.d = (BYTE)ipaddrDnsAlt_D;
  1508. TRACE4(L"Connectoid ipaddrDnsAlt %d.%d.%d.%d",
  1509. ipaddrDnsAlt_A, ipaddrDnsAlt_B, ipaddrDnsAlt_C, ipaddrDnsAlt_D);
  1510. // RASIPADDR ipaddrWins;
  1511. // RASIPADDR ipaddrWinsAlt;
  1512. }
  1513. //
  1514. // Framing
  1515. //
  1516. // dwFrameSize; Ignored unless framing is RASFP_Slip
  1517. rasentry.dwfNetProtocols = RASNP_Ip;
  1518. rasentry.dwFramingProtocol = RASFP_Ppp;
  1519. //
  1520. // Scripting
  1521. //
  1522. // szScript[ MAX_PATH ];
  1523. //
  1524. // AutoDial - Use the default dialer
  1525. //
  1526. // szAutodialDll[ MAX_PATH ];
  1527. // szAutodialFunc[ MAX_PATH ];
  1528. //
  1529. // Device
  1530. //
  1531. if (NULL != bstrDeviceType)
  1532. {
  1533. lstrcpyn(rasentry.szDeviceType, bstrDeviceType, RAS_MaxDeviceType + 1);
  1534. TRACE1(L"Connectoid DeviceType %s", rasentry.szDeviceType);
  1535. }
  1536. if (NULL != bstrDeviceName)
  1537. {
  1538. lstrcpyn(rasentry.szDeviceName, bstrDeviceName, RAS_MaxDeviceName + 1);
  1539. TRACE1(L"Connectoid DeviceName %s", rasentry.szDeviceName);
  1540. }
  1541. //
  1542. // X.25 - not using an X.25 device
  1543. //
  1544. // szX25PadType[ RAS_MaxPadType + 1 ];
  1545. // szX25Address[ RAS_MaxX25Address + 1 ];
  1546. // szX25Facilities[ RAS_MaxFacilities + 1 ];
  1547. // szX25UserData[ RAS_MaxUserData + 1 ];
  1548. // dwChannels;
  1549. //
  1550. // Reserved
  1551. //
  1552. // dwReserved1;
  1553. // dwReserved2;
  1554. //
  1555. // Multilink and BAP
  1556. //
  1557. // dwSubEntries;
  1558. // dwDialMode;
  1559. // dwDialExtraPercent;
  1560. // dwDialExtraSampleSeconds;
  1561. // dwHangUpExtraPercent;
  1562. // dwHangUpExtraSampleSeconds;
  1563. //
  1564. // Idle time out
  1565. //
  1566. // dwIdleDisconnectSeconds;
  1567. //
  1568. rasentry.dwType = dwEntryType;
  1569. // dwEncryptionType; // type of encryption to use
  1570. // dwCustomAuthKey; // authentication key for EAP
  1571. // guidId; // guid that represents
  1572. // the phone-book entry
  1573. // szCustomDialDll[MAX_PATH]; // DLL for custom dialing
  1574. // dwVpnStrategy; // specifies type of VPN protocol
  1575. TRACE5(L"Connectoid %d %d %d %d %d",
  1576. rasentry.dwSize, rasentry.dwfOptions, rasentry.dwfNetProtocols,
  1577. rasentry.dwFramingProtocol, rasentry.dwType);
  1578. // Now pass all parameters to RAS
  1579. hr = RasSetEntryProperties(bstrPhoneBook,
  1580. bstrConnectionName,
  1581. &rasentry,
  1582. sizeof(RASENTRY),
  1583. NULL,
  1584. 0
  1585. );
  1586. if (ERROR_SUCCESS == hr)
  1587. {
  1588. HRESULT hr2;
  1589. RASCREDENTIALS rascred;
  1590. ZeroMemory(&rascred, sizeof(rascred));
  1591. rascred.dwSize = sizeof(rascred);
  1592. rascred.dwMask = RASCM_UserName
  1593. | RASCM_Password
  1594. | RASCM_Domain
  1595. | RASCM_DefaultCreds;
  1596. if (bstrUserName != NULL)
  1597. {
  1598. lstrcpyn(rascred.szUserName, bstrUserName,UNLEN);
  1599. }
  1600. else
  1601. {
  1602. lstrcpyn(rascred.szUserName, L"", UNLEN);
  1603. }
  1604. if (bstrPassword != NULL)
  1605. {
  1606. lstrcpyn(rascred.szPassword, bstrPassword,PWLEN);
  1607. }
  1608. else
  1609. {
  1610. lstrcpyn(rascred.szPassword, L"", PWLEN);
  1611. }
  1612. lstrcpyn(rascred.szDomain, L"",DNLEN);
  1613. hr2 = RasSetCredentials(bstrPhoneBook,
  1614. bstrConnectionName,
  1615. &rascred,
  1616. FALSE);
  1617. TRACE1(L"Connectoid SetCredentials 0x%08lx", hr2);
  1618. SetDefaultConnectoid(AutodialTypeNoNet, bstrConnectionName);
  1619. // Save the connectoid name so it can be firewalled by the HomeNet
  1620. // Wizard.
  1621. //
  1622. lstrcpy(m_szExternalConnectoid, bstrConnectionName);
  1623. }
  1624. TRACE1(L"CreateConnectoid %d\n", hr);
  1625. return hr;
  1626. }
  1627. //////////////////////////////////////////////////////////////////////////////
  1628. //
  1629. // DoFinalTasks
  1630. //
  1631. // This method is called during OOBE's Finish code. Complete any final tasks
  1632. // (ie, run the HomeNet Wizard) here.
  1633. //
  1634. // parameters:
  1635. // pfRebootRequired pointer to a buffer that receives a boolean
  1636. // indicating whether a reboot is required before
  1637. // something done here will take affect.
  1638. //
  1639. // returns:
  1640. // HRESULT returned by CHomeNet::ConfigureSilently
  1641. //
  1642. //////////////////////////////////////////////////////////////////////////////
  1643. STDMETHODIMP CObCommunicationManager::DoFinalTasks(
  1644. BOOL* pfRebootRequired
  1645. )
  1646. {
  1647. HRESULT hr = S_OK;
  1648. BOOL fRebootRequired = FALSE;
  1649. LPCWSTR szConnectoidName = (0 < lstrlen(m_szExternalConnectoid)
  1650. ? m_szExternalConnectoid
  1651. : NULL);
  1652. if (szConnectoidName)
  1653. {
  1654. // Run the HomeNet Wizard sans UI. m_szExternalConnectoid is the name of
  1655. // the connectoid that will be firewalled.
  1656. //
  1657. CHomeNet HomeNet;
  1658. HomeNet.Create();
  1659. // Run the HomeNet Wizard sans UI. m_szExternalConnectoid is the name of
  1660. // the connectoid that will be firewalled.
  1661. //
  1662. hr = HomeNet.ConfigureSilently(szConnectoidName,
  1663. &fRebootRequired);
  1664. if (FAILED(hr))
  1665. {
  1666. TRACE2(L"Failed: IHomeNetWizard::ConfigureSilently(%s): (0x%08X)",
  1667. m_szExternalConnectoid, hr
  1668. );
  1669. fRebootRequired = FALSE;
  1670. }
  1671. else
  1672. {
  1673. TRACE1(L"Connection %s Firewalled", szConnectoidName);
  1674. }
  1675. }
  1676. else if (m_bFirewall)
  1677. {
  1678. PSTRINGLIST List = NULL;
  1679. m_ConnectionManager.EnumPublicConnections(&List);
  1680. if (List)
  1681. {
  1682. CHomeNet HomeNet;
  1683. if (SUCCEEDED(HomeNet.Create()))
  1684. {
  1685. for (PSTRINGLIST p = List; p; p = p->Next)
  1686. {
  1687. BOOL bRet = FALSE;
  1688. hr = HomeNet.ConfigureSilently(p->String, &bRet);
  1689. if (SUCCEEDED(hr))
  1690. {
  1691. TRACE1(L"Connection %s Firewalled", p->String);
  1692. if (bRet)
  1693. {
  1694. fRebootRequired = TRUE;
  1695. }
  1696. }
  1697. else
  1698. {
  1699. TRACE2(
  1700. L"Failed: IHomeNetWizard::ConfigureSilently(%s): (0x%08X)",
  1701. p->String,
  1702. hr
  1703. );
  1704. }
  1705. }
  1706. }
  1707. else
  1708. {
  1709. TRACE1(L"Failed: IHomeNetWizard CoCreateInstance: (0x%08lx)", hr);
  1710. }
  1711. DestroyList(List);
  1712. }
  1713. }
  1714. if (NULL != pfRebootRequired)
  1715. {
  1716. *pfRebootRequired = fRebootRequired;
  1717. }
  1718. return hr;
  1719. } // CObCommunicationManager::DoFinalTasks
  1720. //////////////////////////////////////////////////////////////////////////////
  1721. //
  1722. // OobeAutodial
  1723. //
  1724. // This method invokes IE's autodial as a modal dialog.
  1725. //
  1726. // If a connection is established, it will be disconnected when
  1727. // OobeAutodialHangup is called or in this class's destructor.
  1728. //
  1729. // Precondition:
  1730. // no internet connectivity is available.
  1731. //
  1732. // returns:
  1733. // S_OK - connection established
  1734. // S_FALSE - no error. Autodial cancelled and no connection established
  1735. // HRESULT error code - error occured.
  1736. //
  1737. //////////////////////////////////////////////////////////////////////////////
  1738. HRESULT CObCommunicationManager::OobeAutodial()
  1739. {
  1740. HRESULT hr = S_OK;
  1741. BOOL bRet = FALSE;
  1742. if (!InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE, m_hwndCallBack))
  1743. {
  1744. hr = HRESULT_FROM_WIN32(GetLastError());
  1745. goto cleanup;
  1746. }
  1747. hr = ConnectedToInternetEx(&bRet);
  1748. if (FAILED(hr))
  1749. {
  1750. goto cleanup;
  1751. }
  1752. if (bRet)
  1753. {
  1754. hr = S_OK;
  1755. m_bAutodialCleanup = true;
  1756. }
  1757. else
  1758. {
  1759. hr = S_FALSE;
  1760. }
  1761. cleanup:
  1762. return hr;
  1763. }
  1764. //////////////////////////////////////////////////////////////////////////////
  1765. //
  1766. // OobeAutodialHangup
  1767. //
  1768. // This method disconnects the autodial connection, if there is one, created
  1769. // by OobeAutodial
  1770. //
  1771. // returns:
  1772. // S_OK - no connection is created by OobeAutodial or hangup succeeded
  1773. // HRESULT error code - error occured.
  1774. //
  1775. //////////////////////////////////////////////////////////////////////////////
  1776. HRESULT CObCommunicationManager::OobeAutodialHangup()
  1777. {
  1778. HRESULT hr = S_OK;
  1779. if (m_bAutodialCleanup)
  1780. {
  1781. if (!InternetAutodialHangup(0))
  1782. {
  1783. hr = HRESULT_FROM_WIN32(GetLastError());
  1784. }
  1785. m_bAutodialCleanup = FALSE;
  1786. }
  1787. return hr;
  1788. }
  1789. HRESULT CObCommunicationManager::UseWinntProxySettings()
  1790. {
  1791. m_ConnectionManager.UseWinntProxySettings();
  1792. return S_OK;
  1793. }
  1794. HRESULT CObCommunicationManager::DisableWinntProxySettings()
  1795. {
  1796. m_ConnectionManager.DisableWinntProxySettings();
  1797. return S_OK;
  1798. }
  1799. HRESULT CObCommunicationManager::GetProxySettings(
  1800. BOOL* pbUseAuto,
  1801. BOOL* pbUseScript,
  1802. BSTR* pszScriptUrl,
  1803. BOOL* pbUseProxy,
  1804. BSTR* pszProxy
  1805. )
  1806. {
  1807. return m_ConnectionManager.GetProxySettings(
  1808. pbUseAuto,
  1809. pbUseScript,
  1810. pszScriptUrl,
  1811. pbUseProxy,
  1812. pszProxy
  1813. );
  1814. }
  1815. HRESULT CObCommunicationManager::SetProxySettings(
  1816. BOOL bUseAuto,
  1817. BOOL bUseScript,
  1818. BSTR szScriptUrl,
  1819. BOOL bUseProxy,
  1820. BSTR szProxy
  1821. )
  1822. {
  1823. return m_ConnectionManager.SetProxySettings(
  1824. bUseAuto,
  1825. bUseScript,
  1826. szScriptUrl,
  1827. bUseProxy,
  1828. szProxy
  1829. );
  1830. }
  1831. BSTR CObCommunicationManager::GetPreferredModem()
  1832. {
  1833. BSTR bstrVal = NULL;
  1834. // Assume CObCommunicationManager::CheckDialReady has been called
  1835. //
  1836. LPWSTR szDeviceName = m_EnumModem.GetDeviceNameFromType(RASDT_Isdn);
  1837. if (szDeviceName == NULL)
  1838. {
  1839. szDeviceName = m_EnumModem.GetDeviceNameFromType(RASDT_Modem);
  1840. }
  1841. if (szDeviceName != NULL)
  1842. {
  1843. bstrVal = SysAllocString(szDeviceName);
  1844. }
  1845. return bstrVal;
  1846. }
  1847. HRESULT CObCommunicationManager::SetICWCompleted(
  1848. BOOL bMultiUser
  1849. )
  1850. {
  1851. BOOL bRet;
  1852. if (bMultiUser)
  1853. {
  1854. bRet = SetMultiUserAutodial(AutodialTypeNever, NULL, TRUE);
  1855. }
  1856. else
  1857. {
  1858. bRet = SetAutodial(HKEY_CURRENT_USER, AutodialTypeNever, NULL, TRUE);
  1859. }
  1860. return (bRet) ? S_OK : E_FAIL;
  1861. }
  1862. //////////////////////////////////////////////////////////////////////////////
  1863. //
  1864. // GetPublicLanCount
  1865. //
  1866. // Forward the work to CConnectionManager::GetPublicLanCount
  1867. //
  1868. //////////////////////////////////////////////////////////////////////////////
  1869. HRESULT
  1870. CObCommunicationManager::GetPublicLanCount(
  1871. int* pcPublicLan
  1872. )
  1873. {
  1874. return m_ConnectionManager.GetPublicLanCount(pcPublicLan);
  1875. } // CObCommunicationManager::GetPublicLanCount
  1876. //////////////////////////////////////////////////////////////////////////////
  1877. //
  1878. // SetExclude1394
  1879. //
  1880. // Forward the work to CConnectionManager::SetExclude1394
  1881. //
  1882. //////////////////////////////////////////////////////////////////////////////
  1883. HRESULT
  1884. CObCommunicationManager::SetExclude1394(
  1885. BOOL bExclude
  1886. )
  1887. {
  1888. m_ConnectionManager.SetExclude1394(bExclude);
  1889. return S_OK;
  1890. } // CObCommunicationManager::SetExclude1394
  1891. //////////////////////////////////////////////////////////////////////////////
  1892. //
  1893. // GnsAutodial
  1894. //
  1895. // Forward the work to CRefDial::SetupForAutoDial
  1896. //
  1897. //////////////////////////////////////////////////////////////////////////////
  1898. HRESULT
  1899. CObCommunicationManager::GnsAutodial(
  1900. BOOL bEnabled,
  1901. BSTR bstrUserSection
  1902. )
  1903. {
  1904. HRESULT hr = S_OK;
  1905. if (m_pRefDial)
  1906. {
  1907. hr = m_pRefDial->SetupForAutoDial(bEnabled, bstrUserSection);
  1908. }
  1909. return hr;
  1910. } // CObCommunicationManager::GnsAutodial