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.

453 lines
16 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // REFDIAL.CPP - Functions for
  7. //
  8. // HISTORY:
  9. //
  10. // 05/13/98 donaldm Created.
  11. //
  12. //*********************************************************************
  13. #include "pre.h"
  14. #include "icwextsn.h"
  15. #include <raserror.h>
  16. extern UINT GetDlgIDFromIndex(UINT uPageIndex);
  17. extern BOOL SetNextPage(HWND hDlg, UINT* puNextPage, BOOL* pfKeepHistory);
  18. extern TCHAR g_szOemCode[];
  19. extern TCHAR g_szProductCode[];
  20. extern TCHAR g_szPromoCode[];
  21. const TCHAR cszISPINFOPath[] = TEXT("download\\ispinfo.csv");
  22. /*******************************************************************
  23. NAME: RefServDialInitProc
  24. SYNOPSIS: Called when page is displayed
  25. ENTRY: hDlg - dialog window
  26. fFirstInit - TRUE if this is the first time the dialog
  27. is initialized, FALSE if this InitProc has been called
  28. before (e.g. went past this page and backed up)
  29. ********************************************************************/
  30. BOOL CALLBACK RefServDialInitProc
  31. (
  32. HWND hDlg,
  33. BOOL fFirstInit,
  34. UINT *puNextPage
  35. )
  36. {
  37. BOOL bRet = TRUE;
  38. // Initialize the progres bar.
  39. SendDlgItemMessage(hDlg, IDC_REFSERV_DIALPROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  40. SendDlgItemMessage(hDlg, IDC_REFSERV_DIALPROGRESS, PBM_SETPOS, 0, 0l);
  41. // Hide the progress bar
  42. ShowWindow(GetDlgItem(hDlg, IDC_REFSERV_DIALPROGRESS), SW_HIDE);
  43. // Disable Back and Next
  44. PropSheet_SetWizButtons(GetParent(hDlg), 0);
  45. g_bAllowCancel = FALSE;
  46. if (fFirstInit)
  47. {
  48. CRefDialEvent *pRefDialEvent;
  49. //set the redial count
  50. gpWizardState->iRedialCount = 0;
  51. gpWizardState->dwLastSelection = 0;
  52. // Blank out the status text initially
  53. SetWindowText(GetDlgItem(hDlg, IDC_REFSERV_DIALSTATUS), TEXT(""));
  54. // Setup and Event Handler
  55. pRefDialEvent = new CRefDialEvent(hDlg);
  56. if (NULL != pRefDialEvent)
  57. {
  58. HRESULT hr;
  59. gpWizardState->pRefDialEvents = pRefDialEvent;
  60. gpWizardState->pRefDialEvents->AddRef();
  61. hr = ConnectToICWConnectionPoint((IUnknown *)gpWizardState->pRefDialEvents,
  62. DIID__RefDialEvents,
  63. TRUE,
  64. (IUnknown *)gpWizardState->pRefDial,
  65. &gpWizardState->pRefDialEvents->m_dwCookie,
  66. NULL);
  67. bRet = TRUE;
  68. }
  69. else
  70. {
  71. //BUGBUG: Throw error message
  72. gfQuitWizard = TRUE;
  73. bRet = FALSE;
  74. }
  75. return (bRet);
  76. }
  77. else
  78. {
  79. ASSERT(puNextPage);
  80. // if we've travelled through external apprentice pages,
  81. // it's easy for our current page pointer to get munged,
  82. // so reset it here for sanity's sake.
  83. gpWizardState->uCurrentPage = ORD_PAGE_REFSERVDIAL;
  84. SetNextPage(hDlg, puNextPage, NULL);
  85. //
  86. // Display the messages
  87. //
  88. TCHAR szTemp[MAX_MESSAGE_LEN];
  89. if (gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_AUTOCONFIG)
  90. {
  91. LoadString(g_hInstance, IDS_REFDIAL_1, szTemp, MAX_MESSAGE_LEN);
  92. SetWindowText(GetDlgItem(hDlg, IDC_REFDIAL_TEXT), szTemp);
  93. }
  94. else
  95. {
  96. TCHAR szIntro[MAX_MESSAGE_LEN];
  97. LoadString(g_hInstance, IDS_REFDIAL_1, szIntro, MAX_MESSAGE_LEN);
  98. LoadString(g_hInstance, IDS_REFDIAL_2, szTemp, MAX_MESSAGE_LEN);
  99. lstrcat(szIntro, szTemp);
  100. SetWindowText(GetDlgItem(hDlg, IDC_REFDIAL_TEXT), szIntro);
  101. }
  102. gpWizardState->pRefDial->DoInit();
  103. }
  104. return bRet;
  105. }
  106. BOOL CALLBACK RefServDialPostInitProc
  107. (
  108. HWND hDlg,
  109. BOOL fFirstInit,
  110. UINT *puNextPage
  111. )
  112. {
  113. BOOL bRet = TRUE;
  114. if (!fFirstInit)
  115. {
  116. // Force the Window to update
  117. UpdateWindow(GetParent(hDlg));
  118. gpWizardState->bDoneRefServRAS = FALSE;
  119. gpWizardState->bStartRefServDownload = FALSE;
  120. gpWizardState->bDoneRefServDownload = FALSE;
  121. if (!gpWizardState->iRedialCount)
  122. // If it's not a redial blank out the status text
  123. SetWindowText(GetDlgItem(hDlg, IDC_REFSERV_DIALSTATUS), TEXT(""));
  124. if (!gpWizardState->bDoUserPick)
  125. {
  126. BSTR bstrPhoneNum = NULL;
  127. DWORD dwFlag = (gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_AUTOCONFIG) ? ICW_CFGFLAG_AUTOCONFIG : 0;
  128. BOOL bRetVal;
  129. dwFlag |= gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_SBS;
  130. // Setup for Dialing. This will ensure that we are ready to dial.
  131. gpWizardState->pRefDial->SetupForDialing(A2W(TEXT("msicw.isp")),
  132. gpWizardState->cmnStateData.dwCountryCode,
  133. A2W(gpWizardState->cmnStateData.szAreaCode),
  134. dwFlag,
  135. &bRetVal);
  136. // if /branding switch is not specified in command line, alloffers become true.
  137. if (!(gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_DO_NOT_OVERRIDE_ALLOFFERS))
  138. gpWizardState->pRefDial->put_AllOfferCode(1);
  139. // We override oem, product and promo codes with the one from command line if there is.
  140. if ( *g_szOemCode || *g_szPromoCode ||
  141. gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_PRODCODE_FROM_CMDLINE )
  142. {
  143. BSTR bstrTmp;
  144. if( *g_szOemCode )
  145. bstrTmp = A2W(g_szOemCode);
  146. else
  147. bstrTmp = A2W(DEFAULT_OEMCODE);
  148. gpWizardState->pRefDial->put_OemCode(bstrTmp);
  149. if( gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_PRODCODE_FROM_CMDLINE )
  150. bstrTmp = A2W(g_szProductCode);
  151. else
  152. bstrTmp = A2W(DEFAULT_PRODUCTCODE);
  153. gpWizardState->pRefDial->put_ProductCode(bstrTmp);
  154. if( *g_szPromoCode )
  155. bstrTmp = A2W(g_szPromoCode);
  156. else
  157. bstrTmp = A2W(DEFAULT_PROMOCODE);
  158. gpWizardState->pRefDial->put_PromoCode(bstrTmp);
  159. // if any of /oem, /prod, or /promo is specified in command line, Alloffers becomes false
  160. gpWizardState->pRefDial->put_AllOfferCode(0);
  161. }
  162. if(gpWizardState->cmnStateData.dwFlags & ICW_CFGFLAG_AUTOCONFIG)
  163. gpWizardState->pRefDial->put_AllOfferCode(1);
  164. if (bRetVal)
  165. {
  166. // Show the phone Number
  167. gpWizardState->pRefDial->get_DialPhoneNumber(&bstrPhoneNum);
  168. SetWindowText(GetDlgItem(hDlg, IDC_REFSERV_PHONENUM), W2A(bstrPhoneNum));
  169. if (ERROR_SUCCESS == gpWizardState->pRefDial->FormReferralServerURL(&bRetVal))
  170. {
  171. gpWizardState->pRefDial->DoConnect(&bRetVal);
  172. }
  173. else
  174. {
  175. // BUGBUG: Throw error message
  176. gfQuitWizard = TRUE;
  177. bRet = FALSE;
  178. }
  179. }
  180. else
  181. {
  182. //gpWizardState->pRefDial->SelectedPhoneNumber(1, &bRetVal);
  183. gpWizardState->pRefDial->get_UserPickNumber(&bRetVal);
  184. if (bRetVal)
  185. {
  186. gpWizardState->bDoUserPick = TRUE;
  187. // Simulate the press of the NEXT button
  188. PropSheet_PressButton(GetParent(hDlg),PSBTN_NEXT);
  189. bRet = TRUE;
  190. }
  191. else
  192. {
  193. gpWizardState->pRefDial->get_QuitWizard(&bRetVal);
  194. if (bRetVal)
  195. {
  196. gfQuitWizard = TRUE;
  197. bRet = FALSE;
  198. }
  199. else
  200. {
  201. gpWizardState->pRefDial->get_TryAgain(&bRetVal);
  202. if (bRetVal)
  203. {
  204. PropSheet_PressButton(GetParent(hDlg),PSBTN_BACK);
  205. }
  206. else
  207. {
  208. PropSheet_PressButton(GetParent(hDlg),PSBTN_NEXT);
  209. }
  210. }
  211. }
  212. }
  213. SysFreeString(bstrPhoneNum);
  214. }
  215. else // else (!gpWizardState->bDoUserPick)
  216. {
  217. BOOL bRetVal;
  218. BSTR bstrPhoneNum = NULL;
  219. // Have we selected a phone number from Multi number page?
  220. if (gpWizardState->lSelectedPhoneNumber != -1)
  221. {
  222. gpWizardState->pRefDial->SelectedPhoneNumber(gpWizardState->lSelectedPhoneNumber, &bRetVal);
  223. gpWizardState->lSelectedPhoneNumber = -1;
  224. }
  225. // Show the phone Number
  226. gpWizardState->pRefDial->get_DialPhoneNumber(&bstrPhoneNum);
  227. SetWindowText(GetDlgItem(hDlg, IDC_REFSERV_PHONENUM), W2A(bstrPhoneNum));
  228. SysFreeString(bstrPhoneNum);
  229. gpWizardState->pRefDial->FormReferralServerURL(&bRetVal);
  230. gpWizardState->pRefDial->DoConnect(&bRetVal);
  231. gpWizardState->bDoUserPick = FALSE;
  232. }
  233. } // endif (!Firstinit)
  234. return bRet;
  235. }
  236. /*******************************************************************
  237. NAME: RefServDialOKProc
  238. SYNOPSIS: Called when Next or Back btns pressed from page
  239. ENTRY: hDlg - dialog window
  240. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  241. puNextPage - if 'Next' was pressed,
  242. proc can fill this in with next page to go to. This
  243. parameter is ingored if 'Back' was pressed.
  244. pfKeepHistory - page will not be kept in history if
  245. proc fills this in with FALSE.
  246. EXIT: returns TRUE to allow page to be turned, FALSE
  247. to keep the same page.
  248. ********************************************************************/
  249. BOOL CALLBACK RefServDialOKProc
  250. (
  251. HWND hDlg,
  252. BOOL fForward,
  253. UINT *puNextPage,
  254. BOOL *pfKeepHistory
  255. )
  256. {
  257. ASSERT(puNextPage);
  258. //Load the External Pages here
  259. if (fForward)
  260. {
  261. *pfKeepHistory = FALSE;
  262. // BUGBUG move this to the global state
  263. if (gpWizardState->bDoUserPick)
  264. {
  265. *puNextPage = ORD_PAGE_MULTINUMBER;
  266. return TRUE;
  267. }
  268. gpWizardState->bDoUserPick = TRUE;
  269. if (gpWizardState->bDoneRefServDownload)
  270. {
  271. // BUGBUG, need to set a legit last page, maybe!
  272. int iReturnPage = gpWizardState->uPageHistory[gpWizardState->uPagesCompleted - 1];
  273. // Set it so that We will read the new ispinfo.csv in incwconn.dll
  274. gpWizardState->cmnStateData.bParseIspinfo = TRUE;
  275. //Make sure we really have a file to parse, other bail to server error
  276. HANDLE hFile = CreateFile((LPCTSTR)cszISPINFOPath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
  277. if (INVALID_HANDLE_VALUE != hFile)
  278. {
  279. CloseHandle(hFile);
  280. gpWizardState->pRefDial->get_bIsISDNDevice(&gpWizardState->cmnStateData.bIsISDNDevice);
  281. if (LoadICWCONNUI(GetParent(hDlg), GetDlgIDFromIndex(iReturnPage), IDD_PAGE_DEFAULT, gpWizardState->cmnStateData.dwFlags))
  282. {
  283. if( DialogIDAlreadyInUse( g_uICWCONNUIFirst) )
  284. {
  285. // we're about to jump into the external apprentice, and we don't want
  286. // this page to show up in our history list
  287. BOOL bRetVal;
  288. *pfKeepHistory = FALSE;
  289. *puNextPage = g_uICWCONNUIFirst;
  290. gpWizardState->pRefDial->RemoveConnectoid(&bRetVal);
  291. gpWizardState->bDoUserPick = 0;
  292. // Backup 1 in the history list, since we the external pages navigate back
  293. // we want this history list to be in the correct spot. Normally
  294. // pressing back would back up the history list, and figure out where to
  295. // go, but in this case, the external DLL just jumps right back in.
  296. gpWizardState->uPagesCompleted--;
  297. }
  298. else
  299. {
  300. }
  301. }
  302. }
  303. else
  304. {
  305. // server error
  306. *puNextPage = ORD_PAGE_REFSERVERR;
  307. }
  308. }
  309. else
  310. {
  311. if (gpWizardState->bDoneRefServRAS)
  312. {
  313. // server error
  314. *puNextPage = ORD_PAGE_REFSERVERR;
  315. }
  316. else
  317. {
  318. //OK so we had a dialing error but let's figure out which one...
  319. HRESULT hrDialErr;
  320. gpWizardState->pRefDial->get_DialError(&hrDialErr);
  321. switch (hrDialErr)
  322. {
  323. case ERROR_LINE_BUSY: //Line is engaged
  324. {
  325. if (gpWizardState->iRedialCount < NUM_MAX_REDIAL)
  326. {
  327. //Redial
  328. // Initialze status before connecting
  329. gpWizardState->lRefDialTerminateStatus = ERROR_SUCCESS;
  330. gpWizardState->bDoneRefServDownload = FALSE;
  331. gpWizardState->bDoneRefServRAS = FALSE;
  332. gpWizardState->bStartRefServDownload = FALSE;
  333. // Assume the user has selected a number on this page
  334. // So we will not do SetupForDialing again next time
  335. gpWizardState->bDoUserPick = TRUE;
  336. *puNextPage = ORD_PAGE_REFSERVDIAL;
  337. gpWizardState->iRedialCount++;
  338. break;
  339. }
  340. gpWizardState->iRedialCount = 0;
  341. }
  342. default:
  343. {
  344. // nothing special just goto the dialing error page
  345. *puNextPage = ORD_PAGE_REFDIALERROR;
  346. break;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. else // a retry is simulated when BACK is pressed
  353. {
  354. *puNextPage = ORD_PAGE_REFSERVDIAL;
  355. }
  356. return TRUE;
  357. }
  358. BOOL CALLBACK RefServDialCancelProc(HWND hDlg)
  359. {
  360. ASSERT(gpWizardState->pRefDial);
  361. //User has canceled so reset the redial count
  362. gpWizardState->iRedialCount = 0;
  363. gpWizardState->pRefDial->DoHangup();
  364. //We should make sure the wiz thinks it's a dialerr to avoid
  365. //the server error page
  366. gpWizardState->bStartRefServDownload = FALSE;
  367. gpWizardState->bDoneRefServDownload = FALSE;
  368. gpWizardState->bDoneRefServRAS = FALSE;
  369. gpWizardState->bDoUserPick = FALSE;
  370. gpWizardState->lRefDialTerminateStatus = ERROR_CANCELLED;
  371. PropSheet_PressButton(GetParent(hDlg),PSBTN_NEXT);
  372. return TRUE;
  373. }