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.

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