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.

3922 lines
120 KiB

  1. // RefDial.cpp : Implementation of CRefDial
  2. //#include "stdafx.h"
  3. //#include "icwhelp.h"
  4. #include <urlmon.h>
  5. #include "commerr.h"
  6. #include "RefDial.h"
  7. #include "msobcomm.h"
  8. #include "appdefs.h"
  9. #include "commerr.h"
  10. #include "util.h"
  11. #include "msobdl.h"
  12. //#include <mshtmhst.h>
  13. const WCHAR c_szCreditsMagicNum[] = L"1 425 555 1212";
  14. const WCHAR c_szRegStrValDigitalPID[] = L"DigitalProductId";
  15. const WCHAR c_szSignedPIDFName[] = L"signed.pid";
  16. const WCHAR c_szRASProfiles[] = L"RemoteAccess\\Profile";
  17. const WCHAR c_szProxyEnable[] = L"ProxyEnable";
  18. const WCHAR c_szURLReferral[] = L"URLReferral";
  19. const WCHAR c_szRegPostURL[] = L"RegPostURL";
  20. const WCHAR c_szStayConnected[] = L"Stayconnected";
  21. static const WCHAR szOptionTag[] = L"<OPTION>%s";
  22. WCHAR g_BINTOHEXLookup[16] =
  23. {
  24. L'0',L'1',L'2',L'3',L'4',L'5',L'6',L'7',
  25. L'8',L'9',L'A',L'B',L'C',L'D',L'E',L'F'
  26. };
  27. extern CObCommunicationManager* gpCommMgr;
  28. extern BOOL isAlnum(WCHAR c);
  29. // ############################################################################
  30. HRESULT Sz2URLValue(WCHAR *s, WCHAR *buf, UINT uiLen)
  31. {
  32. HRESULT hr;
  33. WCHAR *t;
  34. hr = ERROR_SUCCESS;
  35. for (t=buf;*s; s++)
  36. {
  37. if (*s == L' ') *t++ = L'+';
  38. else if (isAlnum(*s)) *t++ = *s;
  39. else {
  40. wsprintf(t, L"%%%02X", (WCHAR) *s);
  41. t += 3;
  42. }
  43. }
  44. *t = L'\0';
  45. return hr;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: LineCallback()
  50. //
  51. // Synopsis: Call back for TAPI line
  52. //
  53. //+---------------------------------------------------------------------------
  54. void CALLBACK LineCallback(DWORD hDevice,
  55. DWORD dwMessage,
  56. DWORD_PTR dwInstance,
  57. DWORD_PTR dwParam1,
  58. DWORD_PTR dwParam2,
  59. DWORD_PTR dwParam3)
  60. {
  61. return;
  62. }
  63. void WINAPI MyProgressCallBack
  64. (
  65. HINTERNET hInternet,
  66. DWORD_PTR dwContext,
  67. DWORD dwInternetStatus,
  68. LPVOID lpvStatusInformation,
  69. DWORD dwStatusInformationLength
  70. )
  71. {
  72. CRefDial *pRefDial = (CRefDial *)dwContext;
  73. int prc;
  74. if (!dwContext)
  75. return;
  76. switch(dwInternetStatus)
  77. {
  78. case CALLBACK_TYPE_PROGRESS:
  79. prc = *(int*)lpvStatusInformation;
  80. // Set the status string ID
  81. pRefDial->m_DownloadStatusID = 0;//IDS_RECEIVING_RESPONSE;
  82. // Post a message to fire an event
  83. PostMessage(gpCommMgr->m_hwndCallBack,
  84. WM_OBCOMM_DOWNLOAD_PROGRESS,
  85. gpCommMgr->m_pRefDial->m_dwCnType,
  86. prc);
  87. break;
  88. case CALLBACK_TYPE_URL:
  89. if (lpvStatusInformation)
  90. lstrcpy(pRefDial->m_szRefServerURL, (LPWSTR)lpvStatusInformation);
  91. break;
  92. default:
  93. //TraceMsg(TF_GENERAL, L"CONNECT:Unknown Internet Status (%d.\n"), dwInternetStatus);
  94. pRefDial->m_DownloadStatusID = 0;
  95. break;
  96. }
  97. }
  98. DWORD WINAPI DownloadThreadInit(LPVOID lpv)
  99. {
  100. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  101. CRefDial *pRefDial = (CRefDial*)lpv;
  102. HINSTANCE hDLDLL = NULL; // Download .DLL
  103. FARPROC fp;
  104. //MinimizeRNAWindowEx();
  105. hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  106. if (!hDLDLL)
  107. {
  108. hr = ERROR_DOWNLOAD_NOT_FOUND;
  109. //AssertMsg(0, L"icwdl missing");
  110. goto ThreadInitExit;
  111. }
  112. // Set up for download
  113. //
  114. fp = GetProcAddress(hDLDLL, DOWNLOADINIT);
  115. if (fp == NULL)
  116. {
  117. hr = ERROR_DOWNLOAD_NOT_FOUND;
  118. //AssertMsg(0, L"DownLoadInit API missing");
  119. goto ThreadInitExit;
  120. }
  121. hr = ((PFNDOWNLOADINIT)fp)(pRefDial->m_szUrl, (DWORD FAR *)pRefDial, &pRefDial->m_dwDownLoad, gpCommMgr->m_hwndCallBack);
  122. if (hr != ERROR_SUCCESS)
  123. goto ThreadInitExit;
  124. // Set up call back for progress dialog
  125. //
  126. fp = GetProcAddress(hDLDLL, DOWNLOADSETSTATUS);
  127. //Assert(fp);
  128. hr = ((PFNDOWNLOADSETSTATUS)fp)(pRefDial->m_dwDownLoad, (INTERNET_STATUS_CALLBACK)MyProgressCallBack);
  129. // Download stuff MIME multipart
  130. //
  131. fp = GetProcAddress(hDLDLL, DOWNLOADEXECUTE);
  132. //Assert(fp);
  133. hr = ((PFNDOWNLOADEXECUTE)fp)(pRefDial->m_dwDownLoad);
  134. if (hr)
  135. {
  136. goto ThreadInitExit;
  137. }
  138. fp = GetProcAddress(hDLDLL, DOWNLOADPROCESS);
  139. //Assert(fp);
  140. hr = ((PFNDOWNLOADPROCESS)fp)(pRefDial->m_dwDownLoad);
  141. if (hr)
  142. {
  143. goto ThreadInitExit;
  144. }
  145. hr = ERROR_SUCCESS;
  146. ThreadInitExit:
  147. // Clean up
  148. //
  149. if (pRefDial->m_dwDownLoad)
  150. {
  151. fp = GetProcAddress(hDLDLL, DOWNLOADCLOSE);
  152. //Assert(fp);
  153. ((PFNDOWNLOADCLOSE)fp)(pRefDial->m_dwDownLoad);
  154. pRefDial->m_dwDownLoad = 0;
  155. }
  156. // Call the OnDownLoadCompelete method
  157. if (ERROR_SUCCESS == hr)
  158. {
  159. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_DOWNLOAD_DONE, gpCommMgr->m_pRefDial->m_dwCnType, 0);
  160. }
  161. // Free the libs used to do the download
  162. if (hDLDLL)
  163. FreeLibrary(hDLDLL);
  164. return hr;
  165. }
  166. //+---------------------------------------------------------------------------
  167. //
  168. // Function: RasErrorToIDS()
  169. //
  170. // Synopsis: Interpret and wrap RAS errors
  171. //
  172. //+---------------------------------------------------------------------------
  173. DWORD RasErrorToIDS(DWORD dwErr)
  174. {
  175. switch(dwErr)
  176. {
  177. case SUCCESS:
  178. return 0;
  179. case ERROR_LINE_BUSY:
  180. return ERR_COMM_RAS_PHONEBUSY;
  181. case ERROR_NO_ANSWER: // No pick up
  182. case ERROR_NO_CARRIER: // No negotiation
  183. case ERROR_PPP_TIMEOUT: // get this on CHAP timeout
  184. return ERR_COMM_RAS_SERVERBUSY;
  185. case ERROR_NO_DIALTONE:
  186. return ERR_COMM_RAS_NODIALTONE;
  187. case ERROR_HARDWARE_FAILURE: // modem turned off
  188. case ERROR_PORT_ALREADY_OPEN: // procomm/hypertrm/RAS has COM port
  189. case ERROR_PORT_OR_DEVICE: // got this when hypertrm had the device open -- jmazner
  190. return ERR_COMM_RAS_NOMODEM;
  191. }
  192. return ERR_COMM_RAS_UNKNOWN;
  193. }
  194. DWORD DoConnMonitor(LPVOID lpv)
  195. {
  196. if (gpCommMgr)
  197. gpCommMgr->m_pRefDial->ConnectionMonitorThread(NULL);
  198. return 1;
  199. }
  200. void CreateConnMonitorThread(LPVOID lpv)
  201. {
  202. DWORD dwThreadID;
  203. if (gpCommMgr->m_pRefDial->m_hConnMonThread)
  204. gpCommMgr->m_pRefDial->TerminateConnMonitorThread();
  205. gpCommMgr->m_pRefDial->m_hConnMonThread = CreateThread(NULL,
  206. 0,
  207. (LPTHREAD_START_ROUTINE)DoConnMonitor,
  208. (LPVOID)0,
  209. 0,
  210. &dwThreadID);
  211. }
  212. HRESULT CRefDial::OnDownloadEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled)
  213. {
  214. if (uMsg == WM_OBCOMM_DOWNLOAD_DONE)
  215. {
  216. DWORD dwThreadResults = STILL_ACTIVE;
  217. int iRetries = 0;
  218. // We keep the RAS connection open here, it must be explicitly
  219. // close by the container (a call DoHangup)
  220. // This code will wait until the download thread exists, and
  221. // collect the download status.
  222. if (m_hThread)
  223. {
  224. do {
  225. if (!GetExitCodeThread(m_hThread, &dwThreadResults))
  226. {
  227. //ASSERT(0, L"CONNECT:GetExitCodeThread failed.\n");
  228. }
  229. iRetries++;
  230. if (dwThreadResults == STILL_ACTIVE)
  231. Sleep(500);
  232. } while (dwThreadResults == STILL_ACTIVE && iRetries < MAX_EXIT_RETRIES);
  233. m_hThread = NULL;
  234. }
  235. // BUGBUG: Is bstrURL used for anything??
  236. // See if there is an URL to pass to the container
  237. BSTR bstrURL;
  238. if (m_szRefServerURL[0] != L'\0')
  239. bstrURL = SysAllocString(m_szRefServerURL);
  240. else
  241. bstrURL = NULL;
  242. // The download is complete now, so we reset this to TRUE, so the RAS
  243. // event handler does not get confused
  244. m_bDownloadHasBeenCanceled = TRUE;
  245. // Read and parse the download folder.
  246. *bHandled = ParseISPInfo(NULL, ICW_ISPINFOPath, TRUE);
  247. // Free any memory allocated above during the conversion
  248. SysFreeString(bstrURL);
  249. }
  250. return 0;
  251. }
  252. //+---------------------------------------------------------------------------
  253. //
  254. // Function: TerminateConnMonitorThread()
  255. //
  256. // Synopsis: Termintate connection monitor thread
  257. //
  258. //+---------------------------------------------------------------------------
  259. void CRefDial::TerminateConnMonitorThread()
  260. {
  261. DWORD dwThreadResults = STILL_ACTIVE;
  262. int iRetries = 0;
  263. if (m_hConnMonThread)
  264. {
  265. SetEvent(m_hConnectionTerminate);
  266. // We keep the RAS connection open here, it must be explicitly
  267. // close by the container (a call DoHangup)
  268. // This code will wait until the monitor thread exists, and
  269. // collect the status.
  270. do
  271. {
  272. if (!GetExitCodeThread(m_hConnMonThread, &dwThreadResults))
  273. {
  274. break;
  275. }
  276. iRetries++;
  277. if (dwThreadResults == STILL_ACTIVE)
  278. Sleep(500);
  279. } while (dwThreadResults == STILL_ACTIVE && iRetries < MAX_EXIT_RETRIES);
  280. CloseHandle(m_hConnMonThread);
  281. m_hConnMonThread = NULL;
  282. }
  283. }
  284. //+---------------------------------------------------------------------------
  285. //
  286. // Function: ConnectionMonitorThread()
  287. //
  288. // Synopsis: Monitor connection status
  289. //
  290. //+---------------------------------------------------------------------------
  291. DWORD CRefDial::ConnectionMonitorThread(LPVOID pdata)
  292. {
  293. HRESULT hr = E_FAIL;
  294. MSG msg;
  295. DWORD dwRetCode;
  296. HANDLE hEventList[1];
  297. BOOL bConnected;
  298. m_hConnectionTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
  299. hEventList[0] = m_hConnectionTerminate;
  300. while(TRUE)
  301. {
  302. // We will wait on window messages and also the named event.
  303. dwRetCode = MsgWaitForMultipleObjects(1,
  304. &hEventList[0],
  305. FALSE,
  306. 1000, // 1 second
  307. QS_ALLINPUT);
  308. if(dwRetCode == WAIT_TIMEOUT)
  309. {
  310. RasGetConnectStatus(&bConnected);
  311. // If we've got disconnected, then we notify UI
  312. if (!bConnected)
  313. {
  314. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONDIALERROR, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)ERROR_REMOTE_DISCONNECTION);
  315. break;
  316. }
  317. }
  318. else if(dwRetCode == WAIT_OBJECT_0)
  319. {
  320. break;
  321. }
  322. else if(dwRetCode == WAIT_OBJECT_0 + 1)
  323. {
  324. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  325. {
  326. if (WM_QUIT == msg.message)
  327. {
  328. //*pbRetVal = FALSE;
  329. break;
  330. }
  331. else
  332. {
  333. TranslateMessage(&msg);
  334. DispatchMessage(&msg);
  335. }
  336. }
  337. }
  338. }
  339. CloseHandle(m_hConnectionTerminate);
  340. m_hConnectionTerminate = NULL;
  341. return hr;
  342. }
  343. //+---------------------------------------------------------------------------
  344. //
  345. // Function: RasDialFunc()
  346. //
  347. // Synopsis: Call back for RAS
  348. //
  349. //+---------------------------------------------------------------------------
  350. void CALLBACK CRefDial::RasDialFunc(HRASCONN hRas,
  351. UINT unMsg,
  352. RASCONNSTATE rasconnstate,
  353. DWORD dwError,
  354. DWORD dwErrorEx)
  355. {
  356. if (gpCommMgr)
  357. {
  358. if (dwError)
  359. {
  360. if (ERROR_USER_DISCONNECTION != dwError)
  361. {
  362. gpCommMgr->m_pRefDial->DoHangup();
  363. //gpCommMgr->Fire_DialError((DWORD)rasconnstate);
  364. TRACE1(L"DialError %d", dwError);
  365. gpCommMgr->m_pRefDial->m_dwRASErr = dwError; // Store dialing error
  366. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONDIALERROR, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)gpCommMgr->m_pRefDial->m_dwRASErr);
  367. }
  368. }
  369. else
  370. {
  371. switch(rasconnstate)
  372. {
  373. case RASCS_OpenPort:
  374. //gpCommMgr->Fire_Dialing((DWORD)rasconnstate);
  375. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONDIALING, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  376. break;
  377. case RASCS_StartAuthentication: // WIN 32 only
  378. //gpCommMgr->Fire_Connecting();
  379. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONCONNECTING, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  380. break;
  381. case RASCS_Authenticate: // WIN 32 only
  382. //gpCommMgr->Fire_Connecting();
  383. if (IsNT())
  384. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONCONNECTING, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  385. break;
  386. case RASCS_PortOpened:
  387. break;
  388. case RASCS_ConnectDevice:
  389. break;
  390. case RASCS_DeviceConnected:
  391. case RASCS_AllDevicesConnected:
  392. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONCONNECTING, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  393. break;
  394. case RASCS_Connected:
  395. {
  396. CreateConnMonitorThread(NULL);
  397. PostMessage(gpCommMgr->m_hwndCallBack,
  398. WM_OBCOMM_ONCONNECTED,
  399. (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType,
  400. (LPARAM)0);
  401. break;
  402. }
  403. case RASCS_Disconnected:
  404. {
  405. if (CONNECTED_REFFERAL == gpCommMgr->m_pRefDial->m_dwCnType &&
  406. !gpCommMgr->m_pRefDial->m_bDownloadHasBeenCanceled)
  407. {
  408. HINSTANCE hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  409. if (hDLDLL)
  410. {
  411. FARPROC fp = GetProcAddress(hDLDLL, DOWNLOADCANCEL);
  412. if(fp)
  413. ((PFNDOWNLOADCANCEL)fp)(gpCommMgr->m_pRefDial->m_dwDownLoad);
  414. FreeLibrary(hDLDLL);
  415. hDLDLL = NULL;
  416. gpCommMgr->m_pRefDial->m_bDownloadHasBeenCanceled = TRUE;
  417. }
  418. }
  419. // If we get a disconnected status from the RAS server, then
  420. // hangup the modem here
  421. gpCommMgr->m_pRefDial->DoHangup();
  422. //gpCommMgr->Fire_DialError((DWORD)rasconnstate);
  423. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONDISCONNECT, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  424. break;
  425. }
  426. default:
  427. break;
  428. }
  429. }
  430. }
  431. return;
  432. }
  433. /////////////////////////////////////////////////////////////////////////////
  434. // CRefDial
  435. CRefDial::CRefDial()
  436. {
  437. HKEY hkey = NULL;
  438. DWORD dwResult = 0;
  439. *m_szCurrentDUNFile = 0;
  440. *m_szLastDUNFile = 0;
  441. *m_szEntryName = 0;
  442. *m_szConnectoid = 0;
  443. *m_szPID = 0;
  444. *m_szRefServerURL = 0;
  445. *m_szRegServerName = 0;
  446. m_nRegServerPort = INTERNET_INVALID_PORT_NUMBER;
  447. m_fSecureRegServer = FALSE;
  448. *m_szRegFormAction = 0;
  449. *m_szISPSupportNumber = 0;
  450. *m_szISPFile = 0;
  451. m_hrDisplayableNumber = ERROR_SUCCESS;
  452. m_dwCountryCode = 0;
  453. m_RasStatusID = 0;
  454. m_dwTapiDev = 0xFFFFFFFF; // NOTE: 0 is a valid value
  455. m_dwWizardVersion = 0;
  456. m_lCurrentModem = -1;
  457. m_lAllOffers = 0;
  458. m_PhoneNumberEnumidx = 0;
  459. m_dwRASErr = 0;
  460. m_bDownloadHasBeenCanceled = TRUE; // This will get set to FALSE when a DOWNLOAD starts
  461. m_bQuitWizard = FALSE;
  462. m_bTryAgain = FALSE;
  463. m_bDisconnect = FALSE;
  464. m_bDialCustom = FALSE;
  465. m_bModemOverride = FALSE; //allows campus net to be used.
  466. m_hrasconn = NULL;
  467. m_pszDisplayable = NULL;
  468. m_pcRNA = NULL;
  469. m_hRasDll = NULL;
  470. m_fpRasDial = NULL;
  471. m_fpRasGetEntryDialParams = NULL;
  472. m_lpGatherInfo = new GATHERINFO;
  473. m_reflpRasEntryBuff = NULL;
  474. m_reflpRasDevInfoBuff = NULL;
  475. m_hThread = NULL;
  476. m_hDialThread = NULL;
  477. m_hConnMonThread = NULL;
  478. m_bUserInitiateHangup = FALSE;
  479. m_pszOriginalDisplayable = NULL;
  480. m_bDialAlternative = TRUE;
  481. memset(&m_SuggestInfo, 0, sizeof(m_SuggestInfo));
  482. memset(&m_szConnectoid, 0, RAS_MaxEntryName+1);
  483. m_dwAppMode = 0;
  484. m_bDial = FALSE;
  485. m_dwCnType = CONNECTED_ISP_SIGNUP;
  486. m_pszISPList = FALSE;
  487. m_dwNumOfAutoConfigOffers = 0;
  488. m_pCSVList = NULL;
  489. m_unSelectedISP = 0;
  490. m_bstrPromoCode = SysAllocString(L"\0");
  491. m_bstrProductCode = SysAllocString(L"\0");
  492. m_bstrSignedPID = SysAllocString(L"\0");
  493. m_bstrSupportNumber = SysAllocString(L"\0");
  494. m_bstrLoggingStartUrl = SysAllocString(L"\0");
  495. m_bstrLoggingEndUrl = SysAllocString(L"\0");
  496. // This Critical Section is used by DoHangup and GetDisplayableNumber
  497. InitializeCriticalSection (&m_csMyCriticalSection);
  498. // Initialize m_dwConnectionType.
  499. m_dwConnectionType = 0;
  500. if ( RegOpenKey(HKEY_LOCAL_MACHINE, ICSSETTINGSPATH,&hkey) == ERROR_SUCCESS)
  501. {
  502. DWORD dwSize = sizeof(DWORD);
  503. DWORD dwType = REG_DWORD;
  504. if (RegQueryValueEx(hkey, ICSCLIENT,NULL,&dwType,(LPBYTE)&dwResult, &dwSize) != ERROR_SUCCESS)
  505. dwResult = 0;
  506. RegCloseKey(hkey);
  507. }
  508. if ( 0 != dwResult )
  509. m_dwConnectionType = CONNECTION_ICS_TYPE;
  510. }
  511. CRefDial::~CRefDial()
  512. {
  513. if (m_hrasconn)
  514. DoHangup();
  515. if (m_hConnMonThread)
  516. {
  517. SetEvent(m_hConnectionTerminate);
  518. }
  519. if (NULL != m_hThread)
  520. {
  521. CloseHandle(m_hThread);
  522. m_hThread = NULL;
  523. }
  524. if (NULL != m_hDialThread)
  525. {
  526. CloseHandle(m_hDialThread);
  527. m_hDialThread = NULL;
  528. }
  529. if (NULL != m_hConnMonThread)
  530. {
  531. CloseHandle(m_hConnMonThread);
  532. m_hConnMonThread = NULL;
  533. }
  534. if (m_lpGatherInfo)
  535. delete(m_lpGatherInfo);
  536. if( (m_pcRNA!=NULL) && (*m_szConnectoid != 0) )
  537. {
  538. m_pcRNA->RasDeleteEntry(NULL, m_szConnectoid);
  539. }
  540. if ( m_pcRNA )
  541. delete m_pcRNA;
  542. if(m_reflpRasEntryBuff)
  543. {
  544. GlobalFree(m_reflpRasEntryBuff);
  545. m_reflpRasEntryBuff = NULL;
  546. }
  547. if(m_reflpRasDevInfoBuff)
  548. {
  549. GlobalFree(m_reflpRasDevInfoBuff);
  550. m_reflpRasDevInfoBuff = NULL;
  551. }
  552. if (m_pszISPList)
  553. delete [] m_pszISPList;
  554. DeleteCriticalSection(&m_csMyCriticalSection);
  555. if (m_pszOriginalDisplayable)
  556. {
  557. GlobalFree(m_pszOriginalDisplayable);
  558. m_pszOriginalDisplayable = NULL;
  559. }
  560. CleanISPList();
  561. }
  562. void CRefDial::CleanISPList(void)
  563. {
  564. if (m_pCSVList)
  565. {
  566. ISPLIST* pCurr;
  567. while (m_pCSVList->pNext != NULL)
  568. {
  569. pCurr = m_pCSVList;
  570. if (NULL != m_pCSVList->pElement)
  571. {
  572. delete pCurr->pElement;
  573. }
  574. m_pCSVList = pCurr->pNext;
  575. delete pCurr;
  576. }
  577. if (NULL != m_pCSVList->pElement)
  578. delete m_pCSVList->pElement;
  579. delete m_pCSVList;
  580. m_pCSVList = NULL;
  581. m_pSelectedISPInfo = NULL;
  582. }
  583. }
  584. /******************************************************************************
  585. // These functions come from the existing ICW code and are use to setup a
  586. // connectiod to the referral server, dial it, and perform the download.
  587. ******************************************************************************/
  588. //+----------------------------------------------------------------------------
  589. // Function: ReadConnectionInformation
  590. //
  591. // Synopsis: Read the contents from the ISP file
  592. //
  593. // Arguments: none
  594. //
  595. // Returns: error value - ERROR_SUCCESS = succes
  596. //
  597. // History: 1/9/98 DONALDM Adapted from ICW 1.x
  598. //-----------------------------------------------------------------------------
  599. //INT _convert;
  600. DWORD CRefDial::ReadConnectionInformation(void)
  601. {
  602. DWORD hr;
  603. WCHAR szUserName[UNLEN+1];
  604. WCHAR szPassword[PWLEN+1];
  605. LPWSTR pszTemp;
  606. BOOL bReboot;
  607. LPWSTR lpRunOnceCmd;
  608. bReboot = FALSE;
  609. lpRunOnceCmd = NULL;
  610. //
  611. // Get the name of DUN file from ISP file, if there is one.
  612. //
  613. WCHAR pszDunFile[MAX_PATH];
  614. *m_szCurrentDUNFile = 0;
  615. hr = GetDataFromISPFile(m_szISPFile, INF_SECTION_ISPINFO, INF_DUN_FILE, pszDunFile,MAX_PATH);
  616. if (ERROR_SUCCESS == hr)
  617. {
  618. //
  619. // Get the full path to the DUN File
  620. //
  621. WCHAR szTempPath[MAX_PATH];
  622. lstrcpy(szTempPath, pszDunFile);
  623. if (!(hr = SearchPath(NULL, szTempPath,NULL,MAX_PATH,pszDunFile,&pszTemp)))
  624. {
  625. //ErrorMsg1(m_hWnd, IDS_CANTREADTHISFILE, CharUpper(pszDunFile));
  626. goto ReadConnectionInformationExit;
  627. }
  628. //
  629. // save current DUN file name in global (for ourself)
  630. //
  631. lstrcpy(m_szCurrentDUNFile, pszDunFile);
  632. }
  633. //
  634. // Read the DUN/ISP file File
  635. //
  636. hr = m_ISPImport.ImportConnection(*m_szCurrentDUNFile != 0 ? m_szCurrentDUNFile : m_szISPFile,
  637. m_szISPSupportNumber,
  638. m_szEntryName,
  639. szUserName,
  640. szPassword,
  641. &bReboot);
  642. lstrcpyn( m_szConnectoid, m_szEntryName, lstrlen(m_szEntryName) + 1);
  643. if (/*(VER_PLATFORM_WIN32_NT == g_dwPlatform) &&*/ (ERROR_INVALID_PARAMETER == hr))
  644. {
  645. // If there are only dial-out entries configured on NT, we get
  646. // ERROR_INVALID_PARAMETER returned from RasSetEntryProperties,
  647. // which InetConfigClient returns to ImportConnection which
  648. // returns it to us. If we get this error, we want to display
  649. // a different error instructing the user to configure a modem
  650. // for dial-out.
  651. ////MessageBox(GetSz(IDS_NODIALOUT),
  652. // GetSz(IDS_TITLE),
  653. // MB_ICONERROR | MB_OK | MB_APPLMODAL);
  654. goto ReadConnectionInformationExit;
  655. }
  656. else
  657. if (ERROR_CANNOT_FIND_PHONEBOOK_ENTRY == hr)
  658. {
  659. //
  660. // The disk is full, or something is wrong with the
  661. // phone book file
  662. ////MessageBox(GetSz(IDS_NOPHONEENTRY),
  663. // GetSz(IDS_TITLE),
  664. // MB_ICONERROR | MB_OK | MB_APPLMODAL);
  665. goto ReadConnectionInformationExit;
  666. }
  667. else if (hr == ERROR_CANCELLED)
  668. {
  669. ////TraceMsg(TF_GENERAL, L"ICWHELP: User cancelled, quitting.\n");
  670. goto ReadConnectionInformationExit;
  671. }
  672. else if (hr == ERROR_RETRY)
  673. {
  674. //TraceMsg(TF_GENERAL, L"ICWHELP: User retrying.\n");
  675. goto ReadConnectionInformationExit;
  676. }
  677. else if (hr != ERROR_SUCCESS)
  678. {
  679. ////ErrorMsg1(m_hWnd, IDS_CANTREADTHISFILE, CharUpper(pszDunFile));
  680. goto ReadConnectionInformationExit;
  681. }
  682. else
  683. {
  684. //
  685. // place the name of the connectoid in the registry
  686. //
  687. if (ERROR_SUCCESS != (hr = StoreInSignUpReg((LPBYTE)m_szEntryName, BYTES_REQUIRED_BY_SZ(m_szEntryName), REG_SZ, RASENTRYVALUENAME)))
  688. {
  689. ////MsgBox(IDS_CANTSAVEKEY, MB_MYERROR);
  690. goto ReadConnectionInformationExit;
  691. }
  692. }
  693. ReadConnectionInformationExit:
  694. return hr;
  695. }
  696. HRESULT CRefDial::ReadPhoneBook(LPGATHERINFO lpGatherInfo, PSUGGESTINFO pSuggestInfo)
  697. {
  698. HRESULT hr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;;
  699. if (pSuggestInfo && m_lpGatherInfo)
  700. {
  701. //
  702. // If phonenumber is not filled in by the ISP file,
  703. // get phone number from oobe phone book
  704. //
  705. pSuggestInfo->wNumber = 1;
  706. lpGatherInfo->m_bUsePhbk = TRUE;
  707. WCHAR szEntrySection[3];
  708. WCHAR szEntryName[MAX_PATH];
  709. WCHAR szEntryValue[MAX_PATH];
  710. INT nPick = 1;
  711. INT nTotal= 3;
  712. WCHAR szFileName[MAX_PATH];
  713. LPWSTR pszTemp;
  714. // Get Country ID from TAPI
  715. m_SuggestInfo.AccessEntry.dwCountryCode = m_lpGatherInfo->m_dwCountryCode;
  716. // Get the name of phone book
  717. GetPrivateProfileString(INF_SECTION_ISPINFO,
  718. INF_PHONE_BOOK,
  719. cszOobePhBkFile,
  720. szEntryValue,
  721. MAX_CHARS_IN_BUFFER(szEntryValue),
  722. m_szISPFile);
  723. SearchPath(NULL, szEntryValue,NULL,MAX_PATH,&szFileName[0],&pszTemp);
  724. wsprintf(szEntrySection, L"%ld", m_lpGatherInfo->m_dwCountryID);
  725. // Read the total number of phone numbers
  726. nTotal = GetPrivateProfileInt(szEntrySection,
  727. cszOobePhBkCount,
  728. 1,
  729. szFileName);
  730. GetPrivateProfileString(szEntrySection,
  731. cszOobePhBkRandom,
  732. L"No",
  733. szEntryValue,
  734. MAX_CHARS_IN_BUFFER(szEntryValue),
  735. szFileName);
  736. if (0 == lstrcmp(szEntryValue, L"Yes"))
  737. {
  738. // Pick a random number to dial
  739. nPick = (rand() % nTotal) + 1;
  740. }
  741. else
  742. {
  743. nPick = (pSuggestInfo->dwPick % nTotal) + 1;
  744. }
  745. // Read the name of the city
  746. wsprintf(szEntryName, cszOobePhBkCity, nPick);
  747. GetPrivateProfileString(szEntrySection,
  748. szEntryName,
  749. L"",
  750. szEntryValue,
  751. MAX_CHARS_IN_BUFFER(szEntryValue),
  752. szFileName);
  753. lstrcpy(pSuggestInfo->AccessEntry.szCity, szEntryValue);
  754. if (0 == lstrlen(szEntryValue))
  755. {
  756. goto ReadPhoneBookExit;
  757. }
  758. // Read the dunfile entry from the phonebook
  759. // lstrcpy(pSuggestInfo->AccessEntry.szDataCenter, L"icwip.dun");
  760. wsprintf(szEntryName, cszOobePhBkDunFile, nPick);
  761. GetPrivateProfileString(szEntrySection,
  762. szEntryName,
  763. L"",
  764. szEntryValue,
  765. MAX_CHARS_IN_BUFFER(szEntryValue),
  766. szFileName);
  767. lstrcpy(pSuggestInfo->AccessEntry.szDataCenter, szEntryValue);
  768. if (0 == lstrlen(szEntryValue))
  769. {
  770. goto ReadPhoneBookExit;
  771. }
  772. // Pick up country code from the Phonebook
  773. wsprintf(szEntryName, cszOobePhBkAreaCode, nPick);
  774. GetPrivateProfileString(szEntrySection,
  775. szEntryName,
  776. L"",
  777. szEntryValue,
  778. MAX_CHARS_IN_BUFFER(szEntryValue),
  779. szFileName);
  780. lstrcpy(pSuggestInfo->AccessEntry.szAreaCode, szEntryValue);
  781. // No area code is possible
  782. // Read the phone number (without areacode) from the Phonebook
  783. wsprintf(szEntryName, cszOobePhBkNumber, nPick);
  784. GetPrivateProfileString(szEntrySection,
  785. szEntryName,
  786. L"",
  787. szEntryValue,
  788. MAX_CHARS_IN_BUFFER(szEntryValue),
  789. szFileName);
  790. lstrcpy(pSuggestInfo->AccessEntry.szAccessNumber, szEntryValue);
  791. if (0 == lstrlen(szEntryValue))
  792. {
  793. goto ReadPhoneBookExit;
  794. }
  795. hr = ERROR_SUCCESS;
  796. }
  797. ReadPhoneBookExit:
  798. return hr;
  799. }
  800. HRESULT CRefDial::GetDisplayableNumber()
  801. {
  802. HRESULT hr = ERROR_SUCCESS;
  803. LPRASENTRY lpRasEntry = NULL;
  804. LPRASDEVINFO lpRasDevInfo = NULL;
  805. DWORD dwRasEntrySize = 0;
  806. DWORD dwRasDevInfoSize = 0;
  807. RNAAPI *pcRNA = NULL;
  808. LPLINETRANSLATEOUTPUT lpOutput1 = NULL;
  809. DWORD dwNumDev;
  810. LPLINETRANSLATEOUTPUT lpOutput2;
  811. LPLINEEXTENSIONID lpExtensionID = NULL;
  812. // Turns out that DialThreadInit can call this at the same time
  813. // that script will call this. So, we need to prevent them from
  814. // stepping on shared variables - m_XXX.
  815. EnterCriticalSection (&m_csMyCriticalSection);
  816. //
  817. // Get phone number from connectoid
  818. //
  819. hr = MyRasGetEntryProperties(NULL,
  820. m_szConnectoid,
  821. &lpRasEntry,
  822. &dwRasEntrySize,
  823. &lpRasDevInfo,
  824. &dwRasDevInfoSize);
  825. if (hr != ERROR_SUCCESS || NULL == lpRasEntry)
  826. {
  827. goto GetDisplayableNumberExit;
  828. }
  829. //
  830. // If this is a dial as is number, just get it from the structure
  831. //
  832. m_bDialAsIs = !(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes);
  833. if (m_bDialAsIs)
  834. {
  835. if (m_pszDisplayable) GlobalFree(m_pszDisplayable);
  836. m_pszDisplayable = (LPWSTR)GlobalAlloc(GPTR, BYTES_REQUIRED_BY_SZ(lpRasEntry->szLocalPhoneNumber));
  837. if (!m_pszDisplayable)
  838. {
  839. hr = ERROR_NOT_ENOUGH_MEMORY;
  840. goto GetDisplayableNumberExit;
  841. }
  842. lstrcpy(m_szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  843. lstrcpy(m_pszDisplayable, lpRasEntry->szLocalPhoneNumber);
  844. WCHAR szAreaCode[MAX_AREACODE+1];
  845. WCHAR szCountryCode[8];
  846. if (SUCCEEDED(tapiGetLocationInfo(szCountryCode, szAreaCode)))
  847. {
  848. if (szCountryCode[0] != L'\0')
  849. m_dwCountryCode = _wtoi(szCountryCode);
  850. else
  851. m_dwCountryCode = 1;
  852. }
  853. else
  854. {
  855. m_dwCountryCode = 1;
  856. }
  857. }
  858. else
  859. {
  860. //
  861. // If there is no area code, don't use parentheses
  862. //
  863. if (lpRasEntry->szAreaCode[0])
  864. wsprintf(m_szPhoneNumber, L"+%lu (%s) %s\0",lpRasEntry->dwCountryCode,
  865. lpRasEntry->szAreaCode, lpRasEntry->szLocalPhoneNumber);
  866. else
  867. wsprintf(m_szPhoneNumber, L"+%lu %s\0",lpRasEntry->dwCountryCode,
  868. lpRasEntry->szLocalPhoneNumber);
  869. //
  870. // Initialize TAPIness
  871. //
  872. dwNumDev = 0;
  873. DWORD dwVer = 0x00020000;
  874. hr = lineInitializeEx(&m_hLineApp,
  875. NULL,
  876. LineCallback,
  877. NULL,
  878. &dwNumDev,
  879. &dwVer,
  880. NULL);
  881. if (hr != ERROR_SUCCESS)
  882. goto GetDisplayableNumberExit;
  883. lpExtensionID = (LPLINEEXTENSIONID )GlobalAlloc(GPTR, sizeof(LINEEXTENSIONID));
  884. if (!lpExtensionID)
  885. {
  886. hr = ERROR_NOT_ENOUGH_MEMORY;
  887. goto GetDisplayableNumberExit;
  888. }
  889. if (m_dwTapiDev == 0xFFFFFFFF)
  890. {
  891. m_dwTapiDev = 0;
  892. }
  893. //
  894. // ChrisK Olympus 5558 6/11/97
  895. // PPTP device will choke the version negotiating
  896. //
  897. do { //E_FAIL here?
  898. hr = lineNegotiateAPIVersion(m_hLineApp,
  899. m_dwTapiDev,
  900. 0x00010004,
  901. 0x00020000,
  902. &m_dwAPIVersion,
  903. lpExtensionID);
  904. } while (hr != ERROR_SUCCESS && m_dwTapiDev++ < dwNumDev - 1);
  905. if (m_dwTapiDev >= dwNumDev)
  906. {
  907. m_dwTapiDev = 0;
  908. }
  909. // ditch it since we don't use it
  910. //
  911. if (lpExtensionID) GlobalFree(lpExtensionID);
  912. lpExtensionID = NULL;
  913. if (hr != ERROR_SUCCESS)
  914. goto GetDisplayableNumberExit;
  915. // Format the phone number
  916. //
  917. lpOutput1 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR, sizeof(LINETRANSLATEOUTPUT));
  918. if (!lpOutput1)
  919. {
  920. hr = ERROR_NOT_ENOUGH_MEMORY;
  921. goto GetDisplayableNumberExit;
  922. }
  923. lpOutput1->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  924. // Turn the canonical form into the "displayable" form
  925. //
  926. hr = lineTranslateAddress(m_hLineApp, m_dwTapiDev,m_dwAPIVersion,
  927. m_szPhoneNumber, 0,
  928. LINETRANSLATEOPTION_CANCELCALLWAITING,
  929. lpOutput1);
  930. // We've seen hr == ERROR_SUCCESS but the size is too small,
  931. // Also, the docs hint that some error cases are due to struct too small.
  932. if (lpOutput1->dwNeededSize > lpOutput1->dwTotalSize)
  933. {
  934. lpOutput2 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR, (size_t)lpOutput1->dwNeededSize);
  935. if (!lpOutput2)
  936. {
  937. hr = ERROR_NOT_ENOUGH_MEMORY;
  938. goto GetDisplayableNumberExit;
  939. }
  940. lpOutput2->dwTotalSize = lpOutput1->dwNeededSize;
  941. GlobalFree(lpOutput1);
  942. lpOutput1 = lpOutput2;
  943. lpOutput2 = NULL;
  944. hr = lineTranslateAddress(m_hLineApp, m_dwTapiDev,
  945. m_dwAPIVersion, m_szPhoneNumber,0,
  946. LINETRANSLATEOPTION_CANCELCALLWAITING,
  947. lpOutput1);
  948. }
  949. if (hr != ERROR_SUCCESS)
  950. {
  951. goto GetDisplayableNumberExit;
  952. }
  953. if (m_pszDisplayable)
  954. {
  955. GlobalFree(m_pszDisplayable);
  956. }
  957. m_pszDisplayable = (LPWSTR)GlobalAlloc(GPTR, ((size_t)lpOutput1->dwDisplayableStringSize+1));
  958. if (!m_pszDisplayable)
  959. {
  960. hr = ERROR_NOT_ENOUGH_MEMORY;
  961. goto GetDisplayableNumberExit;
  962. }
  963. lstrcpyn(m_pszDisplayable,
  964. (LPWSTR)&((LPBYTE)lpOutput1)[lpOutput1->dwDisplayableStringOffset],
  965. (int)(lpOutput1->dwDisplayableStringSize/sizeof(WCHAR)));
  966. WCHAR szAreaCode[MAX_AREACODE+1];
  967. WCHAR szCountryCode[8];
  968. if (SUCCEEDED(tapiGetLocationInfo(szCountryCode, szAreaCode)))
  969. {
  970. if (szCountryCode[0] != L'\0')
  971. m_dwCountryCode = _wtoi(szCountryCode);
  972. else
  973. m_dwCountryCode = 1;
  974. }
  975. else
  976. {
  977. m_dwCountryCode = 1;
  978. }
  979. }
  980. GetDisplayableNumberExit:
  981. if (lpOutput1) GlobalFree(lpOutput1);
  982. if (m_hLineApp) lineShutdown(m_hLineApp);
  983. // Release ownership of the critical section
  984. LeaveCriticalSection (&m_csMyCriticalSection);
  985. return hr;
  986. }
  987. BOOL CRefDial::FShouldRetry(HRESULT hrErr)
  988. {
  989. BOOL bRC;
  990. m_uiRetry++;
  991. if (hrErr == ERROR_LINE_BUSY ||
  992. hrErr == ERROR_VOICE_ANSWER ||
  993. hrErr == ERROR_NO_ANSWER ||
  994. hrErr == ERROR_NO_CARRIER ||
  995. hrErr == ERROR_AUTHENTICATION_FAILURE ||
  996. hrErr == ERROR_PPP_TIMEOUT ||
  997. hrErr == ERROR_REMOTE_DISCONNECTION ||
  998. hrErr == ERROR_AUTH_INTERNAL ||
  999. hrErr == ERROR_PROTOCOL_NOT_CONFIGURED ||
  1000. hrErr == ERROR_PPP_NO_PROTOCOLS_CONFIGURED)
  1001. {
  1002. bRC = TRUE;
  1003. } else {
  1004. bRC = FALSE;
  1005. }
  1006. bRC = bRC && m_uiRetry < MAX_RETIES;
  1007. return bRC;
  1008. }
  1009. DWORD CRefDial:: DialThreadInit(LPVOID pdata)
  1010. {
  1011. WCHAR szPassword[PWLEN+1];
  1012. WCHAR szUserName[UNLEN + 1];
  1013. WCHAR szDomain[DNLEN+1];
  1014. LPRASDIALPARAMS lpRasDialParams = NULL;
  1015. LPRASDIALEXTENSIONS lpRasDialExtentions = NULL;
  1016. HRESULT hr = ERROR_SUCCESS;
  1017. BOOL bPW;
  1018. DWORD dwResult;
  1019. // Initialize the dial error member
  1020. m_dwRASErr = 0;
  1021. if (!m_pcRNA)
  1022. {
  1023. hr = E_FAIL;
  1024. goto DialExit;
  1025. }
  1026. // Get connectoid information
  1027. //
  1028. lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR, sizeof(RASDIALPARAMS));
  1029. if (!lpRasDialParams)
  1030. {
  1031. hr = ERROR_NOT_ENOUGH_MEMORY;
  1032. goto DialExit;
  1033. }
  1034. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  1035. lstrcpyn(lpRasDialParams->szEntryName, m_szConnectoid,MAX_CHARS_IN_BUFFER(lpRasDialParams->szEntryName));
  1036. bPW = FALSE;
  1037. hr = m_pcRNA->RasGetEntryDialParams(NULL, lpRasDialParams,&bPW);
  1038. if (hr != ERROR_SUCCESS)
  1039. {
  1040. goto DialExit;
  1041. }
  1042. lpRasDialExtentions = (LPRASDIALEXTENSIONS)GlobalAlloc(GPTR, sizeof(RASDIALEXTENSIONS));
  1043. if (lpRasDialExtentions)
  1044. {
  1045. lpRasDialExtentions->dwSize = sizeof(RASDIALEXTENSIONS);
  1046. lpRasDialExtentions->dwfOptions = RDEOPT_UsePrefixSuffix;
  1047. }
  1048. //
  1049. // Add the user's password
  1050. //
  1051. szPassword[0] = 0;
  1052. szUserName[0] = 0;
  1053. WCHAR szOOBEInfoINIFile[MAX_PATH];
  1054. SearchPath(NULL, cszOOBEINFOINI, NULL, MAX_CHARS_IN_BUFFER(szOOBEInfoINIFile), szOOBEInfoINIFile, NULL);
  1055. GetPrivateProfileString(INFFILE_USER_SECTION,
  1056. INFFILE_PASSWORD,
  1057. NULLSZ,
  1058. szPassword,
  1059. PWLEN + 1,
  1060. *m_szCurrentDUNFile != 0 ? m_szCurrentDUNFile : m_szISPFile);
  1061. if (m_lpGatherInfo->m_bUsePhbk)
  1062. {
  1063. if (GetPrivateProfileString(DUN_SECTION,
  1064. USERNAME,
  1065. NULLSZ,
  1066. szUserName,
  1067. UNLEN + 1,
  1068. szOOBEInfoINIFile))
  1069. {
  1070. if(szUserName[0])
  1071. lstrcpy(lpRasDialParams->szUserName, szUserName);
  1072. }
  1073. }
  1074. if(szPassword[0])
  1075. lstrcpy(lpRasDialParams->szPassword, szPassword);
  1076. GetPrivateProfileString(INFFILE_USER_SECTION,
  1077. INFFILE_DOMAIN,
  1078. NULLSZ,
  1079. szDomain,
  1080. DNLEN + 1,
  1081. *m_szCurrentDUNFile != 0 ? m_szCurrentDUNFile : m_szISPFile);
  1082. szDomain[0] = 0;
  1083. if (szDomain[0])
  1084. lstrcpy(lpRasDialParams->szDomain, szDomain);
  1085. dwResult = m_pcRNA->RasDial( lpRasDialExtentions,
  1086. NULL,
  1087. lpRasDialParams,
  1088. 1,
  1089. CRefDial::RasDialFunc,
  1090. &m_hrasconn);
  1091. if (( dwResult != ERROR_SUCCESS))
  1092. {
  1093. // We failed to connect for some reason, so hangup
  1094. if (m_hrasconn)
  1095. {
  1096. if (m_pcRNA)
  1097. {
  1098. m_pcRNA->RasHangUp(m_hrasconn);
  1099. m_hrasconn = NULL;
  1100. }
  1101. }
  1102. goto DialExit;
  1103. }
  1104. if (m_bFromPhoneBook && (GetDisplayableNumber() == ERROR_SUCCESS))
  1105. {
  1106. if (m_pszOriginalDisplayable)
  1107. GlobalFree(m_pszOriginalDisplayable);
  1108. m_pszOriginalDisplayable = (LPWSTR)GlobalAlloc(GPTR, BYTES_REQUIRED_BY_SZ(m_pszDisplayable));
  1109. lstrcpy(m_pszOriginalDisplayable, m_pszDisplayable);
  1110. TRACE1(L"DialThreadInit: Dialing phone number %s",
  1111. m_pszOriginalDisplayable);
  1112. m_bFromPhoneBook = FALSE;
  1113. }
  1114. DialExit:
  1115. if (lpRasDialParams)
  1116. GlobalFree(lpRasDialParams);
  1117. lpRasDialParams = NULL;
  1118. if (lpRasDialExtentions)
  1119. GlobalFree(lpRasDialExtentions);
  1120. lpRasDialExtentions = NULL;
  1121. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_DIAL_DONE, 0, 0);
  1122. //m_dwRASErr = RasErrorToIDS(hr);
  1123. m_dwRASErr = hr;
  1124. return S_OK;
  1125. }
  1126. DWORD WINAPI DoDial(LPVOID lpv)
  1127. {
  1128. if (gpCommMgr)
  1129. gpCommMgr->m_pRefDial->DialThreadInit(NULL);
  1130. return 1;
  1131. }
  1132. // This function will perform the actual dialing
  1133. HRESULT CRefDial::DoConnect(BOOL * pbRetVal)
  1134. {
  1135. //Fix for redialing, on win9x we need to make sure we "hangup"
  1136. //and free the rna resources in case we are redialing.
  1137. //NT - is smart enough not to need it but it won't hurt.
  1138. if (m_hrasconn)
  1139. {
  1140. if (m_pcRNA)
  1141. m_pcRNA->RasHangUp(m_hrasconn);
  1142. m_hrasconn = NULL;
  1143. }
  1144. if (CONNECTED_REFFERAL == m_dwCnType)
  1145. FormReferralServerURL(pbRetVal);
  1146. #if defined(PRERELEASE)
  1147. if (FCampusNetOverride())
  1148. {
  1149. m_bModemOverride = TRUE;
  1150. if (gpCommMgr)
  1151. {
  1152. // Pretend we have the connection
  1153. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONCONNECTED, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType , (LPARAM)0);
  1154. // Pretend we have connection and downloaded
  1155. //PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_DOWNLOAD_DONE, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType, (LPARAM)0);
  1156. }
  1157. }
  1158. #endif
  1159. if (!m_bModemOverride)
  1160. {
  1161. DWORD dwThreadID;
  1162. if (m_hThread)
  1163. CloseHandle(m_hThread);
  1164. m_hDialThread = CreateThread(NULL,
  1165. 0,
  1166. (LPTHREAD_START_ROUTINE)DoDial,
  1167. (LPVOID)0,
  1168. 0,
  1169. &dwThreadID);
  1170. }
  1171. m_bModemOverride = FALSE;
  1172. *pbRetVal = (NULL != m_hThread);
  1173. return S_OK;
  1174. }
  1175. //+---------------------------------------------------------------------------
  1176. //
  1177. // Function: MyRasGetEntryProperties()
  1178. //
  1179. // Synopsis: Performs some buffer size checks and then calls RasGetEntryProperties()
  1180. // See the RasGetEntryProperties() docs to understand why this is needed.
  1181. //
  1182. // Arguments: Same as RasGetEntryProperties with the following exceptions:
  1183. // lplpRasEntryBuff -- pointer to a pointer to a RASENTRY struct. On successfull
  1184. // return, *lplpRasEntryBuff will point to the RASENTRY struct
  1185. // and buffer returned by RasGetEntryProperties.
  1186. // NOTE: should not have memory allocated to it at call time!
  1187. // To emphasize this point, *lplpRasEntryBuff must be NULL
  1188. // lplpRasDevInfoBuff -- pointer to a pointer to a RASDEVINFO struct. On successfull
  1189. // return, *lplpRasDevInfoBuff will point to the RASDEVINFO struct
  1190. // and buffer returned by RasGetEntryProperties.
  1191. // NOTE: should not have memory allocated to it at call time!
  1192. // To emphasize this point, *lplpRasDevInfoBuff must be NULL
  1193. // NOTE: Even on a successfull call to RasGetEntryProperties,
  1194. // *lplpRasDevInfoBuff may return with a value of NULL
  1195. // (occurs when there is no extra device info)
  1196. //
  1197. // Returns: ERROR_NOT_ENOUGH_MEMORY if unable to allocate either RASENTRY or RASDEVINFO buffer
  1198. // Otherwise, it retuns the error code from the call to RasGetEntryProperties.
  1199. // NOTE: if return is anything other than ERROR_SUCCESS, *lplpRasDevInfoBuff and
  1200. // *lplpRasEntryBuff will be NULL,
  1201. // and *lpdwRasEntryBuffSize and *lpdwRasDevInfoBuffSize will be 0
  1202. //
  1203. // Example:
  1204. //
  1205. // LPRASENTRY lpRasEntry = NULL;
  1206. // LPRASDEVINFO lpRasDevInfo = NULL;
  1207. // DWORD dwRasEntrySize, dwRasDevInfoSize;
  1208. //
  1209. // hr = MyRasGetEntryProperties( NULL,
  1210. // g_pcDialErr->m_szConnectoid,
  1211. // &lpRasEntry,
  1212. // &dwRasEntrySize,
  1213. // &lpRasDevInfo,
  1214. // &dwRasDevInfoSize);
  1215. //
  1216. //
  1217. // if (hr != ERROR_SUCCESS)
  1218. // {
  1219. // //handle errors here
  1220. // } else
  1221. // {
  1222. // //continue processing
  1223. // }
  1224. //
  1225. //
  1226. // History: 9/10/96 JMazner Created for icwconn2
  1227. // 9/17/96 JMazner Adapted for icwconn1
  1228. // 1/8/98 DONALDM Moved to the new ICW/GetConn project
  1229. //----------------------------------------------------------------------------
  1230. HRESULT CRefDial::MyRasGetEntryProperties(LPWSTR lpszPhonebookFile,
  1231. LPWSTR lpszPhonebookEntry,
  1232. LPRASENTRY *lplpRasEntryBuff,
  1233. LPDWORD lpdwRasEntryBuffSize,
  1234. LPRASDEVINFO *lplpRasDevInfoBuff,
  1235. LPDWORD lpdwRasDevInfoBuffSize)
  1236. {
  1237. HRESULT hr;
  1238. DWORD dwOldDevInfoBuffSize;
  1239. //Assert( NULL != lplpRasEntryBuff );
  1240. //Assert( NULL != lpdwRasEntryBuffSize );
  1241. //Assert( NULL != lplpRasDevInfoBuff );
  1242. //Assert( NULL != lpdwRasDevInfoBuffSize );
  1243. *lpdwRasEntryBuffSize = 0;
  1244. *lpdwRasDevInfoBuffSize = 0;
  1245. if (!m_pcRNA)
  1246. {
  1247. m_pcRNA = new RNAAPI;
  1248. hr = ERROR_NOT_ENOUGH_MEMORY;
  1249. goto MyRasGetEntryPropertiesErrExit;
  1250. }
  1251. // use RasGetEntryProperties with a NULL lpRasEntry pointer to find out size buffer we need
  1252. // As per the docs' recommendation, do the same with a NULL lpRasDevInfo pointer.
  1253. hr = m_pcRNA->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  1254. (LPBYTE) NULL,
  1255. lpdwRasEntryBuffSize,
  1256. (LPBYTE) NULL,
  1257. lpdwRasDevInfoBuffSize);
  1258. // we expect the above call to fail because the buffer size is 0
  1259. // If it doesn't fail, that means our RasEntry is messed, so we're in trouble
  1260. if( ERROR_BUFFER_TOO_SMALL != hr )
  1261. {
  1262. goto MyRasGetEntryPropertiesErrExit;
  1263. }
  1264. // dwRasEntryBuffSize and dwRasDevInfoBuffSize now contain the size needed for their
  1265. // respective buffers, so allocate the memory for them
  1266. // dwRasEntryBuffSize should never be less than the size of the RASENTRY struct.
  1267. // If it is, we'll run into problems sticking values into the struct's fields
  1268. //Assert( *lpdwRasEntryBuffSize >= sizeof(RASENTRY) );
  1269. if (m_reflpRasEntryBuff)
  1270. {
  1271. if (*lpdwRasEntryBuffSize > m_reflpRasEntryBuff->dwSize)
  1272. {
  1273. LPRASENTRY lpRasEntryTemp = (LPRASENTRY)GlobalReAlloc(m_reflpRasEntryBuff, *lpdwRasEntryBuffSize, GPTR);
  1274. if (lpRasEntryTemp)
  1275. {
  1276. m_reflpRasEntryBuff = lpRasEntryTemp;
  1277. }
  1278. else
  1279. {
  1280. GlobalFree(m_reflpRasEntryBuff);
  1281. m_reflpRasEntryBuff = NULL;
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. m_reflpRasEntryBuff = (LPRASENTRY)GlobalAlloc(GPTR, *lpdwRasEntryBuffSize);
  1288. }
  1289. if (!m_reflpRasEntryBuff)
  1290. {
  1291. hr = ERROR_NOT_ENOUGH_MEMORY;
  1292. goto MyRasGetEntryPropertiesErrExit;
  1293. }
  1294. // This is a bit convoluted: lpRasEntrySize->dwSize needs to contain the size of _only_ the
  1295. // RASENTRY structure, and _not_ the actual size of the buffer that lpRasEntrySize points to.
  1296. // This is because the dwSize field is used by RAS for compatability purposes to determine which
  1297. // version of the RASENTRY struct we're using.
  1298. // Same holds for lpRasDevInfo->dwSize
  1299. m_reflpRasEntryBuff->dwSize = sizeof(RASENTRY);
  1300. //
  1301. // Allocate the DeviceInfo size that RasGetEntryProperties told us we needed.
  1302. // If size is 0, don't alloc anything
  1303. //
  1304. if( *lpdwRasDevInfoBuffSize > 0 )
  1305. {
  1306. //Assert( *lpdwRasDevInfoBuffSize >= sizeof(RASDEVINFO) );
  1307. if (m_reflpRasDevInfoBuff)
  1308. {
  1309. // check if existing size is not sufficient
  1310. if ( *lpdwRasDevInfoBuffSize > m_reflpRasDevInfoBuff->dwSize )
  1311. {
  1312. LPRASDEVINFO lpRasDevInfoTemp = (LPRASDEVINFO)GlobalReAlloc(m_reflpRasDevInfoBuff, *lpdwRasDevInfoBuffSize, GPTR);
  1313. if (lpRasDevInfoTemp)
  1314. {
  1315. m_reflpRasDevInfoBuff = lpRasDevInfoTemp;
  1316. }
  1317. else
  1318. {
  1319. GlobalFree(m_reflpRasDevInfoBuff);
  1320. m_reflpRasDevInfoBuff = NULL;
  1321. }
  1322. }
  1323. }
  1324. else
  1325. {
  1326. m_reflpRasDevInfoBuff = (LPRASDEVINFO)GlobalAlloc(GPTR, *lpdwRasDevInfoBuffSize);
  1327. }
  1328. if (!m_reflpRasDevInfoBuff)
  1329. {
  1330. hr = ERROR_NOT_ENOUGH_MEMORY;
  1331. goto MyRasGetEntryPropertiesErrExit;
  1332. }
  1333. }
  1334. else
  1335. {
  1336. m_reflpRasDevInfoBuff = NULL;
  1337. }
  1338. if( m_reflpRasDevInfoBuff )
  1339. {
  1340. m_reflpRasDevInfoBuff->dwSize = sizeof(RASDEVINFO);
  1341. }
  1342. // now we're ready to make the actual call...
  1343. // jmazner see below for why this is needed
  1344. dwOldDevInfoBuffSize = *lpdwRasDevInfoBuffSize;
  1345. hr = m_pcRNA->RasGetEntryProperties(lpszPhonebookFile, lpszPhonebookEntry,
  1346. (LPBYTE) m_reflpRasEntryBuff,
  1347. lpdwRasEntryBuffSize,
  1348. (LPBYTE) m_reflpRasDevInfoBuff,
  1349. lpdwRasDevInfoBuffSize);
  1350. // jmazner 10/7/96 Normandy #8763
  1351. // For unknown reasons, in some cases on win95, devInfoBuffSize increases after the above call,
  1352. // but the return code indicates success, not BUFFER_TOO_SMALL. If this happens, set the
  1353. // size back to what it was before the call, so the DevInfoBuffSize and the actuall space allocated
  1354. // for the DevInfoBuff match on exit.
  1355. if( (ERROR_SUCCESS == hr) && (dwOldDevInfoBuffSize != *lpdwRasDevInfoBuffSize) )
  1356. {
  1357. *lpdwRasDevInfoBuffSize = dwOldDevInfoBuffSize;
  1358. }
  1359. *lplpRasEntryBuff = m_reflpRasEntryBuff;
  1360. *lplpRasDevInfoBuff = m_reflpRasDevInfoBuff;
  1361. return( hr );
  1362. MyRasGetEntryPropertiesErrExit:
  1363. if(m_reflpRasEntryBuff)
  1364. {
  1365. GlobalFree(m_reflpRasEntryBuff);
  1366. m_reflpRasEntryBuff = NULL;
  1367. *lplpRasEntryBuff = NULL;
  1368. }
  1369. if(m_reflpRasDevInfoBuff)
  1370. {
  1371. GlobalFree(m_reflpRasDevInfoBuff);
  1372. m_reflpRasDevInfoBuff = NULL;
  1373. *lplpRasDevInfoBuff = NULL;
  1374. }
  1375. *lpdwRasEntryBuffSize = 0;
  1376. *lpdwRasDevInfoBuffSize = 0;
  1377. return( hr );
  1378. }
  1379. HRESULT MyGetFileVersion(LPCWSTR pszFileName, LPGATHERINFO lpGatherInfo)
  1380. {
  1381. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1382. DWORD dwSize = 0;
  1383. DWORD dwTemp = 0;
  1384. LPVOID pv = NULL, pvVerInfo = NULL;
  1385. UINT uiSize;
  1386. DWORD dwVerPiece;
  1387. //int idx;
  1388. // verify parameters
  1389. //
  1390. //Assert(pszFileName && lpGatherInfo);
  1391. // Get version
  1392. //
  1393. dwSize = GetFileVersionInfoSize((LPWSTR)pszFileName, &dwTemp);
  1394. if (!dwSize)
  1395. {
  1396. hr = GetLastError();
  1397. goto MyGetFileVersionExit;
  1398. }
  1399. pv = (LPVOID)GlobalAlloc(GPTR, (size_t)dwSize);
  1400. if (!pv) goto MyGetFileVersionExit;
  1401. if (!GetFileVersionInfo((LPWSTR)pszFileName, dwTemp,dwSize,pv))
  1402. {
  1403. hr = GetLastError();
  1404. goto MyGetFileVersionExit;
  1405. }
  1406. if (!VerQueryValue(pv, L"\\\0",&pvVerInfo,&uiSize))
  1407. {
  1408. hr = GetLastError();
  1409. goto MyGetFileVersionExit;
  1410. }
  1411. pvVerInfo = (LPVOID)((DWORD_PTR)pvVerInfo + sizeof(DWORD)*4);
  1412. lpGatherInfo->m_szSUVersion[0] = L'\0';
  1413. dwVerPiece = (*((LPDWORD)pvVerInfo)) >> 16;
  1414. wsprintf(lpGatherInfo->m_szSUVersion, L"%d.",dwVerPiece);
  1415. dwVerPiece = (*((LPDWORD)pvVerInfo)) & 0x0000ffff;
  1416. wsprintf(lpGatherInfo->m_szSUVersion, L"%s%d.",lpGatherInfo->m_szSUVersion,dwVerPiece);
  1417. dwVerPiece = (((LPDWORD)pvVerInfo)[1]) >> 16;
  1418. wsprintf(lpGatherInfo->m_szSUVersion, L"%s%d.",lpGatherInfo->m_szSUVersion,dwVerPiece);
  1419. dwVerPiece = (((LPDWORD)pvVerInfo)[1]) & 0x0000ffff;
  1420. wsprintf(lpGatherInfo->m_szSUVersion, L"%s%d",lpGatherInfo->m_szSUVersion,dwVerPiece);
  1421. if (!VerQueryValue(pv, L"\\VarFileInfo\\Translation",&pvVerInfo,&uiSize))
  1422. {
  1423. hr = GetLastError();
  1424. goto MyGetFileVersionExit;
  1425. }
  1426. // separate version information from character set
  1427. lpGatherInfo->m_lcidApps = (LCID)(LOWORD(*(DWORD*)pvVerInfo));
  1428. hr = ERROR_SUCCESS;
  1429. MyGetFileVersionExit:
  1430. if (pv) GlobalFree(pv);
  1431. return hr;
  1432. }
  1433. DWORD CRefDial::FillGatherInfoStruct(LPGATHERINFO lpGatherInfo)
  1434. {
  1435. HKEY hkey = NULL;
  1436. SYSTEM_INFO si;
  1437. WCHAR szTempPath[MAX_PATH];
  1438. DWORD dwRet = ERROR_SUCCESS;
  1439. lpGatherInfo->m_lcidUser = GetUserDefaultLCID();
  1440. lpGatherInfo->m_lcidSys = GetSystemDefaultLCID();
  1441. OSVERSIONINFO osvi;
  1442. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  1443. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1444. if (!GetVersionEx(&osvi))
  1445. {
  1446. // Nevermind, we'll just assume the version is 0.0 if we can't read it
  1447. //
  1448. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  1449. }
  1450. lpGatherInfo->m_dwOS = osvi.dwPlatformId;
  1451. lpGatherInfo->m_dwMajorVersion = osvi.dwMajorVersion;
  1452. lpGatherInfo->m_dwMinorVersion = osvi.dwMinorVersion;
  1453. ZeroMemory(&si, sizeof(SYSTEM_INFO));
  1454. GetSystemInfo(&si);
  1455. lpGatherInfo->m_wArchitecture = si.wProcessorArchitecture;
  1456. // Sign-up version
  1457. //
  1458. lpGatherInfo->m_szSUVersion[0] = L'\0';
  1459. if( MyGetModuleFileName(0/*_Module.GetModuleInstance()*/, szTempPath, MAX_PATH))
  1460. {
  1461. if ((MyGetFileVersion(szTempPath, lpGatherInfo)) != ERROR_SUCCESS)
  1462. {
  1463. return (GetLastError());
  1464. }
  1465. }
  1466. else
  1467. return( GetLastError() );
  1468. // 2/20/97 jmazner Olympus #259
  1469. if ( RegOpenKey(HKEY_LOCAL_MACHINE, ICWSETTINGSPATH,&hkey) == ERROR_SUCCESS)
  1470. {
  1471. DWORD dwSize;
  1472. DWORD dwType;
  1473. dwType = REG_SZ;
  1474. dwSize = BYTES_REQUIRED_BY_CCH(MAX_RELPROD + 1);
  1475. if (RegQueryValueEx(hkey, RELEASEPRODUCTKEY,NULL,&dwType,(LPBYTE)&lpGatherInfo->m_szRelProd[0],&dwSize) != ERROR_SUCCESS)
  1476. lpGatherInfo->m_szRelProd[0] = L'\0';
  1477. dwSize = BYTES_REQUIRED_BY_CCH(MAX_RELVER + 1);
  1478. if (RegQueryValueEx(hkey, RELEASEVERSIONKEY,NULL,&dwType,(LPBYTE)&lpGatherInfo->m_szRelVer[0],&dwSize) != ERROR_SUCCESS)
  1479. lpGatherInfo->m_szRelVer[0] = L'\0';
  1480. RegCloseKey(hkey);
  1481. }
  1482. // PromoCode
  1483. lpGatherInfo->m_szPromo[0] = L'\0';
  1484. WCHAR szPIDPath[MAX_PATH]; // Reg path to the PID
  1485. // Form the Path, it is HKLM\\Software\\Microsoft\Windows[ NT]\\CurrentVersion
  1486. lstrcpy(szPIDPath, L"");
  1487. // Form the Path, it is HKLM\\Software\\Microsoft\Windows[ NT]\\CurrentVersion
  1488. lstrcpy(szPIDPath, L"Software\\Microsoft\\Windows");
  1489. lstrcat(szPIDPath, L"\\CurrentVersion");
  1490. BYTE byDigitalPID[MAX_DIGITAL_PID];
  1491. // Get the Product ID for this machine
  1492. if ( RegOpenKey(HKEY_LOCAL_MACHINE, szPIDPath,&hkey) == ERROR_SUCCESS)
  1493. {
  1494. DWORD dwSize;
  1495. DWORD dwType;
  1496. dwType = REG_BINARY;
  1497. dwSize = sizeof(byDigitalPID);
  1498. if (RegQueryValueEx(hkey,
  1499. c_szRegStrValDigitalPID,
  1500. NULL,
  1501. &dwType,
  1502. (LPBYTE)byDigitalPID,
  1503. &dwSize) == ERROR_SUCCESS)
  1504. {
  1505. // BINHEX the digital PID data so we can send it to the ref_server
  1506. int i = 0;
  1507. BYTE by;
  1508. for (DWORD dwX = 0; dwX < dwSize; dwX++)
  1509. {
  1510. by = byDigitalPID[dwX];
  1511. m_szPID[i++] = g_BINTOHEXLookup[((by & 0xF0) >> 4)];
  1512. m_szPID[i++] = g_BINTOHEXLookup[(by & 0x0F)];
  1513. }
  1514. m_szPID[i] = L'\0';
  1515. }
  1516. else
  1517. {
  1518. m_szPID[0] = L'\0';
  1519. }
  1520. RegCloseKey(hkey);
  1521. }
  1522. return( dwRet );
  1523. }
  1524. // ############################################################################
  1525. HRESULT CRefDial::CreateEntryFromDUNFile(LPWSTR pszDunFile)
  1526. {
  1527. WCHAR szFileName[MAX_PATH];
  1528. WCHAR szUserName[UNLEN+1];
  1529. WCHAR szPassword[PWLEN+1];
  1530. LPWSTR pszTemp;
  1531. HRESULT hr;
  1532. BOOL fNeedsRestart=FALSE;
  1533. hr = ERROR_SUCCESS;
  1534. // Get fully qualified path name
  1535. //
  1536. if (!SearchPath(NULL, pszDunFile,NULL,MAX_PATH,&szFileName[0],&pszTemp))
  1537. {
  1538. hr = ERROR_FILE_NOT_FOUND;
  1539. goto CreateEntryFromDUNFileExit;
  1540. }
  1541. // save current DUN file name in global
  1542. lstrcpy(m_szCurrentDUNFile, &szFileName[0]);
  1543. hr = m_ISPImport.ImportConnection (&szFileName[0], m_szISPSupportNumber, m_szEntryName, szUserName, szPassword, &fNeedsRestart);
  1544. // place the name of the connectoid in the registry
  1545. //
  1546. if (ERROR_SUCCESS != (StoreInSignUpReg((LPBYTE)m_szEntryName,
  1547. BYTES_REQUIRED_BY_SZ(m_szEntryName),
  1548. REG_SZ, RASENTRYVALUENAME)))
  1549. {
  1550. goto CreateEntryFromDUNFileExit;
  1551. }
  1552. lstrcpy(m_szLastDUNFile, pszDunFile);
  1553. CreateEntryFromDUNFileExit:
  1554. return hr;
  1555. }
  1556. HRESULT CRefDial::SetupForRASDialing
  1557. (
  1558. LPGATHERINFO lpGatherInfo,
  1559. HINSTANCE hPHBKDll,
  1560. LPDWORD lpdwPhoneBook,
  1561. PSUGGESTINFO pSuggestInfo,
  1562. WCHAR *pszConnectoid,
  1563. BOOL FAR *bConnectiodCreated
  1564. )
  1565. {
  1566. WCHAR szEntry[MAX_RASENTRYNAME];
  1567. DWORD dwSize = BYTES_REQUIRED_BY_CCH(MAX_RASENTRYNAME);
  1568. RASENTRY *prasentry = NULL;
  1569. RASDEVINFO *prasdevinfo = NULL;
  1570. DWORD dwRasentrySize = 0;
  1571. DWORD dwRasdevinfoSize = 0;
  1572. HINSTANCE hRasDll = NULL;
  1573. LPRASCONN lprasconn = NULL;
  1574. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1575. m_bUserInitiateHangup = FALSE;
  1576. // Load the connectoid
  1577. //
  1578. if (!m_pcRNA)
  1579. m_pcRNA = new RNAAPI;
  1580. if (!m_pcRNA)
  1581. goto SetupForRASDialingExit;
  1582. prasentry = (RASENTRY*)GlobalAlloc(GPTR, sizeof(RASENTRY)+2);
  1583. //Assert(prasentry);
  1584. if (!prasentry)
  1585. {
  1586. hr = GetLastError();
  1587. goto SetupForRASDialingExit;
  1588. }
  1589. prasentry->dwSize = sizeof(RASENTRY);
  1590. dwRasentrySize = sizeof(RASENTRY);
  1591. prasdevinfo = (RASDEVINFO*)GlobalAlloc(GPTR, sizeof(RASDEVINFO));
  1592. if (!prasdevinfo)
  1593. {
  1594. hr = GetLastError();
  1595. goto SetupForRASDialingExit;
  1596. }
  1597. prasdevinfo->dwSize = sizeof(RASDEVINFO);
  1598. dwRasdevinfoSize = sizeof(RASDEVINFO);
  1599. hr = ReadSignUpReg((LPBYTE)&szEntry[0], &dwSize, REG_SZ,
  1600. RASENTRYVALUENAME);
  1601. if (hr != ERROR_SUCCESS)
  1602. goto SetupForRASDialingExit;
  1603. hr = m_pcRNA->RasGetEntryProperties(NULL, szEntry,
  1604. (LPBYTE)prasentry,
  1605. &dwRasentrySize,
  1606. (LPBYTE)prasdevinfo,
  1607. &dwRasdevinfoSize);
  1608. if (hr == ERROR_BUFFER_TOO_SMALL)
  1609. {
  1610. GlobalFree(prasentry);
  1611. prasentry = (RASENTRY*)GlobalAlloc(GPTR, ((size_t)dwRasentrySize));
  1612. prasentry->dwSize = dwRasentrySize;
  1613. GlobalFree(prasdevinfo);
  1614. prasdevinfo = (RASDEVINFO*)GlobalAlloc(GPTR, ((size_t)dwRasdevinfoSize));
  1615. prasdevinfo->dwSize = dwRasdevinfoSize;
  1616. hr = m_pcRNA->RasGetEntryProperties(NULL, szEntry,
  1617. (LPBYTE)prasentry,
  1618. &dwRasentrySize,
  1619. (LPBYTE)prasdevinfo,
  1620. &dwRasdevinfoSize);
  1621. }
  1622. if (hr != ERROR_SUCCESS)
  1623. goto SetupForRASDialingExit;
  1624. //
  1625. // Check to see if the phone number was filled in
  1626. //
  1627. if (lstrcmp(&prasentry->szLocalPhoneNumber[0], DUN_NOPHONENUMBER) == 0)
  1628. {
  1629. //
  1630. // If phonenumber is not filled in by the ISP file,
  1631. // get phone number from oobe phone book
  1632. //
  1633. m_bFromPhoneBook = TRUE;
  1634. hr = ReadPhoneBook(lpGatherInfo, pSuggestInfo);
  1635. }
  1636. else
  1637. {
  1638. ZeroMemory(pszConnectoid, dwSize);
  1639. hr = ReadSignUpReg((LPBYTE)pszConnectoid, &dwSize, REG_SZ,
  1640. RASENTRYVALUENAME);
  1641. if (hr != ERROR_SUCCESS)
  1642. goto SetupForRASDialingExit;
  1643. // Use the RASENTRY that we have to create the connectiod
  1644. hr = m_pcRNA->RasSetEntryProperties(NULL,
  1645. pszConnectoid,
  1646. (LPBYTE)prasentry,
  1647. dwRasentrySize,
  1648. (LPBYTE)prasdevinfo,
  1649. dwRasdevinfoSize);
  1650. *bConnectiodCreated = TRUE;
  1651. }
  1652. SetupForRASDialingExit:
  1653. if (prasentry)
  1654. GlobalFree(prasentry);
  1655. if (prasdevinfo)
  1656. GlobalFree(prasdevinfo);
  1657. return hr;
  1658. }
  1659. // 10/22/96 jmazner Normandy #9923
  1660. // Since in SetupConnectoidExit we're treating results other than ERROR_SUCCESS as
  1661. // indicating successfull completion, we need bSuccess to provide a simple way for the
  1662. // caller to tell whether the function completed.
  1663. HRESULT CRefDial::SetupConnectoid
  1664. (
  1665. PSUGGESTINFO pSuggestInfo,
  1666. int irc,
  1667. WCHAR *pszConnectoid,
  1668. DWORD dwSize,
  1669. BOOL *pbSuccess
  1670. )
  1671. {
  1672. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  1673. RASENTRY *prasentry = NULL;
  1674. RASDEVINFO *prasdevinfo = NULL;
  1675. DWORD dwRasentrySize = 0;
  1676. DWORD dwRasdevinfoSize = 0;
  1677. HINSTANCE hPHBKDll = NULL;
  1678. HINSTANCE hRasDll =NULL;
  1679. LPWSTR lpszSetupFile;
  1680. LPRASCONN lprasconn = NULL;
  1681. //Assert(pbSuccess);
  1682. if (!pSuggestInfo)
  1683. {
  1684. hr = ERROR_PHBK_NOT_FOUND;
  1685. goto SetupConnectoidExit;
  1686. }
  1687. lpszSetupFile = *m_szCurrentDUNFile != 0 ? m_szCurrentDUNFile : m_szISPFile;
  1688. WCHAR szFileName[MAX_PATH];
  1689. LPWSTR pszTemp;
  1690. SearchPath(NULL, pSuggestInfo->AccessEntry.szDataCenter,NULL,MAX_PATH,&szFileName[0],&pszTemp);
  1691. if(0 != lstrcmpi(m_szCurrentDUNFile, szFileName))
  1692. {
  1693. hr = CreateEntryFromDUNFile(pSuggestInfo->AccessEntry.szDataCenter);
  1694. if (hr == ERROR_SUCCESS)
  1695. {
  1696. ZeroMemory(pszConnectoid, dwSize);
  1697. hr = ReadSignUpReg((LPBYTE)pszConnectoid, &dwSize, REG_SZ,
  1698. RASENTRYVALUENAME);
  1699. if (hr != ERROR_SUCCESS)
  1700. goto SetupConnectoidExit;
  1701. if( prasentry )
  1702. {
  1703. GlobalFree( prasentry );
  1704. prasentry = NULL;
  1705. dwRasentrySize = NULL;
  1706. }
  1707. if( prasdevinfo )
  1708. {
  1709. GlobalFree( prasdevinfo );
  1710. prasdevinfo = NULL;
  1711. dwRasdevinfoSize = NULL;
  1712. }
  1713. }
  1714. else
  1715. {
  1716. // 10/22/96 jmazner Normandy #9923
  1717. goto SetupConnectoidExit;
  1718. }
  1719. }
  1720. hr = MyRasGetEntryProperties(NULL,
  1721. pszConnectoid,
  1722. &prasentry,
  1723. &dwRasentrySize,
  1724. &prasdevinfo,
  1725. &dwRasdevinfoSize);
  1726. if (hr != ERROR_SUCCESS || NULL == prasentry)
  1727. goto SetupConnectoidExit;
  1728. /*
  1729. else
  1730. {
  1731. goto SetupConnectoidExit;
  1732. }*/
  1733. prasentry->dwCountryID = pSuggestInfo->AccessEntry.dwCountryID;
  1734. lstrcpyn(prasentry->szAreaCode,
  1735. pSuggestInfo->AccessEntry.szAreaCode,
  1736. MAX_CHARS_IN_BUFFER(prasentry->szAreaCode));
  1737. lstrcpyn(prasentry->szLocalPhoneNumber,
  1738. pSuggestInfo->AccessEntry.szAccessNumber,
  1739. MAX_CHARS_IN_BUFFER(prasentry->szLocalPhoneNumber));
  1740. prasentry->dwCountryCode = 0;
  1741. prasentry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  1742. // 10/19/96 jmazner Multiple modems problems
  1743. // If no device name and type has been specified, grab the one we've stored
  1744. // in ConfigRasEntryDevice
  1745. if( 0 == lstrlen(prasentry->szDeviceName) )
  1746. {
  1747. // doesn't make sense to have an empty device name but a valid device type
  1748. //Assert( 0 == lstrlen(prasentry->szDeviceType) );
  1749. // double check that we've already stored the user's choice.
  1750. //Assert( lstrlen(m_ISPImport.m_szDeviceName) );
  1751. //Assert( lstrlen(m_ISPImport.m_szDeviceType) );
  1752. lstrcpyn( prasentry->szDeviceName, m_ISPImport.m_szDeviceName, lstrlen(m_ISPImport.m_szDeviceName) );
  1753. lstrcpyn( prasentry->szDeviceType, m_ISPImport.m_szDeviceType, lstrlen(m_ISPImport.m_szDeviceType) );
  1754. }
  1755. // Write out new connectoid
  1756. if (m_pcRNA)
  1757. hr = m_pcRNA->RasSetEntryProperties(NULL, pszConnectoid,
  1758. (LPBYTE)prasentry,
  1759. dwRasentrySize,
  1760. (LPBYTE)prasdevinfo,
  1761. dwRasdevinfoSize);
  1762. // Set this connetiod to have not proxy enabled
  1763. /*
  1764. WCHAR szConnectionProfile[REGSTR_MAX_VALUE_LENGTH];
  1765. lstrcpy(szConnectionProfile, c_szRASProfiles);
  1766. lstrcat(szConnectionProfile, L"\\");
  1767. lstrcat(szConnectionProfile, pszConnectoid);
  1768. reg.CreateKey(HKEY_CURRENT_USER, szConnectionProfile);
  1769. reg.SetValue(c_szProxyEnable, (DWORD)0);*/
  1770. SetupConnectoidExit:
  1771. *pbSuccess = FALSE;
  1772. if (hr == ERROR_SUCCESS)
  1773. *pbSuccess = TRUE;
  1774. return hr;
  1775. }
  1776. void CRefDial::GetISPFileSettings(LPWSTR lpszFile)
  1777. {
  1778. WCHAR szTemp[INTERNET_MAX_URL_LENGTH];
  1779. /*GetINTFromISPFile(lpszFile,
  1780. (LPWSTR)cszBrandingSection,
  1781. (LPWSTR)cszBrandingFlags,
  1782. (int FAR *)&m_lBrandingFlags,
  1783. BRAND_DEFAULT);*/
  1784. // Read the Support Number
  1785. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1786. (LPWSTR)cszSupportSection,
  1787. (LPWSTR)cszSupportNumber,
  1788. szTemp,
  1789. MAX_CHARS_IN_BUFFER(szTemp)))
  1790. {
  1791. m_bstrSupportNumber= SysAllocString(szTemp);
  1792. }
  1793. else
  1794. m_bstrSupportNumber = NULL;
  1795. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1796. (LPWSTR)cszLoggingSection,
  1797. (LPWSTR)cszStartURL,
  1798. szTemp,
  1799. MAX_CHARS_IN_BUFFER(szTemp)))
  1800. {
  1801. m_bstrLoggingStartUrl = SysAllocString(szTemp);
  1802. }
  1803. else
  1804. m_bstrLoggingStartUrl = NULL;
  1805. if (ERROR_SUCCESS == GetDataFromISPFile(lpszFile,
  1806. (LPWSTR)cszLoggingSection,
  1807. (LPWSTR)cszEndURL,
  1808. szTemp,
  1809. MAX_CHARS_IN_BUFFER(szTemp)))
  1810. {
  1811. m_bstrLoggingEndUrl = SysAllocString(szTemp);
  1812. }
  1813. else
  1814. m_bstrLoggingEndUrl = NULL;
  1815. }
  1816. // This function will accept user selected values that are necessary to
  1817. // setup a connectiod for dialing
  1818. // Returns:
  1819. // TRUE OK to dial
  1820. // FALSE Some kind of problem
  1821. // QuitWizard - TRUE, then terminate
  1822. // UserPickNumber - TRUE, then display Pick a Number DLG
  1823. // QuitWizard and UserPickNumber both FALSE, then just
  1824. // display the page prior to Dialing UI.
  1825. HRESULT CRefDial::SetupForDialing
  1826. (
  1827. UINT nType,
  1828. BSTR bstrISPFile,
  1829. DWORD dwCountry,
  1830. BSTR bstrAreaCode,
  1831. DWORD dwFlag,
  1832. DWORD dwAppMode,
  1833. DWORD dwMigISPIdx,
  1834. LPCWSTR szRasDeviceName
  1835. )
  1836. {
  1837. HRESULT hr = S_OK;
  1838. long lRC = 0;
  1839. HINSTANCE hPHBKDll = NULL;
  1840. DWORD dwPhoneBook = 0;
  1841. BOOL bSuccess = FALSE;
  1842. BOOL bConnectiodCreated = FALSE;
  1843. LPWSTR pszTemp;
  1844. WCHAR szISPPath[MAX_PATH];
  1845. WCHAR szShortISPPath[MAX_PATH];
  1846. m_dwCnType = nType;
  1847. if (!bstrAreaCode)
  1848. goto SetupForDialingExit;
  1849. if (CONNECTED_ISP_MIGRATE == m_dwCnType) // ACCOUNT MIGRATION
  1850. {
  1851. if (!m_pCSVList)
  1852. ParseISPInfo(NULL, ICW_ISPINFOPath, TRUE);
  1853. if (m_pCSVList && (dwMigISPIdx < m_dwNumOfAutoConfigOffers))
  1854. {
  1855. ISPLIST* pCurr = m_pCSVList;
  1856. for( UINT i = 0; i < dwMigISPIdx && pCurr->pNext != NULL; i++)
  1857. pCurr = pCurr->pNext;
  1858. if (NULL != (m_pSelectedISPInfo = (CISPCSV *) pCurr->pElement))
  1859. {
  1860. lstrcpy(szShortISPPath, m_pSelectedISPInfo->get_szISPFilePath());
  1861. }
  1862. }
  1863. }
  1864. else // ISP FILE SIGNUP
  1865. {
  1866. if (!bstrISPFile)
  1867. goto SetupForDialingExit;
  1868. lstrcpyn(szShortISPPath, bstrISPFile, MAX_PATH);
  1869. }
  1870. // Locate ISP file
  1871. if (!SearchPath(NULL, szShortISPPath,INF_SUFFIX,MAX_PATH,szISPPath,&pszTemp))
  1872. {
  1873. hr = ERROR_FILE_NOT_FOUND;
  1874. goto SetupForDialingExit;
  1875. }
  1876. if(0 == lstrcmpi(m_szISPFile, szISPPath) &&
  1877. 0 == lstrcmpi(m_lpGatherInfo->m_szAreaCode, bstrAreaCode) &&
  1878. m_lpGatherInfo->m_dwCountryID == dwCountry)
  1879. {
  1880. if (m_bDialCustom)
  1881. {
  1882. m_bDialCustom = FALSE;
  1883. return S_OK;
  1884. }
  1885. // If ISP file is the same, no need to recreate connectoid
  1886. // Modify the connectiod here
  1887. // If we used the phonebook for this connectoid, we need to
  1888. // continue and import the dun files. Otherwise, we are done
  1889. if (!m_lpGatherInfo->m_bUsePhbk)
  1890. {
  1891. return S_OK;
  1892. }
  1893. if (m_bDialAlternative)
  1894. {
  1895. m_SuggestInfo.dwPick++;
  1896. }
  1897. }
  1898. else
  1899. {
  1900. BOOL bRet;
  1901. RemoveConnectoid(&bRet);
  1902. m_SuggestInfo.dwPick = 0;
  1903. m_bDialCustom = FALSE;
  1904. }
  1905. if (CONNECTED_REFFERAL == m_dwCnType)
  1906. {
  1907. // Check whether the isp file is ICW capable by reading the referral URL
  1908. GetPrivateProfileString(INF_SECTION_ISPINFO,
  1909. c_szURLReferral,
  1910. L"",
  1911. m_szRefServerURL,
  1912. INTERNET_MAX_URL_LENGTH,
  1913. szISPPath);
  1914. }
  1915. lstrcpy(m_szISPFile, szISPPath);
  1916. m_dwAppMode = dwAppMode;
  1917. // Initialize failure codes
  1918. m_bQuitWizard = FALSE;
  1919. m_bUserPickNumber = FALSE;
  1920. m_lpGatherInfo->m_bUsePhbk = FALSE;
  1921. // Stuff the Area Code, and Country Code into the GatherInfo struct
  1922. m_lpGatherInfo->m_dwCountryID = dwCountry;
  1923. m_lpGatherInfo->m_dwCountryCode = dwFlag;
  1924. lstrcpyn(
  1925. m_lpGatherInfo->m_szAreaCode,
  1926. bstrAreaCode,
  1927. MAX_CHARS_IN_BUFFER(m_lpGatherInfo->m_szAreaCode)
  1928. );
  1929. m_SuggestInfo.AccessEntry.dwCountryID = dwCountry;
  1930. m_SuggestInfo.AccessEntry.dwCountryCode = dwFlag;
  1931. lstrcpy(m_SuggestInfo.AccessEntry.szAreaCode, bstrAreaCode);
  1932. GetISPFileSettings(szISPPath);
  1933. lstrcpyn(
  1934. m_ISPImport.m_szDeviceName,
  1935. szRasDeviceName,
  1936. MAX_CHARS_IN_BUFFER(m_ISPImport.m_szDeviceName)
  1937. );
  1938. // Read the Connection File information which will create
  1939. // a connectiod from the passed in ISP file
  1940. hr = ReadConnectionInformation();
  1941. // If we failed for some reason above, we need to return
  1942. // the error to the caller, and Quit The Wizard.
  1943. if (S_OK != hr)
  1944. goto SetupForDialingExit;
  1945. FillGatherInfoStruct(m_lpGatherInfo);
  1946. // Setup, and possible create a connectiod
  1947. hr = SetupForRASDialing(m_lpGatherInfo,
  1948. hPHBKDll,
  1949. &dwPhoneBook,
  1950. &m_SuggestInfo,
  1951. &m_szConnectoid[0],
  1952. &bConnectiodCreated);
  1953. if (ERROR_SUCCESS != hr)
  1954. {
  1955. m_bQuitWizard = TRUE;
  1956. goto SetupForDialingExit;
  1957. }
  1958. // If we have a RASENTRY struct from SetupForRASDialing, then just use it
  1959. // otherwise use the suggest info
  1960. if (!bConnectiodCreated)
  1961. {
  1962. // If there is only 1 suggested number, then we setup the
  1963. // connectiod, and we are ready to dial
  1964. if (1 == m_SuggestInfo.wNumber)
  1965. {
  1966. hr = SetupConnectoid(&m_SuggestInfo, 0, &m_szConnectoid[0],
  1967. sizeof(m_szConnectoid), &bSuccess);
  1968. if( !bSuccess )
  1969. {
  1970. goto SetupForDialingExit;
  1971. }
  1972. }
  1973. else
  1974. {
  1975. // More than 1 entry in the Phonebook, so we need to
  1976. // ask the user which one they want to use
  1977. hr = ERROR_FILE_NOT_FOUND;
  1978. goto SetupForDialingExit;
  1979. }
  1980. }
  1981. // Success if we get to here
  1982. SetupForDialingExit:
  1983. if (ERROR_SUCCESS != hr)
  1984. *m_szISPFile = 0;
  1985. return hr;
  1986. }
  1987. HRESULT CRefDial::CheckPhoneBook
  1988. (
  1989. BSTR bstrISPFile,
  1990. DWORD dwCountry,
  1991. BSTR bstrAreaCode,
  1992. DWORD dwFlag,
  1993. BOOL *pbRetVal
  1994. )
  1995. {
  1996. HRESULT hr = S_OK;
  1997. long lRC = 0;
  1998. HINSTANCE hPHBKDll = NULL;
  1999. DWORD dwPhoneBook = 0;
  2000. BOOL bSuccess = FALSE;
  2001. BOOL bConnectiodCreated = FALSE;
  2002. LPWSTR pszTemp;
  2003. WCHAR szISPPath[MAX_PATH];
  2004. *pbRetVal = FALSE;
  2005. if (!bstrISPFile || !bstrAreaCode)
  2006. {
  2007. hr = ERROR_FILE_NOT_FOUND;
  2008. goto CheckPhoneBookExit;
  2009. }
  2010. // Locate ISP file
  2011. if (!SearchPath(NULL, bstrISPFile,INF_SUFFIX,MAX_PATH,szISPPath,&pszTemp))
  2012. {
  2013. hr = ERROR_FILE_NOT_FOUND;
  2014. goto CheckPhoneBookExit;
  2015. }
  2016. //lstrcpy(m_szISPFile, szISPPath);
  2017. // Stuff the Area Code, and Country Code into the GatherInfo struct
  2018. m_lpGatherInfo->m_dwCountryID = dwCountry;
  2019. m_lpGatherInfo->m_dwCountryCode = dwFlag;
  2020. lstrcpy(m_lpGatherInfo->m_szAreaCode, bstrAreaCode);
  2021. m_SuggestInfo.AccessEntry.dwCountryID = dwCountry;
  2022. m_SuggestInfo.AccessEntry.dwCountryCode = dwFlag;
  2023. lstrcpy(m_SuggestInfo.AccessEntry.szAreaCode, bstrAreaCode);
  2024. //
  2025. // If phonenumber is not filled in by the ISP file,
  2026. // get phone number from oobe phone book
  2027. //
  2028. hr = ReadPhoneBook(m_lpGatherInfo, &m_SuggestInfo);
  2029. if (ERROR_CANNOT_FIND_PHONEBOOK_ENTRY != hr)
  2030. *pbRetVal = TRUE;
  2031. CheckPhoneBookExit:
  2032. return hr;
  2033. }
  2034. // This function will determine if we can connect to the next server in
  2035. // the same phone call
  2036. // Returns:
  2037. // S_OK OK to stay connected
  2038. // E_FAIL Need to redial
  2039. HRESULT CRefDial::CheckStayConnected(BSTR bstrISPFile, BOOL *pbVal)
  2040. {
  2041. BOOL bSuccess = FALSE;
  2042. LPWSTR pszTemp;
  2043. WCHAR szISPPath[MAX_PATH];
  2044. *pbVal = FALSE;
  2045. // Locate ISP file
  2046. if (SearchPath(NULL, bstrISPFile,INF_SUFFIX,MAX_PATH,szISPPath,&pszTemp))
  2047. {
  2048. if (GetPrivateProfileInt(INF_SECTION_CONNECTION,
  2049. c_szStayConnected,
  2050. 0,
  2051. szISPPath))
  2052. {
  2053. *pbVal = TRUE;
  2054. }
  2055. }
  2056. return S_OK;
  2057. }
  2058. HRESULT CRefDial::RemoveConnectoid(BOOL * pVal)
  2059. {
  2060. if (m_hrasconn)
  2061. DoHangup();
  2062. if( (m_pcRNA!=NULL) && (m_szConnectoid[0]!=L'\0') )
  2063. {
  2064. m_pcRNA->RasDeleteEntry(NULL, m_szConnectoid);
  2065. }
  2066. return S_OK;
  2067. }
  2068. HRESULT CRefDial::GetDialPhoneNumber(BSTR * pVal)
  2069. {
  2070. if (pVal == NULL)
  2071. return E_POINTER;
  2072. // Generate a Displayable number
  2073. if (GetDisplayableNumber() == ERROR_SUCCESS)
  2074. *pVal = SysAllocString(m_pszDisplayable);
  2075. else
  2076. *pVal = SysAllocString(m_szPhoneNumber);
  2077. return S_OK;
  2078. }
  2079. HRESULT CRefDial::GetPhoneBookNumber(BSTR * pVal)
  2080. {
  2081. if (pVal == NULL)
  2082. return E_POINTER;
  2083. // Generate a Displayable number
  2084. if (m_pszOriginalDisplayable)
  2085. *pVal = SysAllocString(m_pszOriginalDisplayable);
  2086. else if (GetDisplayableNumber() == ERROR_SUCCESS)
  2087. *pVal = SysAllocString(m_pszDisplayable);
  2088. else
  2089. *pVal = SysAllocString(m_szPhoneNumber);
  2090. return S_OK;
  2091. }
  2092. HRESULT CRefDial::PutDialPhoneNumber(BSTR bstrNewVal)
  2093. {
  2094. LPRASENTRY lpRasEntry = NULL;
  2095. LPRASDEVINFO lpRasDevInfo = NULL;
  2096. DWORD dwRasEntrySize = 0;
  2097. DWORD dwRasDevInfoSize = 0;
  2098. RNAAPI *pcRNA = NULL;
  2099. HRESULT hr;
  2100. // Get the current RAS entry properties
  2101. hr = MyRasGetEntryProperties(NULL,
  2102. m_szConnectoid,
  2103. &lpRasEntry,
  2104. &dwRasEntrySize,
  2105. &lpRasDevInfo,
  2106. &dwRasDevInfoSize);
  2107. if (NULL ==lpRasDevInfo)
  2108. {
  2109. dwRasDevInfoSize = 0;
  2110. }
  2111. if (hr == ERROR_SUCCESS && NULL != lpRasEntry)
  2112. {
  2113. // Replace the phone number with the new one
  2114. //
  2115. lstrcpy(lpRasEntry->szLocalPhoneNumber, bstrNewVal);
  2116. // non-zero dummy values are required due to bugs in win95
  2117. lpRasEntry->dwCountryID = 1;
  2118. lpRasEntry->dwCountryCode = 1;
  2119. lpRasEntry->szAreaCode[1] = L'\0';
  2120. lpRasEntry->szAreaCode[0] = L'8';
  2121. // Set to dial as is
  2122. //
  2123. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  2124. pcRNA = new RNAAPI;
  2125. if (pcRNA)
  2126. {
  2127. TRACE6(L"CRefDial::put_DialPhoneNumber - MyRasGetEntryProperties()"
  2128. L"lpRasEntry->dwfOptions: %ld"
  2129. L"lpRasEntry->dwCountryID: %ld"
  2130. L"lpRasEntry->dwCountryCode: %ld"
  2131. L"lpRasEntry->szAreaCode: %s"
  2132. L"lpRasEntry->szLocalPhoneNumber: %s"
  2133. L"lpRasEntry->dwAlternateOffset: %ld",
  2134. lpRasEntry->dwfOptions,
  2135. lpRasEntry->dwCountryID,
  2136. lpRasEntry->dwCountryCode,
  2137. lpRasEntry->szAreaCode,
  2138. lpRasEntry->szLocalPhoneNumber,
  2139. lpRasEntry->dwAlternateOffset
  2140. );
  2141. pcRNA->RasSetEntryProperties(NULL,
  2142. m_szConnectoid,
  2143. (LPBYTE)lpRasEntry,
  2144. dwRasEntrySize,
  2145. (LPBYTE)lpRasDevInfo,
  2146. dwRasDevInfoSize);
  2147. delete pcRNA;
  2148. m_bDialCustom = TRUE;
  2149. }
  2150. }
  2151. // Regenerate the displayable number
  2152. //GetDisplayableNumber();
  2153. return S_OK;
  2154. }
  2155. //+---------------------------------------------------------------------------
  2156. //
  2157. // Function: SetDialAlternative
  2158. //
  2159. // Synopsis: Set whether or not to look for another number in phonebook
  2160. // when dialing next time
  2161. //
  2162. //+---------------------------------------------------------------------------
  2163. HRESULT CRefDial::SetDialAlternative(BOOL bVal)
  2164. {
  2165. m_bDialAlternative = bVal;
  2166. return S_OK;
  2167. }
  2168. //+---------------------------------------------------------------------------
  2169. //
  2170. // Function: DoHangup
  2171. //
  2172. // Synopsis: Hangup the modem for the currently active RAS session
  2173. //
  2174. //+---------------------------------------------------------------------------
  2175. HRESULT CRefDial::DoHangup()
  2176. {
  2177. // Set the disconnect flag as the system may be too busy with dialing.
  2178. // Once we get a chance to terminate dialing, we know we have to hangu
  2179. EnterCriticalSection (&m_csMyCriticalSection);
  2180. // Your code to access the shared resource goes here.
  2181. TerminateConnMonitorThread();
  2182. if (NULL != m_hrasconn)
  2183. {
  2184. RNAAPI* pRNA = new RNAAPI();
  2185. if (pRNA)
  2186. {
  2187. pRNA->RasHangUp(m_hrasconn);
  2188. m_hrasconn = NULL;
  2189. delete pRNA;
  2190. }
  2191. }
  2192. // Release ownership of the critical section
  2193. LeaveCriticalSection (&m_csMyCriticalSection);
  2194. return (m_hrasconn == NULL) ? S_OK : E_POINTER;
  2195. }
  2196. BOOL CRefDial::get_QueryString(WCHAR* szTemp, DWORD cchMax)
  2197. {
  2198. WCHAR szOOBEInfoINIFile[MAX_PATH];
  2199. WCHAR szISPSignup[MAX_PATH];
  2200. WCHAR szOEMName[MAX_PATH];
  2201. WCHAR szQueryString[MAX_SECTIONS_BUFFER*2];
  2202. WCHAR szBroadbandDeviceName[MAX_STRING];
  2203. WCHAR szBroadbandDevicePnpid[MAX_STRING];
  2204. OSVERSIONINFO osvi;
  2205. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  2206. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  2207. if (!GetVersionEx(&osvi))
  2208. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  2209. if (VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId)
  2210. m_lpGatherInfo->m_dwOS = 1;
  2211. else if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
  2212. m_lpGatherInfo->m_dwOS = 2;
  2213. else
  2214. m_lpGatherInfo->m_dwOS = 0;
  2215. SearchPath(NULL, cszOOBEINFOINI, NULL, MAX_CHARS_IN_BUFFER(szOOBEInfoINIFile), szOOBEInfoINIFile, NULL);
  2216. DWORD dwOfferCode = 0;
  2217. if(m_dwAppMode == APMD_MSN)
  2218. {
  2219. lstrcpy(szISPSignup, L"MSN");
  2220. }
  2221. else
  2222. {
  2223. GetPrivateProfileString(cszSignup,
  2224. cszISPSignup,
  2225. L"",
  2226. szISPSignup,
  2227. MAX_CHARS_IN_BUFFER(szISPSignup),
  2228. szOOBEInfoINIFile);
  2229. dwOfferCode = GetPrivateProfileInt(cszSignup,
  2230. cszOfferCode,
  2231. 0,
  2232. szOOBEInfoINIFile);
  2233. }
  2234. GetPrivateProfileString(cszBranding,
  2235. cszOEMName,
  2236. L"",
  2237. szOEMName,
  2238. MAX_CHARS_IN_BUFFER(szOEMName),
  2239. szOOBEInfoINIFile);
  2240. GetPrivateProfileString(cszOptions,
  2241. cszBroadbandDeviceName,
  2242. L"",
  2243. szBroadbandDeviceName,
  2244. MAX_CHARS_IN_BUFFER(szBroadbandDeviceName),
  2245. szOOBEInfoINIFile);
  2246. GetPrivateProfileString(cszOptions,
  2247. cszBroadbandDevicePnpid,
  2248. L"",
  2249. szBroadbandDevicePnpid,
  2250. MAX_CHARS_IN_BUFFER(szBroadbandDevicePnpid),
  2251. szOOBEInfoINIFile);
  2252. //DT tells the ISP if the query is coming from fullscreen OOBE or the desktop (windowed) version of OOBE. DT=1 means desktop version, DT=0 means fullscreen.
  2253. INT nDT = (m_dwAppMode == APMD_OOBE) ? 0 : 1;
  2254. wsprintf(szQueryString, L"LCID=%lu&TCID=%lu&ISPSignup=%s&OfferCode=%lu&OS=%lu%&BUILD=%ld&DT=%lu&OEMName=%s&BroadbandDeviceName=%s&BroadbandDevicePnpid=%s",
  2255. GetUserDefaultUILanguage(),
  2256. m_lpGatherInfo->m_dwCountryID,
  2257. szISPSignup,
  2258. dwOfferCode,
  2259. m_lpGatherInfo->m_dwOS,
  2260. LOWORD(osvi.dwBuildNumber),
  2261. nDT,
  2262. szOEMName,
  2263. szBroadbandDeviceName,
  2264. szBroadbandDevicePnpid);
  2265. // Parse the ISP section in the INI file to find query pair to append
  2266. WCHAR *pszKeys = NULL;
  2267. PWSTR pszKey = NULL;
  2268. WCHAR szValue[MAX_PATH];
  2269. ULONG ulRetVal = 0;
  2270. BOOL bEnumerate = TRUE;
  2271. ULONG ulBufferSize = MAX_SECTIONS_BUFFER;
  2272. WCHAR szOobeinfoPath[MAX_PATH + 1];
  2273. //BUGBUG :: this search path is foir the same file as the previous one and is redundant.
  2274. SearchPath(NULL, cszOOBEINFOINI, NULL, MAX_PATH, szOobeinfoPath, NULL);
  2275. // Loop to find the appropriate buffer size to retieve the ins to memory
  2276. ulBufferSize = MAX_KEYS_BUFFER;
  2277. ulRetVal = 0;
  2278. if (!(pszKeys = (LPWSTR)GlobalAlloc(GPTR, ulBufferSize*sizeof(WCHAR)))) {
  2279. return FALSE;
  2280. }
  2281. while (ulRetVal < (ulBufferSize - 2))
  2282. {
  2283. ulRetVal = ::GetPrivateProfileString(cszISPQuery, NULL, L"", pszKeys, ulBufferSize, szOobeinfoPath);
  2284. if (0 == ulRetVal)
  2285. bEnumerate = FALSE;
  2286. if (ulRetVal < (ulBufferSize - 2))
  2287. {
  2288. break;
  2289. }
  2290. GlobalFree( pszKeys );
  2291. ulBufferSize += ulBufferSize;
  2292. pszKeys = (LPWSTR)GlobalAlloc(GPTR, ulBufferSize*sizeof(WCHAR));
  2293. if (!pszKeys)
  2294. {
  2295. bEnumerate = FALSE;
  2296. }
  2297. }
  2298. if (bEnumerate)
  2299. {
  2300. // Enumerate each key value pair in the section
  2301. pszKey = pszKeys;
  2302. while (*pszKey)
  2303. {
  2304. ulRetVal = ::GetPrivateProfileString(cszISPQuery, pszKey, L"", szValue, MAX_CHARS_IN_BUFFER(szValue), szOobeinfoPath);
  2305. if ((ulRetVal != 0) && (ulRetVal < MAX_CHARS_IN_BUFFER(szValue) - 1))
  2306. {
  2307. // Append query pair
  2308. wsprintf(szQueryString, L"%s&%s=%s", szQueryString, pszKey, szValue);
  2309. }
  2310. pszKey += lstrlen(pszKey) + 1;
  2311. }
  2312. }
  2313. if(GetPrivateProfileInt(INF_SECTION_URL,
  2314. ISP_MSNSIGNUP,
  2315. 0,
  2316. m_szISPFile))
  2317. {
  2318. lstrcat(szQueryString, QUERY_STRING_MSNSIGNUP);
  2319. }
  2320. if (pszKeys)
  2321. GlobalFree( pszKeys );
  2322. if (cchMax < (DWORD)lstrlen(szQueryString) + 1)
  2323. return FALSE;
  2324. lstrcpy(szTemp, szQueryString);
  2325. return TRUE;
  2326. }
  2327. HRESULT CRefDial::get_SignupURL(BSTR * pVal)
  2328. {
  2329. WCHAR szTemp[INTERNET_MAX_URL_LENGTH] = L"";
  2330. if (pVal == NULL)
  2331. return E_POINTER;
  2332. // Get the URL from the ISP file, and then convert it
  2333. if (SUCCEEDED(GetDataFromISPFile(m_szISPFile, INF_SECTION_URL, INF_SIGNUP_URL,&szTemp[0],INTERNET_MAX_URL_LENGTH)))
  2334. {
  2335. if(*szTemp)
  2336. {
  2337. WCHAR szUrl[INTERNET_MAX_URL_LENGTH];
  2338. WCHAR szQuery[MAX_PATH * 4] = L"\0";
  2339. get_QueryString(szQuery, MAX_CHARS_IN_BUFFER(szQuery));
  2340. wsprintf(szUrl, L"%s%s",
  2341. szTemp,
  2342. szQuery);
  2343. *pVal = SysAllocString(szUrl);
  2344. }
  2345. else
  2346. *pVal = NULL;
  2347. }
  2348. else
  2349. {
  2350. *pVal = NULL;
  2351. }
  2352. return S_OK;
  2353. }
  2354. //BUGBUG:: this should be combined with get_SignupURL
  2355. HRESULT CRefDial::get_ReconnectURL(BSTR * pVal)
  2356. {
  2357. WCHAR szTemp[INTERNET_MAX_URL_LENGTH] = L"\0";
  2358. if (pVal == NULL)
  2359. return E_POINTER;
  2360. // Get the URL from the ISP file, and then convert it
  2361. if (SUCCEEDED(GetDataFromISPFile(m_szISPFile, INF_SECTION_URL, INF_RECONNECT_URL,&szTemp[0],INTERNET_MAX_URL_LENGTH)))
  2362. {
  2363. WCHAR szUrl[INTERNET_MAX_URL_LENGTH];
  2364. WCHAR szQuery[MAX_PATH * 4] = L"\0";
  2365. DWORD dwErr = 0;
  2366. if(*szTemp)
  2367. {
  2368. get_QueryString(szQuery, MAX_CHARS_IN_BUFFER(szQuery));
  2369. if (m_dwRASErr)
  2370. dwErr = 1;
  2371. wsprintf(szUrl, L"%s%s&Error=%ld",
  2372. szTemp,
  2373. szQuery,
  2374. dwErr);
  2375. *pVal = SysAllocString(szUrl);
  2376. }
  2377. else
  2378. *pVal = NULL;
  2379. }
  2380. else
  2381. {
  2382. *pVal = NULL;
  2383. }
  2384. return S_OK;
  2385. }
  2386. HRESULT CRefDial::GetConnectionType(DWORD * pdwVal)
  2387. {
  2388. *pdwVal = m_dwConnectionType;
  2389. return S_OK;
  2390. }
  2391. HRESULT CRefDial::GetDialErrorMsg(BSTR * pVal)
  2392. {
  2393. if (pVal == NULL)
  2394. return E_POINTER;
  2395. return S_OK;
  2396. }
  2397. HRESULT CRefDial::GetSupportNumber(BSTR * pVal)
  2398. {
  2399. /*
  2400. WCHAR szSupportNumber[MAX_PATH];
  2401. if (pVal == NULL)
  2402. return E_POINTER;
  2403. if (m_SupportInfo.GetSupportInfo(szSupportNumber, m_dwCountryCode))
  2404. *pVal = SysAllocString(szSupportNumber);
  2405. else
  2406. *pVal = NULL;
  2407. */
  2408. return S_OK;
  2409. }
  2410. BOOL CRefDial::IsDBCSString( CHAR *sz )
  2411. {
  2412. if (!sz)
  2413. return FALSE;
  2414. while( NULL != *sz )
  2415. {
  2416. if (IsDBCSLeadByte(*sz)) return FALSE;
  2417. sz++;
  2418. }
  2419. return TRUE;
  2420. }
  2421. //+---------------------------------------------------------------------------
  2422. //
  2423. // Function: RasGetConnectStatus
  2424. //
  2425. // Synopsis: Checks for existing Ras connection; return TRUE for connected
  2426. // Return FALSE for disconnect.
  2427. //
  2428. //+---------------------------------------------------------------------------
  2429. HRESULT CRefDial::RasGetConnectStatus(BOOL *pVal)
  2430. {
  2431. HRESULT hr = E_FAIL;
  2432. *pVal = FALSE;
  2433. if (NULL != m_hrasconn)
  2434. {
  2435. RASCONNSTATUS rasConnectState;
  2436. rasConnectState.dwSize = sizeof(RASCONNSTATUS);
  2437. if (m_pcRNA)
  2438. {
  2439. if (0 == m_pcRNA->RasGetConnectStatus(m_hrasconn, &rasConnectState))
  2440. {
  2441. if (RASCS_Disconnected != rasConnectState.rasconnstate)
  2442. *pVal = TRUE;
  2443. }
  2444. hr = S_OK;
  2445. }
  2446. }
  2447. return hr;
  2448. }
  2449. //+---------------------------------------------------------------------------
  2450. //
  2451. // Function: DoOfferDownload
  2452. //
  2453. // Synopsis: Download the ISP offer from the ISP server
  2454. //
  2455. //+---------------------------------------------------------------------------
  2456. HRESULT CRefDial::DoOfferDownload(BOOL *pbRetVal)
  2457. {
  2458. HRESULT hr;
  2459. RNAAPI *pcRNA;
  2460. //
  2461. // Hide RNA window on Win95 retail
  2462. //
  2463. // MinimizeRNAWindow(m_pszConnectoid, g_hInst);
  2464. // 4/2/97 ChrisK Olympus 296
  2465. // g_hRNAZapperThread = LaunchRNAReestablishZapper(g_hInst);
  2466. //
  2467. // The connection is open and ready. Start the download.
  2468. //
  2469. m_dwThreadID = 0;
  2470. m_hThread = CreateThread(NULL,
  2471. 0,
  2472. (LPTHREAD_START_ROUTINE)DownloadThreadInit,
  2473. (LPVOID)this,
  2474. 0,
  2475. &m_dwThreadID);
  2476. // 5-1-97 ChrisK Olympus 2934
  2477. // m_objBusyMessages.Start(m_hWnd, IDC_LBLSTATUS,m_hrasconn);
  2478. // If we dont get the donwload thread, then kill the open
  2479. // connection
  2480. if (!m_hThread)
  2481. {
  2482. hr = GetLastError();
  2483. if (m_hrasconn)
  2484. {
  2485. pcRNA = new RNAAPI;
  2486. if (pcRNA)
  2487. {
  2488. pcRNA->RasHangUp(m_hrasconn);
  2489. m_hrasconn = NULL;
  2490. delete pcRNA;
  2491. pcRNA = NULL;
  2492. }
  2493. }
  2494. *pbRetVal = FALSE;
  2495. }
  2496. else
  2497. {
  2498. // Download has started.
  2499. m_bDownloadHasBeenCanceled = FALSE;
  2500. *pbRetVal = TRUE;
  2501. }
  2502. return S_OK;
  2503. }
  2504. // Form the Dialing URL. Must be called after setting up for dialing.
  2505. HRESULT CRefDial::FormReferralServerURL(BOOL * pbRetVal)
  2506. {
  2507. WCHAR szTemp[MAX_PATH] = L"\0";
  2508. WCHAR szPromo[MAX_PATH]= L"\0";
  2509. WCHAR szProd[MAX_PATH] = L"\0";
  2510. WCHAR szArea[MAX_PATH] = L"\0";
  2511. WCHAR szOEM[MAX_PATH] = L"\0";
  2512. DWORD dwCONNWIZVersion = 500; // Version of CONNWIZ.HTM
  2513. //
  2514. // ChrisK Olympus 3997 5/25/97
  2515. //
  2516. WCHAR szRelProd[MAX_PATH] = L"\0";
  2517. WCHAR szRelProdVer[MAX_PATH] = L"\0";
  2518. HRESULT hr = ERROR_SUCCESS;
  2519. OSVERSIONINFO osvi;
  2520. //
  2521. // Build URL complete with name value pairs
  2522. //
  2523. hr = GetDataFromISPFile(m_szISPFile, INF_SECTION_ISPINFO, INF_REFERAL_URL,&szTemp[0],256);
  2524. if (L'\0' == szTemp[0])
  2525. {
  2526. //MsgBox(IDS_MSNSU_WRONG, MB_MYERROR);
  2527. return hr;
  2528. }
  2529. //Assert(szTemp[0]);
  2530. Sz2URLValue(m_szOEM, szOEM,0);
  2531. Sz2URLValue(m_lpGatherInfo->m_szAreaCode, szArea,0);
  2532. if (m_bstrProductCode)
  2533. Sz2URLValue(m_bstrProductCode, szProd,0);
  2534. else
  2535. Sz2URLValue(DEFAULT_PRODUCTCODE, szProd,0);
  2536. if (m_bstrPromoCode)
  2537. Sz2URLValue(((BSTR)m_bstrPromoCode), szPromo,0);
  2538. else
  2539. Sz2URLValue(DEFAULT_PROMOCODE, szPromo,0);
  2540. //
  2541. // ChrisK Olympus 3997 5/25/97
  2542. //
  2543. Sz2URLValue(m_lpGatherInfo->m_szRelProd, szRelProd, 0);
  2544. Sz2URLValue(m_lpGatherInfo->m_szRelVer, szRelProdVer, 0);
  2545. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  2546. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  2547. if (!GetVersionEx(&osvi))
  2548. {
  2549. ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
  2550. }
  2551. // Autoconfig will set alloffers always.
  2552. if ( m_lAllOffers || (m_lpGatherInfo->m_dwFlag & ICW_CFGFLAG_AUTOCONFIG) )
  2553. {
  2554. m_lpGatherInfo->m_dwFlag |= ICW_CFGFLAG_ALLOFFERS;
  2555. }
  2556. wsprintf(m_szUrl, L"%slcid=%lu&sysdeflcid=%lu&appslcid=%lu&icwos=%lu&osver=%lu.%2.2d%s&arch=%u&promo=%s&oem=%s&area=%s&country=%lu&icwver=%s&prod=%s&osbld=%d&icwrp=%s&icwrpv=%s&wizver=%lu&PID=%s&cfgflag=%lu",
  2557. szTemp,
  2558. m_lpGatherInfo->m_lcidUser,
  2559. m_lpGatherInfo->m_lcidSys,
  2560. m_lpGatherInfo->m_lcidApps,
  2561. m_lpGatherInfo->m_dwOS,
  2562. m_lpGatherInfo->m_dwMajorVersion,
  2563. m_lpGatherInfo->m_dwMinorVersion,
  2564. ICW_OS_VER,
  2565. m_lpGatherInfo->m_wArchitecture,
  2566. szPromo,
  2567. szOEM,
  2568. szArea,
  2569. m_lpGatherInfo->m_dwCountryCode,
  2570. &m_lpGatherInfo->m_szSUVersion[0],
  2571. szProd,
  2572. LOWORD(osvi.dwBuildNumber),
  2573. szRelProd,
  2574. szRelProdVer,
  2575. dwCONNWIZVersion,
  2576. m_szPID,
  2577. m_lpGatherInfo->m_dwFlag);
  2578. StoreInSignUpReg(
  2579. (LPBYTE)m_lpGatherInfo,
  2580. sizeof(GATHERINFO),
  2581. REG_BINARY,
  2582. GATHERINFOVALUENAME);
  2583. return hr;
  2584. }
  2585. /*******************************************************************
  2586. NAME: ParseISPInfo
  2587. SYNOPSIS: Called when page is displayed
  2588. ENTRY: hDlg - dialog window
  2589. fFirstInit - TRUE if this is the first time the dialog
  2590. is initialized, FALSE if this InitProc has been called
  2591. before (e.g. went past this page and backed up)
  2592. ********************************************************************/
  2593. BOOL CRefDial::ParseISPInfo
  2594. (
  2595. HWND hDlg,
  2596. WCHAR *pszCSVFileName,
  2597. BOOL bCheckDupe
  2598. )
  2599. {
  2600. // On the first init, we will read the ISPINFO.CSV file, and populate the ISP LISTVIEW
  2601. CCSVFile far *pcCSVFile;
  2602. CISPCSV far *pcISPCSV;
  2603. BOOL bRet = TRUE;
  2604. BOOL bHaveCNSOffer = FALSE;
  2605. BOOL bISDNMode = FALSE;
  2606. HRESULT hr;
  2607. CleanISPList();
  2608. ISPLIST* pCurr = NULL;
  2609. DWORD dwCurrISPListSize = 1;
  2610. m_dwNumOfAutoConfigOffers = 0;
  2611. m_unSelectedISP = 0;
  2612. // Open and process the CSV file
  2613. pcCSVFile = new CCSVFile;
  2614. if (!pcCSVFile)
  2615. {
  2616. // BUGBUG: Show Error Message
  2617. return (FALSE);
  2618. }
  2619. if (!pcCSVFile->Open(pszCSVFileName))
  2620. {
  2621. // BUGBUG: Show Error Message
  2622. delete pcCSVFile;
  2623. pcCSVFile = NULL;
  2624. return (FALSE);
  2625. }
  2626. // Read the first line, since it contains field headers
  2627. pcISPCSV = new CISPCSV;
  2628. if (!pcISPCSV)
  2629. {
  2630. // BUGBUG Show error message
  2631. delete pcCSVFile;
  2632. return (FALSE);
  2633. }
  2634. if (ERROR_SUCCESS != (hr = pcISPCSV->ReadFirstLine(pcCSVFile)))
  2635. {
  2636. // Handle the error case
  2637. delete pcCSVFile;
  2638. pcCSVFile = NULL;
  2639. return (FALSE);
  2640. }
  2641. delete pcISPCSV; // Don't need this one any more
  2642. // Create the SELECT tag for the html so it can get all the country names in one shot.
  2643. if (m_pszISPList)
  2644. delete [] m_pszISPList;
  2645. m_pszISPList = new WCHAR[1024];
  2646. if (!m_pszISPList)
  2647. return FALSE;
  2648. memset(m_pszISPList, 0, sizeof(m_pszISPList));
  2649. do {
  2650. // Allocate a new ISP record
  2651. pcISPCSV = new CISPCSV;
  2652. if (!pcISPCSV)
  2653. {
  2654. // BUGBUG Show error message
  2655. bRet = FALSE;
  2656. break;
  2657. }
  2658. // Read a line from the ISPINFO file
  2659. hr = pcISPCSV->ReadOneLine(pcCSVFile);
  2660. if (hr == ERROR_SUCCESS)
  2661. {
  2662. // If this line contains a nooffer flag, then leave now
  2663. if (!(pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_OFFERS))
  2664. {
  2665. m_dwNumOfAutoConfigOffers = 0;
  2666. break;
  2667. }
  2668. if ((pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_AUTOCONFIG) &&
  2669. (bISDNMode ? (pcISPCSV->get_dwCFGFlag() & ICW_CFGFLAG_ISDN_OFFER) : TRUE) )
  2670. {
  2671. // Form the ISP list option tag for HTML
  2672. WCHAR szBuffer[MAX_PATH];
  2673. wsprintf(szBuffer, szOptionTag, pcISPCSV->get_szISPName());
  2674. DWORD dwSizeReq = (DWORD)lstrlen(m_pszISPList) + lstrlen(szBuffer) + 1;
  2675. if (dwCurrISPListSize < dwSizeReq)
  2676. {
  2677. WCHAR *szTemp = new WCHAR[dwSizeReq];
  2678. if (szTemp)
  2679. lstrcpy(szTemp, m_pszISPList);
  2680. dwCurrISPListSize = dwSizeReq;
  2681. delete [] m_pszISPList;
  2682. m_pszISPList = szTemp;
  2683. }
  2684. // Add the isp to the list.
  2685. if (m_pszISPList)
  2686. lstrcat(m_pszISPList, szBuffer);
  2687. if (m_pCSVList == NULL) // First one
  2688. {
  2689. // Add the CSV file object to the first node of linked list
  2690. ISPLIST* pNew = new ISPLIST;
  2691. pNew->pElement = pcISPCSV;
  2692. pNew->uElem = m_dwNumOfAutoConfigOffers;
  2693. pNew->pNext = NULL;
  2694. pCurr = pNew;
  2695. m_pCSVList = pCurr;
  2696. }
  2697. else
  2698. {
  2699. // Append CSV object to the end of list
  2700. ISPLIST* pNew = new ISPLIST;
  2701. pNew->pElement = pcISPCSV;
  2702. pNew->uElem = m_dwNumOfAutoConfigOffers;
  2703. pNew->pNext = NULL;
  2704. pCurr->pNext = pNew;
  2705. pCurr = pCurr->pNext;
  2706. }
  2707. ++m_dwNumOfAutoConfigOffers;
  2708. }
  2709. else
  2710. {
  2711. delete pcISPCSV;
  2712. }
  2713. }
  2714. else if (hr == ERROR_NO_MORE_ITEMS)
  2715. {
  2716. delete pcISPCSV; // We don't need this one
  2717. break;
  2718. }
  2719. else if (hr == ERROR_FILE_NOT_FOUND)
  2720. {
  2721. // do not show this ISP when its data is invalid
  2722. // we don't want to halt everything. Just let it contine
  2723. delete pcISPCSV;
  2724. }
  2725. else
  2726. {
  2727. // Show error message Later
  2728. delete pcISPCSV;
  2729. //iNumOfAutoConfigOffers = ISP_INFO_NO_VALIDOFFER;
  2730. bRet = FALSE;
  2731. break;
  2732. }
  2733. } while (TRUE);
  2734. delete pcCSVFile;
  2735. return bRet;
  2736. }
  2737. HRESULT CRefDial::GetISPList(BSTR* pbstrISPList)
  2738. {
  2739. if (pbstrISPList)
  2740. *pbstrISPList = NULL;
  2741. else
  2742. return E_FAIL;
  2743. if (!m_pszISPList)
  2744. {
  2745. ParseISPInfo(NULL, ICW_ISPINFOPath, TRUE);
  2746. }
  2747. if (m_pszISPList && *m_pszISPList)
  2748. {
  2749. *pbstrISPList = SysAllocString(m_pszISPList);
  2750. return S_OK;
  2751. }
  2752. return E_FAIL;
  2753. }
  2754. HRESULT CRefDial::Set_SelectISP(UINT nVal)
  2755. {
  2756. if (nVal < m_dwNumOfAutoConfigOffers)
  2757. {
  2758. m_unSelectedISP = nVal;
  2759. }
  2760. return S_OK;
  2761. }
  2762. HRESULT CRefDial::Set_ConnectionMode(UINT nVal)
  2763. {
  2764. if (nVal < m_dwNumOfAutoConfigOffers)
  2765. {
  2766. m_unSelectedISP = nVal;
  2767. }
  2768. return S_OK;
  2769. }
  2770. HRESULT CRefDial::Get_ConnectionMode(UINT *pnVal)
  2771. {
  2772. if (pnVal)
  2773. {
  2774. *pnVal = m_dwCnType;
  2775. return S_OK;
  2776. }
  2777. return E_FAIL;
  2778. }
  2779. HRESULT CRefDial::ProcessSignedPID(BOOL * pbRetVal)
  2780. {
  2781. HANDLE hfile;
  2782. DWORD dwFileSize;
  2783. DWORD dwBytesRead;
  2784. LPBYTE lpbSignedPID;
  2785. LPWSTR lpszSignedPID;
  2786. *pbRetVal = FALSE;
  2787. // Open the PID file for Binary Reading. It will be in the CWD
  2788. if (INVALID_HANDLE_VALUE != (hfile = CreateFile(c_szSignedPIDFName,
  2789. GENERIC_READ,
  2790. 0,
  2791. NULL,
  2792. OPEN_EXISTING,
  2793. FILE_ATTRIBUTE_NORMAL,
  2794. NULL)))
  2795. {
  2796. dwFileSize = GetFileSize(hfile, NULL);
  2797. // Allocate a buffer to read the file, and one to store the BINHEX version
  2798. lpbSignedPID = new BYTE[dwFileSize];
  2799. lpszSignedPID = new WCHAR[(dwFileSize * 2) + 1];
  2800. if (lpbSignedPID && lpszSignedPID)
  2801. {
  2802. if (ReadFile(hfile, (LPVOID) lpbSignedPID, dwFileSize, &dwBytesRead, NULL) &&
  2803. (dwFileSize == dwBytesRead))
  2804. {
  2805. // BINHEX the signed PID data so we can send it to the signup server
  2806. DWORD dwX = 0;
  2807. BYTE by;
  2808. for (DWORD dwY = 0; dwY < dwFileSize; dwY++)
  2809. {
  2810. by = lpbSignedPID[dwY];
  2811. lpszSignedPID[dwX++] = g_BINTOHEXLookup[((by & 0xF0) >> 4)];
  2812. lpszSignedPID[dwX++] = g_BINTOHEXLookup[(by & 0x0F)];
  2813. }
  2814. lpszSignedPID[dwX] = L'\0';
  2815. // Convert the signed pid to a BSTR
  2816. m_bstrSignedPID = SysAllocString(lpszSignedPID);
  2817. // Set the return value
  2818. *pbRetVal = TRUE;
  2819. }
  2820. }
  2821. // Free the buffers we allocated
  2822. if (lpbSignedPID)
  2823. {
  2824. delete[] lpbSignedPID;
  2825. }
  2826. if (lpszSignedPID)
  2827. {
  2828. delete[] lpszSignedPID;
  2829. }
  2830. // Close the File
  2831. CloseHandle(hfile);
  2832. #ifndef DEBUG
  2833. // Delete the File
  2834. // defer removal of this file until the container app exits.
  2835. // see BUG 373.
  2836. //DeleteFile(c_szSignedPIDFName);
  2837. #endif
  2838. }
  2839. return S_OK;
  2840. }
  2841. HRESULT CRefDial::get_SignedPID(BSTR * pVal)
  2842. {
  2843. if (pVal == NULL)
  2844. return E_POINTER;
  2845. *pVal = SysAllocString(m_bstrSignedPID);
  2846. return S_OK;
  2847. }
  2848. HRESULT CRefDial::get_ISDNAutoConfigURL(BSTR * pVal)
  2849. {
  2850. WCHAR szTemp[256];
  2851. if (pVal == NULL)
  2852. return E_POINTER;
  2853. // Get the URL from the ISP file, and then convert it
  2854. if (SUCCEEDED(GetDataFromISPFile(m_szISPFile, INF_SECTION_URL, INF_ISDN_AUTOCONFIG_URL,&szTemp[0],256)))
  2855. {
  2856. *pVal = SysAllocString(szTemp);
  2857. }
  2858. else
  2859. {
  2860. *pVal = NULL;
  2861. }
  2862. return S_OK;
  2863. }
  2864. HRESULT CRefDial::get_ISPName(BSTR * pVal)
  2865. {
  2866. if (m_pSelectedISPInfo)
  2867. {
  2868. *pVal = SysAllocString(m_pSelectedISPInfo->get_szISPName());
  2869. }
  2870. else
  2871. {
  2872. *pVal = NULL;
  2873. }
  2874. return S_OK;
  2875. }
  2876. HRESULT CRefDial::get_AutoConfigURL(BSTR * pVal)
  2877. {
  2878. WCHAR szTemp[256];
  2879. if (pVal == NULL)
  2880. return E_POINTER;
  2881. // Get the URL from the ISP file, and then convert it
  2882. if (SUCCEEDED(GetDataFromISPFile(m_szISPFile, INF_SECTION_URL, INF_AUTOCONFIG_URL,&szTemp[0],256)))
  2883. {
  2884. *pVal = SysAllocString(szTemp);
  2885. }
  2886. else
  2887. {
  2888. *pVal = NULL;
  2889. }
  2890. return S_OK;
  2891. }
  2892. HRESULT CRefDial::DownloadISPOffer(BOOL *pbVal, BSTR *pVal)
  2893. {
  2894. HRESULT hr = S_OK;
  2895. // Download the ISP file, and then copy its contents
  2896. // If Ras is complete
  2897. if (pbVal && pVal)
  2898. {
  2899. // Download the first page from Webgate
  2900. BSTR bstrURL = NULL;
  2901. BSTR bstrQueryURL = NULL;
  2902. BOOL bRet;
  2903. *pVal = NULL;
  2904. *pbVal = FALSE;
  2905. m_pISPData = new CICWISPData;
  2906. WCHAR szTemp[10]; // Big enough to format a WORD
  2907. // Add the PID, GIUD, and Offer ID to the ISP data object
  2908. ProcessSignedPID(&bRet);
  2909. if (bRet)
  2910. {
  2911. m_pISPData->PutDataElement(ISPDATA_SIGNED_PID, m_bstrSignedPID, FALSE);
  2912. }
  2913. else
  2914. {
  2915. m_pISPData->PutDataElement(ISPDATA_SIGNED_PID, NULL, FALSE);
  2916. }
  2917. // GUID comes from the ISPCSV file
  2918. m_pISPData->PutDataElement(ISPDATA_GUID,
  2919. m_pSelectedISPInfo->get_szOfferGUID(),
  2920. FALSE);
  2921. // Offer ID comes from the ISPCSV file as a WORD
  2922. // NOTE: This is the last one, so besure AppendQueryPair does not add an Ampersand
  2923. if (m_pSelectedISPInfo)
  2924. {
  2925. wsprintf (szTemp, L"%d", m_pSelectedISPInfo->get_wOfferID());
  2926. m_pISPData->PutDataElement(ISPDATA_OFFERID, szTemp, FALSE);
  2927. }
  2928. // BUGBUG: If ISDN get the ISDN Autoconfig URL
  2929. if (m_ISPImport.m_bIsISDNDevice)
  2930. {
  2931. get_ISDNAutoConfigURL(&bstrURL);
  2932. }
  2933. else
  2934. {
  2935. get_AutoConfigURL(&bstrURL);
  2936. }
  2937. if (*bstrURL)
  2938. {
  2939. // Get the full signup url with Query string params added to it
  2940. m_pISPData->GetQueryString(bstrURL, &bstrQueryURL);
  2941. // Setup WebGate
  2942. if (S_OK != gpCommMgr->FetchPage(bstrQueryURL, pVal))
  2943. {
  2944. // Download problem:
  2945. // User has disconnected
  2946. if (TRUE == m_bUserInitiateHangup)
  2947. {
  2948. hr = E_FAIL;
  2949. }
  2950. }
  2951. else
  2952. {
  2953. *pbVal = TRUE;
  2954. }
  2955. }
  2956. // Now that webgate is done with it, free the queryURL
  2957. SysFreeString(bstrQueryURL);
  2958. // Memory cleanup
  2959. SysFreeString(bstrURL);
  2960. delete m_pISPData;
  2961. m_pISPData = NULL;
  2962. }
  2963. return hr;
  2964. }
  2965. HRESULT CRefDial::RemoveDownloadDir()
  2966. {
  2967. DWORD dwAttribs;
  2968. WCHAR szDownloadDir[MAX_PATH];
  2969. WCHAR szSignedPID[MAX_PATH];
  2970. // form the ICW98 dir. It is basically the CWD
  2971. if(!GetOOBEPath(szDownloadDir))
  2972. return S_OK;
  2973. // remove the signed.pid file from the ICW directory (see BUG 373)
  2974. wsprintf(szSignedPID, L"%s%s", szDownloadDir, L"\\signed.pid");
  2975. if (GetFileAttributes(szSignedPID) != 0xFFFFFFFF)
  2976. {
  2977. SetFileAttributes(szSignedPID, FILE_ATTRIBUTE_NORMAL);
  2978. DeleteFile(szSignedPID);
  2979. }
  2980. lstrcat(szDownloadDir, L"\\download");
  2981. // See if the directory exists
  2982. dwAttribs = GetFileAttributes(szDownloadDir);
  2983. if (dwAttribs != 0xFFFFFFFF && dwAttribs & FILE_ATTRIBUTE_DIRECTORY)
  2984. DeleteDirectory(szDownloadDir);
  2985. return S_OK;
  2986. }
  2987. void CRefDial::DeleteDirectory (LPCWSTR szDirName)
  2988. {
  2989. WIN32_FIND_DATA fdata;
  2990. WCHAR szPath[MAX_PATH];
  2991. HANDLE hFile;
  2992. BOOL fDone;
  2993. wsprintf(szPath, L"%s\\*.*", szDirName);
  2994. hFile = FindFirstFile (szPath, &fdata);
  2995. if (INVALID_HANDLE_VALUE != hFile)
  2996. fDone = FALSE;
  2997. else
  2998. fDone = TRUE;
  2999. while (!fDone)
  3000. {
  3001. wsprintf(szPath, L"%s\\%s", szDirName, fdata.cFileName);
  3002. if (fdata.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
  3003. {
  3004. if (lstrcmpi(fdata.cFileName, L".") != 0 &&
  3005. lstrcmpi(fdata.cFileName, L"..") != 0)
  3006. {
  3007. // recursively delete this dir too
  3008. DeleteDirectory(szPath);
  3009. }
  3010. }
  3011. else
  3012. {
  3013. SetFileAttributes(szPath, FILE_ATTRIBUTE_NORMAL);
  3014. DeleteFile(szPath);
  3015. }
  3016. if (FindNextFile(hFile, &fdata) == 0)
  3017. {
  3018. FindClose(hFile);
  3019. fDone = TRUE;
  3020. }
  3021. }
  3022. SetFileAttributes(szDirName, FILE_ATTRIBUTE_NORMAL);
  3023. RemoveDirectory(szDirName);
  3024. }
  3025. HRESULT CRefDial::PostRegData(DWORD dwSrvType, LPWSTR szPath)
  3026. {
  3027. static WCHAR hdrs[] = L"Content-Type: application/x-www-form-urlencoded";
  3028. static WCHAR accept[] = L"Accept: */*";
  3029. static LPCWSTR rgsz[] = {accept, NULL};
  3030. WCHAR szRegPostURL[INTERNET_MAX_URL_LENGTH] = L"\0";
  3031. HRESULT hRet = E_FAIL;
  3032. if (POST_TO_MS & dwSrvType)
  3033. {
  3034. // Get the RegPostURL from Reg.isp file for MS registration
  3035. GetPrivateProfileString(INF_SECTION_URL,
  3036. c_szRegPostURL,
  3037. L"",
  3038. szRegPostURL,
  3039. INTERNET_MAX_URL_LENGTH,
  3040. m_szISPFile);
  3041. }
  3042. else if (POST_TO_OEM & dwSrvType)
  3043. {
  3044. WCHAR szOOBEInfoINIFile[MAX_PATH];
  3045. SearchPath(NULL, cszOOBEINFOINI, NULL, MAX_CHARS_IN_BUFFER(szOOBEInfoINIFile), szOOBEInfoINIFile, NULL);
  3046. GetPrivateProfileString(INF_OEMREGPAGE,
  3047. c_szRegPostURL,
  3048. L"",
  3049. szRegPostURL,
  3050. INTERNET_MAX_URL_LENGTH,
  3051. szOOBEInfoINIFile);
  3052. }
  3053. // Connecting to http://mscomdev.dns.microsoft.com/register.asp.
  3054. if (CrackUrl(
  3055. szRegPostURL,
  3056. m_szRegServerName,
  3057. m_szRegFormAction,
  3058. &m_nRegServerPort,
  3059. &m_fSecureRegServer))
  3060. {
  3061. HINTERNET hSession = InternetOpen(
  3062. L"OOBE",
  3063. INTERNET_OPEN_TYPE_PRECONFIG,
  3064. NULL,
  3065. NULL,
  3066. 0
  3067. );
  3068. if (hSession)
  3069. {
  3070. HINTERNET hConnect = InternetConnect(
  3071. hSession,
  3072. m_szRegServerName,
  3073. m_nRegServerPort,
  3074. NULL,
  3075. NULL,
  3076. INTERNET_SERVICE_HTTP,
  3077. 0,
  3078. 1
  3079. );
  3080. if (hConnect)
  3081. {
  3082. // INTERNET_FLAG_SECURE is needed KB Q168151
  3083. HINTERNET hRequest = HttpOpenRequest(
  3084. hConnect,
  3085. L"POST",
  3086. m_szRegFormAction,
  3087. NULL,
  3088. NULL,
  3089. rgsz,
  3090. (m_fSecureRegServer) ? INTERNET_FLAG_SECURE : 0,
  3091. 1
  3092. );
  3093. if (hRequest)
  3094. {
  3095. // The data for the HttpSendRequest has to be in ANSI. The server side does
  3096. // not understand a UNICODE string. If the server side gets changed to understand
  3097. // UNICODE data, the conversion below needs to be removed.
  3098. LPSTR szAnsiData = NULL;
  3099. INT iLength;
  3100. // compute the length
  3101. //
  3102. iLength = WideCharToMultiByte(CP_ACP, 0, szPath, -1, NULL, 0, NULL, NULL);
  3103. if (iLength > 0)
  3104. {
  3105. szAnsiData = new char[iLength];
  3106. if (szAnsiData)
  3107. {
  3108. WideCharToMultiByte(CP_ACP, 0, szPath, -1, szAnsiData, iLength, NULL, NULL);
  3109. szAnsiData[iLength - 1] = 0;
  3110. }
  3111. }
  3112. if (szAnsiData)
  3113. {
  3114. // 2nd/3rd params are a string/char length pair,
  3115. // but 4th/5th params are a buffer/byte length pair.
  3116. if (HttpSendRequest(hRequest, hdrs, lstrlen(hdrs), szAnsiData, lstrlenA(szAnsiData)))
  3117. {
  3118. // Get size of file in bytes.
  3119. WCHAR bufQuery[32] ;
  3120. DWORD dwFileSize ;
  3121. DWORD cchMaxBufQuery = MAX_CHARS_IN_BUFFER(bufQuery);
  3122. BOOL bQuery = HttpQueryInfo(hRequest,
  3123. HTTP_QUERY_CONTENT_LENGTH,
  3124. bufQuery,
  3125. &cchMaxBufQuery,
  3126. NULL) ;
  3127. if (bQuery)
  3128. {
  3129. // The Query was successful, so allocate the memory.
  3130. dwFileSize = (DWORD)_wtol(bufQuery) ;
  3131. }
  3132. else
  3133. {
  3134. // The Query failed. Allocate some memory. Should allocate memory in blocks.
  3135. dwFileSize = 5*1024 ;
  3136. }
  3137. // BUGBUG: What is the purpose of this code?? It
  3138. // appears to read a file, null-terminate the buffer,
  3139. // then delete the buffer. Why??
  3140. BYTE* rgbFile = new BYTE[dwFileSize+1] ;
  3141. if (rgbFile)
  3142. {
  3143. DWORD dwBytesRead ;
  3144. BOOL bRead = InternetReadFile(hRequest,
  3145. rgbFile,
  3146. dwFileSize+1,
  3147. &dwBytesRead);
  3148. if (bRead)
  3149. {
  3150. rgbFile[dwBytesRead] = 0 ;
  3151. hRet = S_OK;
  3152. } // InternetReadFile
  3153. delete [] rgbFile;
  3154. }
  3155. }
  3156. else
  3157. {
  3158. DWORD dwErr = GetLastError();
  3159. }
  3160. delete [] szAnsiData;
  3161. }
  3162. InternetCloseHandle(hRequest);
  3163. hRet = S_OK;
  3164. }
  3165. InternetCloseHandle(hConnect);
  3166. }
  3167. InternetCloseHandle(hSession);
  3168. }
  3169. }
  3170. if (hRet != S_OK)
  3171. {
  3172. DWORD dwErr = GetLastError();
  3173. hRet = HRESULT_FROM_WIN32(dwErr);
  3174. }
  3175. TRACE2(TEXT("Post registration data to %s 0x%08lx"), szRegPostURL, hRet);
  3176. return hRet;
  3177. }
  3178. // This function will accept user selected values that are necessary to
  3179. // setup a connectiod for dialing
  3180. // Returns:
  3181. // TRUE OK to dial
  3182. // FALSE Some kind of problem
  3183. // QuitWizard - TRUE, then terminate
  3184. // UserPickNumber - TRUE, then display Pick a Number DLG
  3185. // QuitWizard and UserPickNumber both FALSE, then just
  3186. // display the page prior to Dialing UI.
  3187. HRESULT CRefDial::Connect
  3188. (
  3189. UINT nType,
  3190. BSTR bstrISPFile,
  3191. DWORD dwCountry,
  3192. BSTR bstrAreaCode,
  3193. DWORD dwFlag,
  3194. DWORD dwAppMode
  3195. )
  3196. {
  3197. HRESULT hr = S_OK;
  3198. BOOL bSuccess = FALSE;
  3199. BOOL bRetVal = FALSE;
  3200. LPWSTR pszTemp;
  3201. WCHAR szISPPath[MAX_PATH];
  3202. m_dwCnType = nType;
  3203. if (!bstrISPFile || !bstrAreaCode)
  3204. {
  3205. return E_FAIL;
  3206. }
  3207. // Locate ISP file
  3208. if (!SearchPath(NULL, bstrISPFile,INF_SUFFIX,MAX_PATH,szISPPath,&pszTemp))
  3209. {
  3210. hr = ERROR_FILE_NOT_FOUND;
  3211. return hr;
  3212. }
  3213. // Check whether the isp file is ICW capable by reading the referral URL
  3214. GetPrivateProfileString(INF_SECTION_ISPINFO,
  3215. c_szURLReferral,
  3216. L"",
  3217. m_szRefServerURL,
  3218. INTERNET_MAX_URL_LENGTH,
  3219. szISPPath);
  3220. lstrcpy(m_szISPFile, szISPPath);
  3221. m_dwAppMode = dwAppMode;
  3222. // Initialize failure codes
  3223. m_bQuitWizard = FALSE;
  3224. m_bUserPickNumber = FALSE;
  3225. m_lpGatherInfo->m_bUsePhbk = FALSE;
  3226. // Stuff the Area Code, and Country Code into the GatherInfo struct
  3227. m_lpGatherInfo->m_dwCountryID = dwCountry;
  3228. m_lpGatherInfo->m_dwCountryCode = dwFlag;
  3229. lstrcpy(m_lpGatherInfo->m_szAreaCode, bstrAreaCode);
  3230. m_SuggestInfo.AccessEntry.dwCountryID = dwCountry;
  3231. m_SuggestInfo.AccessEntry.dwCountryCode = dwFlag;
  3232. lstrcpy(m_SuggestInfo.AccessEntry.szAreaCode, bstrAreaCode);
  3233. GetISPFileSettings(szISPPath);
  3234. FillGatherInfoStruct(m_lpGatherInfo);
  3235. if (CONNECTED_REFFERAL == m_dwCnType)
  3236. FormReferralServerURL(&bRetVal);
  3237. // LAN connection support in desktop mode
  3238. if (gpCommMgr)
  3239. {
  3240. // Pretend we have the connection
  3241. PostMessage(gpCommMgr->m_hwndCallBack, WM_OBCOMM_ONCONNECTED, (WPARAM)gpCommMgr->m_pRefDial->m_dwCnType , (LPARAM)0);
  3242. }
  3243. return hr;
  3244. }
  3245. HRESULT CRefDial::CheckOnlineStatus(BOOL *pbVal)
  3246. {
  3247. // #if defined(DEBUG)
  3248. // *pbVal = TRUE;
  3249. // return S_OK;
  3250. // #endif
  3251. *pbVal = (BOOL)(m_hrasconn != NULL);
  3252. return S_OK;
  3253. }
  3254. BOOL CRefDial::CrackUrl(
  3255. const WCHAR* lpszUrlIn,
  3256. WCHAR* lpszHostOut,
  3257. WCHAR* lpszActionOut,
  3258. INTERNET_PORT* lpnHostPort,
  3259. BOOL* lpfSecure)
  3260. {
  3261. URL_COMPONENTS urlcmpTheUrl;
  3262. LPURL_COMPONENTS lpUrlComp = &urlcmpTheUrl;
  3263. urlcmpTheUrl.dwStructSize = sizeof(urlcmpTheUrl);
  3264. urlcmpTheUrl.lpszScheme = NULL;
  3265. urlcmpTheUrl.lpszHostName = NULL;
  3266. urlcmpTheUrl.lpszUserName = NULL;
  3267. urlcmpTheUrl.lpszPassword = NULL;
  3268. urlcmpTheUrl.lpszUrlPath = NULL;
  3269. urlcmpTheUrl.lpszExtraInfo = NULL;
  3270. urlcmpTheUrl.dwSchemeLength = 1;
  3271. urlcmpTheUrl.dwHostNameLength = 1;
  3272. urlcmpTheUrl.dwUserNameLength = 1;
  3273. urlcmpTheUrl.dwPasswordLength = 1;
  3274. urlcmpTheUrl.dwUrlPathLength = 1;
  3275. urlcmpTheUrl.dwExtraInfoLength = 1;
  3276. if (!InternetCrackUrl(lpszUrlIn, lstrlen(lpszUrlIn),0, lpUrlComp) || !lpszHostOut || !lpszActionOut || !lpnHostPort || !lpfSecure)
  3277. {
  3278. return FALSE;
  3279. }
  3280. else
  3281. {
  3282. if (urlcmpTheUrl.dwHostNameLength != 0)
  3283. {
  3284. lstrcpyn(lpszHostOut, urlcmpTheUrl.lpszHostName, urlcmpTheUrl.dwHostNameLength+1);
  3285. }
  3286. if (urlcmpTheUrl.dwUrlPathLength != 0)
  3287. {
  3288. lstrcpyn(lpszActionOut, urlcmpTheUrl.lpszUrlPath, urlcmpTheUrl.dwUrlPathLength+1);
  3289. }
  3290. *lpfSecure = (urlcmpTheUrl.nScheme == INTERNET_SCHEME_HTTPS) ? TRUE : FALSE;
  3291. *lpnHostPort = urlcmpTheUrl.nPort;
  3292. return TRUE;
  3293. }
  3294. }