Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

884 lines
26 KiB

  1. /*-----------------------------------------------------------------------------
  2. dialdlg.cpp
  3. Implement functionality of dialing and download progress dialog
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. ChrisK ChrisKauffman
  8. History:
  9. 7/22/96 ChrisK Cleaned and formatted
  10. -----------------------------------------------------------------------------*/
  11. #include "pch.hpp"
  12. #include "icwdl.h"
  13. #include "resource.h"
  14. // the progress bar messages are defined in commctrl.h, but we can't include
  15. // it, because it introduces a conflicting definition for strDup.
  16. // so, just take out the one #define that we need
  17. //#include <commctrl.h>
  18. #define PBM_SETPOS (WM_USER+2)
  19. #define WM_DIAL WM_USER + 3
  20. #define MAX_EXIT_RETRIES 10
  21. #define MAX_RETIES 3
  22. #define VALID_INIT (m_pcRNA && m_pcDLAPI)
  23. // ############################################################################
  24. void CALLBACK LineCallback(DWORD hDevice,
  25. DWORD dwMessage,
  26. DWORD dwInstance,
  27. DWORD dwParam1,
  28. DWORD dwParam2,
  29. DWORD dwParam3)
  30. {
  31. }
  32. //+----------------------------------------------------------------------------
  33. //
  34. // Function: NeedZapper
  35. //
  36. // Synopsis: Checks to see if we need to handle the RNA connection dialog.
  37. // Only builds earlier than 1071 will have the RNA connection dialog
  38. //
  39. // Arguments: None
  40. //
  41. // Returns: True - the RNA dialog will have to be handled
  42. //
  43. // History: ArulM Created 7/18/96
  44. // ChrisK Installed into autodialer 7/19/96
  45. //
  46. //-----------------------------------------------------------------------------
  47. static BOOL NeedZapper(void)
  48. {
  49. OSVERSIONINFO oi;
  50. memset(&oi, 0, sizeof(oi));
  51. oi.dwOSVersionInfoSize = sizeof(oi);
  52. if( GetVersionEx(&oi) &&
  53. (oi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) &&
  54. (oi.dwMajorVersion==4) &&
  55. (oi.dwMinorVersion==0) &&
  56. (LOWORD(oi.dwBuildNumber) <= 1070) )
  57. return TRUE;
  58. else
  59. return FALSE;
  60. }
  61. // ############################################################################
  62. VOID WINAPI ProgressCallBack(
  63. HINTERNET hInternet,
  64. DWORD_PTR dwContext,
  65. DWORD dwInternetStatus,
  66. LPVOID lpvStatusInformation,
  67. DWORD dwStatusInformationLength
  68. )
  69. {
  70. if (dwContext)
  71. ((CDialingDlg*)dwContext)->ProgressCallBack(hInternet,dwContext,dwInternetStatus,
  72. lpvStatusInformation,
  73. dwStatusInformationLength);
  74. }
  75. // ############################################################################
  76. HRESULT WINAPI DialingDownloadDialog(PDIALDLGDATA pDD)
  77. {
  78. HRESULT hr = ERROR_SUCCESS;
  79. CDialingDlg *pcDialDlg;
  80. LPLINEEXTENSIONID lpExtensionID=NULL;
  81. // Validate parameters
  82. //
  83. Assert(pDD);
  84. if (!pDD)
  85. {
  86. hr = ERROR_INVALID_PARAMETER;
  87. goto DialingDownloadDialogExit;
  88. }
  89. if (pDD->dwSize < sizeof(DIALDLGDATA))
  90. {
  91. hr = ERROR_BUFFER_TOO_SMALL;
  92. goto DialingDownloadDialogExit;
  93. }
  94. // Alloc and fill dialog object
  95. //
  96. pcDialDlg = new CDialingDlg;
  97. if (!pcDialDlg)
  98. {
  99. hr = ERROR_NOT_ENOUGH_MEMORY;
  100. goto DialingDownloadDialogExit;
  101. }
  102. if (ERROR_SUCCESS != (hr = pcDialDlg->Init()))
  103. goto DialingDownloadDialogExit;
  104. StrDup(&pcDialDlg->m_pszConnectoid,pDD->pszRasEntryName);
  105. StrDup(&pcDialDlg->m_pszMessage,pDD->pszMessage);
  106. StrDup(&pcDialDlg->m_pszUrl,pDD->pszMultipartMIMEUrl);
  107. StrDup(&pcDialDlg->m_pszDunFile,pDD->pszDunFile);
  108. pcDialDlg->m_pfnStatusCallback = pDD->pfnStatusCallback;
  109. pcDialDlg->m_hInst = pDD->hInst;
  110. pcDialDlg->m_bSkipDial = pDD->bSkipDial;
  111. // Initialize TAPI
  112. //
  113. hr = lineInitialize(&pcDialDlg->m_hLineApp,pcDialDlg->m_hInst,LineCallback,NULL,&pcDialDlg->m_dwNumDev);
  114. if (hr != ERROR_SUCCESS)
  115. goto DialingDownloadDialogExit;
  116. AssertMsg(pcDialDlg->m_dwTapiDev < pcDialDlg->m_dwNumDev,"The user has selected an invalid TAPI device.\n");
  117. lpExtensionID = (LPLINEEXTENSIONID)GlobalAlloc(GPTR,sizeof(LINEEXTENSIONID));
  118. if (!lpExtensionID)
  119. {
  120. hr = ERROR_NOT_ENOUGH_MEMORY;
  121. goto DialingDownloadDialogExit;
  122. }
  123. hr = lineNegotiateAPIVersion(pcDialDlg->m_hLineApp, pcDialDlg->m_dwTapiDev,
  124. 0x00010004, 0x00010004,&pcDialDlg->m_dwAPIVersion, lpExtensionID);
  125. // 4/2/97 ChrisK Olympus 2745
  126. while (ERROR_SUCCESS != hr && pcDialDlg->m_dwTapiDev < (pcDialDlg->m_dwNumDev - 1))
  127. {
  128. pcDialDlg->m_dwTapiDev++;
  129. hr = lineNegotiateAPIVersion(pcDialDlg->m_hLineApp, pcDialDlg->m_dwTapiDev,
  130. 0x00010004, 0x00010004,&pcDialDlg->m_dwAPIVersion, lpExtensionID);
  131. }
  132. // Delete the extenstion ID since we don't use it, but keep the version information.
  133. //
  134. if (lpExtensionID) GlobalFree(lpExtensionID);
  135. if (hr != ERROR_SUCCESS)
  136. goto DialingDownloadDialogExit;
  137. // Call back filter for reconnect
  138. pcDialDlg->m_pfnRasDialFunc1 = pDD->pfnRasDialFunc1;
  139. // Display dialog
  140. //
  141. hr = (HRESULT)DialogBoxParam(GetModuleHandle(TEXT("ICWDIAL")),MAKEINTRESOURCE(IDD_DIALING),
  142. pDD->hParentHwnd,GenericDlgProc,(LPARAM)pcDialDlg);
  143. if (pDD->phRasConn)
  144. *(pDD->phRasConn) = pcDialDlg->m_hrasconn;
  145. // 4/2/97 ChrisK Olympus 296
  146. // This is now handled inside the dialog
  147. //#if !defined(WIN16)
  148. // if ((ERROR_USERNEXT == hr) && NeedZapper())
  149. // MinimizeRNAWindow(pDD->pszRasEntryName,GetModuleHandle("ICWDIAL"));
  150. //#endif
  151. // BUGBUG: on an error wait for the connection to die
  152. DialingDownloadDialogExit:
  153. // Close tapi line
  154. //
  155. if (NULL != pcDialDlg)
  156. {
  157. // 4/2/97 ChrisK Olympus 296
  158. if (pcDialDlg->m_hLineApp)
  159. {
  160. lineShutdown(pcDialDlg->m_hLineApp);
  161. pcDialDlg->m_hLineApp = NULL;
  162. }
  163. //
  164. // ChrisK 296 6/3/97
  165. // Broaden window
  166. //
  167. // StopRNAReestablishZapper(g_hRNAZapperThread);
  168. }
  169. //
  170. // 5/23/97 jmazner Olympus #4652
  171. //
  172. delete(pcDialDlg);
  173. return hr;
  174. }
  175. // ############################################################################
  176. CDialingDlg::CDialingDlg()
  177. {
  178. m_hrasconn = NULL;
  179. m_pszConnectoid = NULL;
  180. m_hThread = NULL;
  181. m_dwThreadID = 0;
  182. m_hwnd = NULL;
  183. m_pszUrl = NULL;
  184. m_pszDisplayable = NULL;
  185. m_dwDownLoad = 0;
  186. m_pszPhoneNumber = NULL;
  187. m_pszMessage = NULL;
  188. m_pfnStatusCallback = NULL;
  189. m_unRasEvent = 0;
  190. m_pszDunFile = NULL;
  191. m_hLineApp = NULL;
  192. m_dwNumDev = 0;
  193. m_dwTapiDev = 0;
  194. m_dwAPIVersion = 0;
  195. m_pcRNA = NULL;
  196. // m_hDownLoadDll = NULL;
  197. m_bProgressShowing = FALSE;
  198. m_dwLastStatus = 0;
  199. m_pcDLAPI = NULL;
  200. m_bSkipDial = FALSE;
  201. // Normandy 11919 - ChrisK
  202. // Do not prompt to exit on dialing dialog since we don't exit the app from
  203. // here
  204. m_bShouldAsk = FALSE;
  205. //
  206. // ChrisK 5240 Olympus
  207. // Only the thread that creates the dwDownload should invalidate it
  208. // so we need another method to track if the cancel button has been
  209. // pressed.
  210. //
  211. m_fDownloadHasBeenCanceled = FALSE;
  212. }
  213. // ############################################################################
  214. HRESULT CDialingDlg::Init()
  215. {
  216. HRESULT hr = ERROR_SUCCESS;
  217. m_pcRNA = new RNAAPI;
  218. if (!m_pcRNA)
  219. {
  220. hr = ERROR_NOT_ENOUGH_MEMORY;
  221. goto InitExit;
  222. }
  223. m_pcDLAPI = new CDownLoadAPI;
  224. if (!m_pcDLAPI)
  225. {
  226. hr = ERROR_NOT_ENOUGH_MEMORY;
  227. goto InitExit;
  228. }
  229. m_pszPhoneNumber = (LPTSTR)GlobalAlloc(GPTR,sizeof(TCHAR)*256);
  230. if (!m_pszPhoneNumber)
  231. {
  232. hr = ERROR_NOT_ENOUGH_MEMORY;
  233. goto InitExit;
  234. }
  235. InitExit:
  236. return hr;
  237. }
  238. // ############################################################################
  239. CDialingDlg::~CDialingDlg()
  240. {
  241. TraceMsg(TF_GENERAL, "ICWDIAL: CDialingDlg::~CDialingDlg");
  242. //
  243. // 5/25/97 ChrisK I know this will leak the connection but that's ok
  244. // since we sweep this up later and in the meantime we need to close
  245. // out the object
  246. //
  247. //if (m_hrasconn && m_pcRNA)
  248. //{
  249. // m_pcRNA->RasHangUp(m_hrasconn);
  250. //}
  251. //m_hrasconn = NULL;
  252. if (m_pszConnectoid) GlobalFree(m_pszConnectoid);
  253. m_pszConnectoid = NULL;
  254. if (m_pszUrl) GlobalFree(m_pszUrl);
  255. m_pszUrl = NULL;
  256. if (m_pszDisplayable) GlobalFree(m_pszDisplayable);
  257. m_pszDisplayable = NULL;
  258. //
  259. // ChrisK 5240 Olympus
  260. // Only the thread that creates the dwDownload should invalidate it
  261. // so we need another method to track if the cancel button has been
  262. // pressed.
  263. //
  264. //
  265. // ChrisK 6/24/97 Olympus 6373
  266. // We have to call DownLoadClose even if the download was canceled because
  267. // we have to release the semaphores
  268. //
  269. if (m_dwDownLoad && m_pcDLAPI)
  270. {
  271. m_pcDLAPI->DownLoadClose(m_dwDownLoad);
  272. m_fDownloadHasBeenCanceled = TRUE;
  273. }
  274. m_dwDownLoad = 0;
  275. if (m_hThread)
  276. {
  277. //
  278. // 5/23/97 jmazner Olympus #4652
  279. //
  280. // we want to make sure the thread is killed before
  281. // we delete the m_pcDLApi that it relies on.
  282. //
  283. WaitForSingleObject(m_hThread, INFINITE);
  284. CloseHandle(m_hThread);
  285. }
  286. m_hThread = NULL;
  287. m_dwThreadID = 0;
  288. m_hwnd = NULL;
  289. if (m_pszPhoneNumber) GlobalFree(m_pszPhoneNumber);
  290. m_pszPhoneNumber = NULL;
  291. if (m_pszMessage) GlobalFree(m_pszMessage);
  292. m_pszMessage = NULL;
  293. m_pfnStatusCallback=NULL;
  294. if (m_pszDunFile) GlobalFree(m_pszDunFile);
  295. m_pszDunFile = NULL;
  296. if (m_hLineApp) lineShutdown(m_hLineApp);
  297. m_hLineApp = NULL;
  298. m_dwNumDev = 0;
  299. m_dwTapiDev = 0;
  300. m_dwAPIVersion = 0;
  301. if (m_pcRNA) delete m_pcRNA;
  302. m_pcRNA = NULL;
  303. m_bProgressShowing = FALSE;
  304. m_dwLastStatus = 0;
  305. if (m_pcDLAPI) delete m_pcDLAPI;
  306. m_pcDLAPI = NULL;
  307. //
  308. // 4/2/97 ChrisK Olympus 296
  309. //
  310. StopRNAReestablishZapper(g_hRNAZapperThread);
  311. }
  312. // ############################################################################
  313. LRESULT CDialingDlg::DlgProc(HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam, LRESULT lres)
  314. {
  315. HRESULT hr;
  316. // Normandy 11745
  317. // WORD wIDS;
  318. FARPROC fp;
  319. DWORD dwThreadResults;
  320. INT iRetries;
  321. static bDisconnect;
  322. Assert(VALID_INIT);
  323. switch(uMsg)
  324. {
  325. case WM_INITDIALOG:
  326. //
  327. // Register with caller's filter
  328. //
  329. if (m_pfnRasDialFunc1)
  330. (m_pfnRasDialFunc1)(NULL,WM_RegisterHWND,RASCS_OpenPort,HandleToUlong(hwnd),0);
  331. m_hwnd = hwnd;
  332. m_bProgressShowing = FALSE;
  333. ShowWindow(GetDlgItem(m_hwnd,IDC_PROGRESS),SW_HIDE);
  334. m_unRasEvent = RegisterWindowMessageA(RASDIALEVENT);
  335. if (m_unRasEvent == 0) m_unRasEvent = WM_RASDIALEVENT;
  336. // Bug Normandy 5920
  337. // ChrisK, turns out we are calling MakeBold twice
  338. // MakeBold(GetDlgItem(m_hwnd,IDC_LBLTITLE),TRUE,FW_BOLD);
  339. IF_NTONLY
  340. bDisconnect = FALSE;
  341. ENDIF_NTONLY
  342. //
  343. // Show number to be dialed
  344. //
  345. if (m_bSkipDial)
  346. {
  347. PostMessage(m_hwnd,m_unRasEvent,RASCS_Connected,SUCCESS);
  348. }
  349. else
  350. {
  351. hr = GetDisplayableNumberDialDlg();
  352. if (hr != ERROR_SUCCESS)
  353. {
  354. SetDlgItemText(m_hwnd,IDC_LBLNUMBER,m_pszPhoneNumber);
  355. } else {
  356. SetDlgItemText(m_hwnd,IDC_LBLNUMBER,m_pszDisplayable);
  357. }
  358. PostMessage(m_hwnd,WM_DIAL,0,0);
  359. }
  360. lres = TRUE;
  361. break;
  362. case WM_DIAL:
  363. SetForegroundWindow(m_hwnd);
  364. hr = DialDlg();
  365. if (hr != ERROR_SUCCESS)
  366. EndDialog(m_hwnd,hr);
  367. lres = TRUE;
  368. break;
  369. case WM_COMMAND:
  370. switch(LOWORD(wparam))
  371. {
  372. case IDC_CMDCANCEL:
  373. //
  374. // Tell the user what we are doing, since it may take awhile
  375. //
  376. SetDlgItemText(m_hwnd,IDC_LBLSTATUS,GetSz(IDS_RAS_HANGINGUP));
  377. //
  378. // Cancel download first, HangUp second....
  379. //
  380. //
  381. // ChrisK 5240 Olympus
  382. // Only the thread that creates the dwDownload should invalidate it
  383. // so we need another method to track if the cancel button has been
  384. // pressed.
  385. //
  386. if (m_dwDownLoad && m_pcDLAPI && !m_fDownloadHasBeenCanceled)
  387. {
  388. m_pcDLAPI->DownLoadCancel(m_dwDownLoad);
  389. m_fDownloadHasBeenCanceled = TRUE;
  390. }
  391. if (m_pcRNA && m_hrasconn)
  392. {
  393. m_pcRNA->RasHangUp(m_hrasconn);
  394. }
  395. PostMessage(m_hwnd,m_unRasEvent,(WPARAM)RASCS_Disconnected,(LPARAM)ERROR_USER_DISCONNECTION);
  396. lres = TRUE;
  397. break;
  398. }
  399. break;
  400. case WM_CLOSE:
  401. // CANCEL First, HangUp second....
  402. //
  403. //
  404. // ChrisK 5240 Olympus
  405. // Only the thread that creates the dwDownload should invalidate it
  406. // so we need another method to track if the cancel button has been
  407. // pressed.
  408. //
  409. if (m_dwDownLoad && m_pcDLAPI && !m_fDownloadHasBeenCanceled)
  410. {
  411. m_pcDLAPI->DownLoadCancel(m_dwDownLoad);
  412. m_fDownloadHasBeenCanceled = TRUE;
  413. }
  414. if (m_pcRNA && m_hrasconn)
  415. {
  416. m_pcRNA->RasHangUp(m_hrasconn);
  417. }
  418. EndDialog(hwnd,ERROR_USERCANCEL);
  419. m_hwnd = NULL;
  420. lres = TRUE;
  421. break;
  422. case WM_DOWNLOAD_DONE:
  423. dwThreadResults = STILL_ACTIVE;
  424. iRetries = 0;
  425. if (m_pcRNA && m_hrasconn)
  426. {
  427. m_pcRNA->RasHangUp(m_hrasconn);
  428. m_hrasconn = NULL;
  429. }
  430. do {
  431. if (!GetExitCodeThread(m_hThread,&dwThreadResults))
  432. {
  433. AssertMsg(0,"CONNECT:GetExitCodeThread failed.\n");
  434. }
  435. iRetries++;
  436. if (dwThreadResults == STILL_ACTIVE) Sleep(500);
  437. } while (dwThreadResults == STILL_ACTIVE && iRetries < MAX_EXIT_RETRIES);
  438. if (dwThreadResults == ERROR_SUCCESS)
  439. EndDialog(hwnd,ERROR_USERNEXT);
  440. else
  441. EndDialog(hwnd,dwThreadResults);
  442. lres = TRUE;
  443. break;
  444. default:
  445. if (uMsg == m_unRasEvent)
  446. {
  447. TCHAR szRasError[10];
  448. TCHAR szRasMessage[256];
  449. wsprintf(szRasError,TEXT("%d %d"),wparam,lparam);
  450. RegSetValue(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\iSignUp"),REG_SZ,
  451. szRasError,lstrlen(szRasError));
  452. TraceMsg(TF_GENERAL, "AUTODIAL: Ras message %d error (%d).\n",wparam,lparam);
  453. hr = m_pfnStatusCallback((DWORD)wparam, szRasMessage, 256);
  454. if (!hr)
  455. SetDlgItemText(m_hwnd,IDC_LBLSTATUS,szRasMessage);
  456. switch(wparam)
  457. {
  458. case RASCS_Connected:
  459. #if !defined(WIN16)
  460. // 4/2/97 ChrisK Olympus 296
  461. //
  462. // ChrisK Olympus 6060 6/10/97
  463. // If the URL is blank, then we don't need the zapper thread.
  464. //
  465. if (NeedZapper())
  466. {
  467. HMODULE hMod;
  468. hMod = GetModuleHandle(TEXT("ICWDIAL"));
  469. MinimizeRNAWindow(m_pszConnectoid,hMod);
  470. if (m_pszUrl && m_pszUrl[0])
  471. {
  472. g_hRNAZapperThread = LaunchRNAReestablishZapper(hMod);
  473. }
  474. hMod = NULL;
  475. }
  476. #endif
  477. if (m_pszUrl)
  478. {
  479. //
  480. // we should now let the user know that we
  481. // are downloading
  482. // MKarki (5/5/97) - Fix for Bug#423
  483. //
  484. SetDlgItemText(m_hwnd,IDC_LBLSTATUS,GetSz (IDS_DOWNLOADING));
  485. // The connection is open and ready. Start the download.
  486. //
  487. m_dwThreadID = 0;
  488. m_hThread = CreateThread(NULL,0,
  489. (LPTHREAD_START_ROUTINE)DownloadThreadInit,this,0,&m_dwThreadID);
  490. if (!m_hThread)
  491. {
  492. hr = GetLastError();
  493. if (m_pcRNA && m_hrasconn)
  494. {
  495. m_pcRNA->RasHangUp(m_hrasconn);
  496. m_hrasconn = NULL;
  497. }
  498. EndDialog(m_hwnd,hr);
  499. break;
  500. }
  501. } else {
  502. EndDialog(m_hwnd,ERROR_USERNEXT);
  503. }
  504. break;
  505. case RASCS_Disconnected:
  506. IF_NTONLY
  507. // There is a possibility that we will get multiple disconnects in NT
  508. // and we only want to handle the first one. Note: the flag is reset
  509. // in the INITIALIZE event, so we should handle 1 disconnect per instance
  510. // of the dialog.
  511. if (bDisconnect)
  512. break;
  513. else
  514. bDisconnect = TRUE;
  515. ENDIF_NTONLY
  516. if (m_hrasconn && m_pcRNA) m_pcRNA->RasHangUp(m_hrasconn);
  517. m_hrasconn = NULL;
  518. EndDialog(m_hwnd,lparam);
  519. break;
  520. default:
  521. IF_NTONLY
  522. if (SUCCESS != lparam)
  523. {
  524. PostMessage(m_hwnd,m_unRasEvent,(WPARAM)RASCS_Disconnected,lparam);
  525. }
  526. ENDIF_NTONLY
  527. }
  528. }
  529. }
  530. return lres;
  531. }
  532. // ############################################################################
  533. HRESULT CDialingDlg::GetDisplayableNumberDialDlg()
  534. {
  535. HRESULT hr;
  536. LPRASENTRY lpRasEntry = NULL;
  537. LPRASDEVINFO lpRasDevInfo = NULL;
  538. DWORD dwRasEntrySize = 0;
  539. DWORD dwRasDevInfoSize = 0;
  540. LPLINETRANSLATEOUTPUT lpOutput1 = NULL;
  541. LPLINETRANSLATEOUTPUT lpOutput2 = NULL;
  542. HINSTANCE hRasDll = NULL;
  543. FARPROC fp = NULL;
  544. Assert(VALID_INIT);
  545. // Format the phone number
  546. //
  547. lpOutput1 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR,sizeof(LINETRANSLATEOUTPUT));
  548. if (!lpOutput1)
  549. {
  550. hr = ERROR_NOT_ENOUGH_MEMORY;
  551. goto GetDisplayableNumberExit;
  552. }
  553. lpOutput1->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  554. // Get phone number from connectoid
  555. //
  556. hr = ICWGetRasEntry(&lpRasEntry, &dwRasEntrySize, &lpRasDevInfo, &dwRasDevInfoSize, m_pszConnectoid);
  557. if (hr != ERROR_SUCCESS)
  558. goto GetDisplayableNumberExit;
  559. //
  560. // If this is a dial as is number, just get it from the structure
  561. //
  562. if (!(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes))
  563. {
  564. if (m_pszDisplayable) GlobalFree(m_pszDisplayable);
  565. m_pszDisplayable = (LPTSTR)GlobalAlloc(GPTR, sizeof(TCHAR)*(lstrlen(lpRasEntry->szLocalPhoneNumber)+1));
  566. if (!m_pszDisplayable)
  567. {
  568. hr = ERROR_NOT_ENOUGH_MEMORY;
  569. goto GetDisplayableNumberExit;
  570. }
  571. lstrcpy(m_pszPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  572. lstrcpy(m_pszDisplayable, lpRasEntry->szLocalPhoneNumber);
  573. }
  574. else
  575. {
  576. //
  577. // If there is no area code, don't use parentheses
  578. //
  579. if (lpRasEntry->szAreaCode[0])
  580. wsprintf(m_pszPhoneNumber,TEXT("+%d (%s) %s\0"),lpRasEntry->dwCountryCode,lpRasEntry->szAreaCode,lpRasEntry->szLocalPhoneNumber);
  581. else
  582. wsprintf(m_pszPhoneNumber,TEXT("+%lu %s\0"),lpRasEntry->dwCountryCode,
  583. lpRasEntry->szLocalPhoneNumber);
  584. // Turn the canonical form into the "displayable" form
  585. //
  586. hr = lineTranslateAddress(m_hLineApp,m_dwTapiDev,m_dwAPIVersion,m_pszPhoneNumber,
  587. 0,LINETRANSLATEOPTION_CANCELCALLWAITING,lpOutput1);
  588. if (hr != ERROR_SUCCESS || (lpOutput1->dwNeededSize != lpOutput1->dwTotalSize))
  589. {
  590. lpOutput2 = (LPLINETRANSLATEOUTPUT)GlobalAlloc(GPTR,lpOutput1->dwNeededSize);
  591. if (!lpOutput2)
  592. {
  593. hr = ERROR_NOT_ENOUGH_MEMORY;
  594. goto GetDisplayableNumberExit;
  595. }
  596. lpOutput2->dwTotalSize = lpOutput1->dwNeededSize;
  597. GlobalFree(lpOutput1);
  598. lpOutput1 = lpOutput2;
  599. lpOutput2 = NULL;
  600. hr = lineTranslateAddress(m_hLineApp,m_dwTapiDev,m_dwAPIVersion,m_pszPhoneNumber,
  601. 0,LINETRANSLATEOPTION_CANCELCALLWAITING,lpOutput1);
  602. }
  603. if (hr != ERROR_SUCCESS)
  604. {
  605. goto GetDisplayableNumberExit;
  606. }
  607. StrDup(&m_pszDisplayable,(LPTSTR)&((LPBYTE)lpOutput1)[lpOutput1->dwDisplayableStringOffset]);
  608. }
  609. GetDisplayableNumberExit:
  610. if (lpRasEntry) GlobalFree(lpRasEntry);
  611. lpRasEntry = NULL;
  612. if (lpRasDevInfo) GlobalFree(lpRasDevInfo);
  613. lpRasDevInfo = NULL;
  614. if (lpOutput1) GlobalFree(lpOutput1);
  615. lpOutput1 = NULL;
  616. return hr;
  617. }
  618. // ############################################################################
  619. HRESULT CDialingDlg::DialDlg()
  620. {
  621. TCHAR szPassword[PWLEN+2];
  622. LPRASDIALPARAMS lpRasDialParams = NULL;
  623. HRESULT hr = ERROR_SUCCESS;
  624. BOOL bPW;
  625. Assert(VALID_INIT);
  626. // Get connectoid information
  627. //
  628. lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR,sizeof(RASDIALPARAMS));
  629. if (!lpRasDialParams)
  630. {
  631. hr = ERROR_NOT_ENOUGH_MEMORY;
  632. goto DialExit;
  633. }
  634. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  635. lstrcpyn(lpRasDialParams->szEntryName,m_pszConnectoid,RAS_MaxEntryName);
  636. bPW = FALSE;
  637. hr = m_pcRNA->RasGetEntryDialParams(NULL,lpRasDialParams,&bPW);
  638. if (hr != ERROR_SUCCESS)
  639. {
  640. goto DialExit;
  641. }
  642. // Add the user's password
  643. //
  644. szPassword[0] = 0;
  645. if (GetISPFile() != NULL && *(GetISPFile()) != TEXT('\0'))
  646. {
  647. // GetPrivateProfileString examines one character before the filename
  648. // if it is an empty string, which could result in AV, if the address
  649. // refers to an invalid page.
  650. GetPrivateProfileString(
  651. INFFILE_USER_SECTION,INFFILE_PASSWORD,
  652. NULLSZ,szPassword,PWLEN + 1,GetISPFile());
  653. }
  654. // if didnt get password, then try to get from DUN file (if any)
  655. if(!szPassword[0] && m_pszDunFile)
  656. {
  657. // 4-29-97 Chrisk Olympus 3985
  658. // Due to the wrong filename being used, the password was always being set to
  659. // NULL and therefore requiring the user to provide the password to log onto the
  660. // signup server.
  661. GetPrivateProfileString(
  662. INFFILE_USER_SECTION,INFFILE_PASSWORD,
  663. NULLSZ,szPassword,PWLEN + 1,m_pszDunFile);
  664. //NULLSZ,szPassword,PWLEN + 1,g_szCurrentDUNFile);
  665. }
  666. if(szPassword[0])
  667. {
  668. lstrcpyn(lpRasDialParams->szPassword, szPassword,PWLEN+1);
  669. TraceMsg(TF_GENERAL, "ICWDIAL: Password is not blank.\r\n");
  670. }
  671. else
  672. {
  673. TraceMsg(TF_GENERAL, "ICWDIAL: Password is blank.\r\n");
  674. }
  675. // Dial connectoid
  676. //
  677. Assert(!m_hrasconn);
  678. #if !defined(WIN16) && defined(DEBUG)
  679. if (FCampusNetOverride())
  680. {
  681. //
  682. // Skip dialing because the server is on the campus network
  683. //
  684. PostMessage(m_hwnd,RegisterWindowMessageA(RASDIALEVENT),RASCS_Connected,0);
  685. }
  686. else
  687. {
  688. #endif // !WIN16 && DEBUG
  689. if (m_pfnRasDialFunc1)
  690. hr = m_pcRNA->RasDial(NULL,NULL,lpRasDialParams,1,m_pfnRasDialFunc1,&m_hrasconn);
  691. else
  692. hr = m_pcRNA->RasDial(NULL,NULL,lpRasDialParams,0xFFFFFFFF,m_hwnd,&m_hrasconn);
  693. if (hr != ERROR_SUCCESS)
  694. {
  695. if (m_hrasconn && m_pcRNA)
  696. {
  697. m_pcRNA->RasHangUp(m_hrasconn);
  698. m_hrasconn = NULL;
  699. }
  700. goto DialExit;
  701. }
  702. #if !defined(WIN16) && defined(DEBUG)
  703. }
  704. #endif
  705. if (lpRasDialParams) GlobalFree(lpRasDialParams);
  706. lpRasDialParams = NULL;
  707. DialExit:
  708. return hr;
  709. }
  710. // ############################################################################
  711. VOID CDialingDlg::ProgressCallBack(
  712. HINTERNET hInternet,
  713. DWORD_PTR dwContext,
  714. DWORD dwInternetStatus,
  715. LPVOID lpvStatusInformation,
  716. DWORD dwStatusInformationLength
  717. )
  718. {
  719. TCHAR szRasMessage[256];
  720. HRESULT hr = ERROR_SUCCESS;
  721. WPARAM *puiStatusInfo = NULL;
  722. //
  723. // 5/28/97 jmazner Olympus #4579
  724. // *lpvStatusInformation is the percentage of completed download,
  725. // as a value from 0 to 100.
  726. //
  727. puiStatusInfo = (WPARAM *) lpvStatusInformation;
  728. Assert( puiStatusInfo );
  729. Assert( *puiStatusInfo <= 100 );
  730. Assert(VALID_INIT);
  731. if (!m_bProgressShowing)
  732. ShowWindow(GetDlgItem(m_hwnd,IDC_PROGRESS),SW_SHOW);
  733. if (m_dwLastStatus != dwInternetStatus)
  734. {
  735. hr = m_pfnStatusCallback(dwInternetStatus,szRasMessage,256);
  736. if (!hr)
  737. SetDlgItemText(m_hwnd,IDC_LBLSTATUS,szRasMessage);
  738. m_dwLastStatus = dwInternetStatus;
  739. TraceMsg(TF_GENERAL, "CONNECT:inet status:%s, %d, %d.\n",szRasMessage,m_dwLastStatus,dwInternetStatus);
  740. }
  741. //
  742. // 5/28/97 jmazner Olympus #4579
  743. // Send update messages to the progress bar
  744. //
  745. PostMessage(GetDlgItem(m_hwnd,IDC_PROGRESS), PBM_SETPOS, *puiStatusInfo, 0);
  746. m_bProgressShowing = TRUE;
  747. }