Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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