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.

1859 lines
56 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994-1995 **
  4. //*********************************************************************
  5. //
  6. // MAILUI.C - Functions for mail/newsgroup configuration UI
  7. //
  8. //
  9. // HISTORY:
  10. //
  11. // 1/9/95 jeremys Created.
  12. // 96/03/25 markdu If a fatal error occurs, set gfQuitWizard.
  13. // 96/03/26 markdu Store values from UI even when back is pressed.
  14. // 96/04/06 markdu Moved CommitConfigurationChanges call to last page.
  15. // 96/05/06 markdu NASH BUG 15637 Removed unused code.
  16. // 96/05/14 markdu NASH BUG 22681 Took out mail and news pages.
  17. //
  18. #include "wizard.h"
  19. #include "icwextsn.h"
  20. #include "icwaprtc.h"
  21. #include "imnext.h"
  22. // Local types for parsing proxy settings
  23. typedef enum {
  24. INTERNET_SCHEME_DEFAULT,
  25. INTERNET_SCHEME_FTP,
  26. INTERNET_SCHEME_GOPHER,
  27. INTERNET_SCHEME_HTTP,
  28. INTERNET_SCHEME_HTTPS,
  29. INTERNET_SCHEME_SOCKS,
  30. INTERNET_SCHEME_UNKNOWN
  31. } INTERNET_SCHEME;
  32. typedef enum {
  33. STATE_START,
  34. STATE_PROTOCOL,
  35. STATE_SCHEME,
  36. STATE_SERVER,
  37. STATE_PORT,
  38. STATE_END,
  39. STATE_ERROR
  40. } PARSER_STATE;
  41. typedef struct {
  42. LPTSTR SchemeName;
  43. DWORD SchemeLength;
  44. INTERNET_SCHEME SchemeType;
  45. DWORD dwControlId;
  46. DWORD dwPortControlId;
  47. } URL_SCHEME;
  48. const URL_SCHEME UrlSchemeList[] = {
  49. TEXT("http"), 4, INTERNET_SCHEME_HTTP, IDC_PROXYHTTP, IDC_PORTHTTP,
  50. TEXT("https"), 5, INTERNET_SCHEME_HTTPS, IDC_PROXYSECURE,IDC_PORTSECURE,
  51. TEXT("ftp"), 3, INTERNET_SCHEME_FTP, IDC_PROXYFTP, IDC_PORTFTP,
  52. TEXT("gopher"), 6, INTERNET_SCHEME_GOPHER, IDC_PROXYGOPHER,IDC_PORTGOPHER,
  53. TEXT("socks"), 5, INTERNET_SCHEME_SOCKS, IDC_PROXYSOCKS, IDC_PORTSOCKS,
  54. NULL, 0, INTERNET_SCHEME_DEFAULT,0,0
  55. };
  56. typedef struct tagNEWPROFILEDLGINFO
  57. {
  58. HWND hwndCombo; // hwnd of combo box on parent dialog
  59. TCHAR szNewProfileName[cchProfileNameMax+1]; // return buffer for chosen name
  60. } NEWPROFILEDLGINFO;
  61. const TCHAR cszLocalString[] = TEXT("<local>");
  62. #define GET_TERMINATOR(string) \
  63. while(*string != '\0') string++
  64. #define ERROR_SERVER_NAME 4440
  65. #define ERROR_PORT_NUM 4441
  66. #define INTERNET_MAX_PORT_LENGTH sizeof(TEXT("123456789"))
  67. VOID EnableProxyControls(HWND hDlg);
  68. VOID ReplicatePROXYHTTP(HWND hDlg, BOOL bSaveOrig);
  69. VOID ReplicatePORTHTTP(HWND hDlg, BOOL bSaveOrig);
  70. BOOL ParseProxyInfo(HWND hDlg, LPTSTR lpszProxy);
  71. BOOL ParseEditCtlForPort(
  72. IN OUT LPTSTR lpszProxyName,
  73. IN HWND hDlg,
  74. IN DWORD dwProxyNameCtlId,
  75. IN DWORD dwProxyPortCtlId
  76. );
  77. DWORD FormatOutProxyEditCtl(
  78. IN HWND hDlg,
  79. IN DWORD dwProxyNameCtlId,
  80. IN DWORD dwProxyPortCtlId,
  81. OUT LPTSTR lpszOutputStr,
  82. IN OUT LPDWORD lpdwOutputStrSize,
  83. IN DWORD dwOutputStrLength,
  84. IN BOOL fDefaultProxy
  85. );
  86. BOOL RemoveLocalFromExceptionList(LPTSTR lpszExceptionList);
  87. INT_PTR CALLBACK NewProfileDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  88. LPARAM lParam);
  89. BOOL NewProfileDlgInit(HWND hDlg,NEWPROFILEDLGINFO * pNewProfileDlgInfo);
  90. BOOL NewProfileDlgOK(HWND hDlg,NEWPROFILEDLGINFO * pNewProfileDlgInfo);
  91. BOOL DoNewProfileDlg(HWND hDlg);
  92. TCHAR gszHttpProxy [MAX_URL_STRING+1] = TEXT("\0");
  93. TCHAR gszHttpPort [INTERNET_MAX_PORT_LENGTH+1] = TEXT("\0");
  94. TCHAR gszSecureProxy [MAX_URL_STRING+1] = TEXT("\0");
  95. TCHAR gszSecurePort [INTERNET_MAX_PORT_LENGTH+1] = TEXT("\0");
  96. TCHAR gszFtpProxy [MAX_URL_STRING+1] = TEXT("\0");
  97. TCHAR gszFtpPort [INTERNET_MAX_PORT_LENGTH+1] = TEXT("\0");
  98. TCHAR gszGopherProxy [MAX_URL_STRING+1] = TEXT("\0");
  99. TCHAR gszGopherPort [INTERNET_MAX_PORT_LENGTH+1] = TEXT("\0");
  100. /*******************************************************************
  101. NAME: UseProxyInitProc
  102. SYNOPSIS: Called when Use Proxy page is displayed
  103. ENTRY: hDlg - dialog window
  104. fFirstInit - TRUE if this is the first time the dialog
  105. is initialized, FALSE if this InitProc has been called
  106. before (e.g. went past this page and backed up)
  107. ********************************************************************/
  108. BOOL CALLBACK UseProxyInitProc(HWND hDlg,BOOL fFirstInit)
  109. {
  110. if (fFirstInit)
  111. {
  112. //
  113. // 6/6/97 jmazner Olympus #5413
  114. // tweak positioning to hack around win95 J display bug
  115. //
  116. Win95JMoveDlgItem( hDlg, GetDlgItem(hDlg,IDC_NOTE), 15 );
  117. CheckDlgButton(hDlg,IDC_USEPROXY,gpUserInfo->fProxyEnable);
  118. CheckDlgButton(hDlg,IDC_NOUSEPROXY,!gpUserInfo->fProxyEnable);
  119. }
  120. // if we've travelled through external apprentice pages,
  121. // it's easy for our current page pointer to get munged,
  122. // so reset it here for sanity's sake.
  123. gpWizardState->uCurrentPage = ORD_PAGE_USEPROXY;
  124. return TRUE;
  125. }
  126. /*******************************************************************
  127. NAME: UseProxyOKProc
  128. SYNOPSIS: Called when Next or Back btns pressed from Use Proxy page
  129. ENTRY: hDlg - dialog window
  130. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  131. puNextPage - if 'Next' was pressed,
  132. proc can fill this in with next page to go to. This
  133. parameter is ingored if 'Back' was pressed.
  134. pfKeepHistory - page will not be kept in history if
  135. proc fills this in with FALSE.
  136. EXIT: returns TRUE to allow page to be turned, FALSE
  137. to keep the same page.
  138. ********************************************************************/
  139. BOOL CALLBACK UseProxyOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  140. BOOL * pfKeepHistory)
  141. {
  142. ASSERT(puNextPage);
  143. gpUserInfo->fProxyEnable = IsDlgButtonChecked(hDlg,IDC_USEPROXY);
  144. if (fForward)
  145. {
  146. if (gpUserInfo->fProxyEnable)
  147. *puNextPage = ORD_PAGE_SETUP_PROXY;//ORD_PAGE_PROXYSERVERS;
  148. else
  149. {
  150. if( LoadAcctMgrUI(GetParent(hDlg),
  151. g_fIsWizard97 ? IDD_PAGE_USEPROXY97 : IDD_PAGE_USEPROXY,
  152. g_fIsWizard97 ? IDD_PAGE_CONNECTEDOK97FIRSTLAST : IDD_PAGE_CONNECTEDOK,
  153. g_fIsWizard97 ? WIZ_USE_WIZARD97 : 0) )
  154. {
  155. if( DialogIDAlreadyInUse( g_uAcctMgrUIFirst) )
  156. {
  157. // we're about to jump into the external apprentice, and we don't want
  158. // this page to show up in our history list
  159. *pfKeepHistory = FALSE;
  160. *puNextPage = g_uAcctMgrUIFirst;
  161. }
  162. else
  163. {
  164. DEBUGMSG("hmm, the first acctMgr dlg id is supposedly %d, but it's not marked as in use!",
  165. g_uAcctMgrUIFirst);
  166. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  167. }
  168. }
  169. else
  170. {
  171. DEBUGMSG("LoadAcctMgrUI returned false, guess we'd better skip over it!");
  172. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  173. }
  174. }
  175. }
  176. return TRUE;
  177. }
  178. /*******************************************************************
  179. NAME: UseProxyCmdProc
  180. SYNOPSIS: Called when dlg control pressed on page
  181. ENTRY: hDlg - dialog window
  182. uCtrlID - control ID of control that was touched
  183. ********************************************************************/
  184. BOOL CALLBACK UseProxyCmdProc(HWND hDlg,WPARAM wParam,LPARAM lParam)
  185. {
  186. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  187. {
  188. case BN_DBLCLK:
  189. {
  190. switch (GET_WM_COMMAND_ID(wParam, lParam))
  191. {
  192. case IDC_USEPROXY:
  193. case IDC_NOUSEPROXY:
  194. {
  195. // somebody double-clicked a radio button
  196. // auto-advance to the next page
  197. PropSheet_PressButton(GetParent(hDlg), PSBTN_NEXT);
  198. break;
  199. }
  200. }
  201. break;
  202. }
  203. }
  204. return TRUE;
  205. }
  206. /*******************************************************************
  207. NAME: ProxyServersInitProc
  208. SYNOPSIS: Called when proxy servers page is displayed
  209. ENTRY: hDlg - dialog window
  210. fFirstInit - TRUE if this is the first time the dialog
  211. is initialized, FALSE if this InitProc has been called
  212. before (e.g. went past this page and backed up)
  213. ********************************************************************/
  214. BOOL CALLBACK ProxyServersInitProc(HWND hDlg,BOOL fFirstInit)
  215. {
  216. if (fFirstInit)
  217. {
  218. //
  219. // 6/6/97 jmazner Olympus #5413
  220. // tweak positioning to hack around win95 J display bug
  221. //
  222. // 15/09/98 vyung
  223. // Test team find that this introduces a tab order bug
  224. // The Win95 J bug is not repro, so this is removed
  225. // Win95JMoveDlgItem( hDlg, GetDlgItem(hDlg,IDC_NOTE), 15 );
  226. // Win95JMoveDlgItem( hDlg, GetDlgItem(hDlg,IDC_PROXYSAME), 160 );
  227. // limit text fields appropriately
  228. // 31/10/98 vyung
  229. // IE CPL removes the text limit on the edit boxes, do so here.
  230. //
  231. /*
  232. SendDlgItemMessage(hDlg,IDC_PROXYHTTP,EM_LIMITTEXT,MAX_URL_STRING,0L);
  233. SendDlgItemMessage(hDlg,IDC_PROXYSECURE,EM_LIMITTEXT,MAX_URL_STRING,0L);
  234. SendDlgItemMessage(hDlg,IDC_PROXYFTP,EM_LIMITTEXT,MAX_URL_STRING,0L);
  235. SendDlgItemMessage(hDlg,IDC_PROXYGOPHER,EM_LIMITTEXT,MAX_URL_STRING,0L);
  236. SendDlgItemMessage(hDlg,IDC_PROXYSOCKS,EM_LIMITTEXT,MAX_URL_STRING,0L);
  237. SendDlgItemMessage(hDlg,IDC_PORTHTTP,EM_LIMITTEXT,INTERNET_MAX_PORT_LENGTH,0L);
  238. SendDlgItemMessage(hDlg,IDC_PORTSECURE,EM_LIMITTEXT,INTERNET_MAX_PORT_LENGTH,0L);
  239. SendDlgItemMessage(hDlg,IDC_PORTFTP,EM_LIMITTEXT,INTERNET_MAX_PORT_LENGTH,0L);
  240. SendDlgItemMessage(hDlg,IDC_PORTGOPHER,EM_LIMITTEXT,INTERNET_MAX_PORT_LENGTH,0L);
  241. SendDlgItemMessage(hDlg,IDC_PORTSOCKS,EM_LIMITTEXT,INTERNET_MAX_PORT_LENGTH,0L);
  242. */
  243. ParseProxyInfo(hDlg,gpUserInfo->szProxyServer);
  244. }
  245. EnableProxyControls(hDlg);
  246. return TRUE;
  247. }
  248. /*******************************************************************
  249. NAME: ProxyServersOKProc
  250. SYNOPSIS: Called when Next or Back btns pressed from proxy server page
  251. ENTRY: hDlg - dialog window
  252. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  253. puNextPage - if 'Next' was pressed,
  254. proc can fill this in with next page to go to. This
  255. parameter is ingored if 'Back' was pressed.
  256. pfKeepHistory - page will not be kept in history if
  257. proc fills this in with FALSE.
  258. EXIT: returns TRUE to allow page to be turned, FALSE
  259. to keep the same page.
  260. ********************************************************************/
  261. BOOL CALLBACK ProxyServersOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  262. BOOL * pfKeepHistory)
  263. {
  264. ASSERT(puNextPage);
  265. DWORD dwProxyServerLen;
  266. DWORD dwErr;
  267. TCHAR szNewProxyString[MAX_REG_LEN+1];
  268. if (fForward)
  269. {
  270. // jmazner 11/9/96 Normandy #6937
  271. // clear out previous contents of gpUserInfo->szProxyServer
  272. // before we start filling in the new contents
  273. //
  274. // 7/10/97 jmazner Olympus #9365
  275. // we want to preserve the orginial proxy string, so use a copy for
  276. // the call to FormatOytProxyEditCtl
  277. //
  278. ZeroMemory(szNewProxyString,sizeof(szNewProxyString));
  279. if (IsDlgButtonChecked(hDlg, IDC_PROXYSAME))
  280. {
  281. dwProxyServerLen = 0;
  282. dwErr = FormatOutProxyEditCtl(hDlg,IDC_PROXYHTTP,IDC_PORTHTTP,
  283. szNewProxyString,
  284. &dwProxyServerLen,
  285. sizeof(szNewProxyString),
  286. TRUE);
  287. if (ERROR_SUCCESS != dwErr)
  288. {
  289. if (ERROR_PORT_NUM == dwErr)
  290. DisplayFieldErrorMsg(hDlg,IDC_PORTHTTP,IDS_INVALID_PORTNUM);
  291. else
  292. DisplayFieldErrorMsg(hDlg,IDC_PROXYHTTP,IDS_ERRProxyRequired);
  293. return FALSE;
  294. }
  295. }
  296. else
  297. {
  298. dwProxyServerLen = 0;
  299. int i = 0;
  300. while (UrlSchemeList[i].SchemeLength)
  301. {
  302. dwErr = FormatOutProxyEditCtl(hDlg,
  303. UrlSchemeList[i].dwControlId,
  304. UrlSchemeList[i].dwPortControlId,
  305. szNewProxyString,
  306. &dwProxyServerLen,
  307. sizeof(szNewProxyString),
  308. FALSE);
  309. switch( dwErr )
  310. {
  311. case ERROR_SUCCESS:
  312. case ERROR_SERVER_NAME:
  313. break;
  314. case ERROR_PORT_NUM:
  315. DisplayFieldErrorMsg(hDlg,UrlSchemeList[i].dwPortControlId,IDS_INVALID_PORTNUM);
  316. return FALSE;
  317. case ERROR_NOT_ENOUGH_MEMORY:
  318. MsgBox(NULL,IDS_ERROutOfMemory,MB_ICONEXCLAMATION,MB_OK);
  319. return FALSE;
  320. }
  321. i++;
  322. }
  323. //
  324. // 6/2/97 jmazner Olympus #4411
  325. // Allow some proxy servers to be null. Only warn if no server
  326. // names were entered.
  327. //
  328. if( 0 == lstrlen(szNewProxyString) )
  329. {
  330. DisplayFieldErrorMsg(hDlg,IDC_PROXYHTTP,IDS_ERRProxyRequired);
  331. return FALSE;
  332. }
  333. }
  334. //
  335. // if we made it this far, then the new proxy settings are valid, so
  336. // now copy them back into the main data structure.
  337. //
  338. lstrcpyn(gpUserInfo->szProxyServer, szNewProxyString, ARRAYSIZE(gpUserInfo->szProxyServer));
  339. *puNextPage = ORD_PAGE_PROXYEXCEPTIONS;
  340. }
  341. return TRUE;
  342. }
  343. /*******************************************************************
  344. NAME: ProxyServersCmdProc
  345. SYNOPSIS: Called when dlg control pressed on page
  346. ENTRY: hDlg - dialog window
  347. uCtrlID - control ID of control that was touched
  348. ********************************************************************/
  349. BOOL CALLBACK ProxyServersCmdProc(HWND hDlg,WPARAM wParam,LPARAM lParam)
  350. {
  351. switch (GET_WM_COMMAND_ID(wParam, lParam))
  352. {
  353. case IDC_PROXYSAME:
  354. // checkbox state changed, enable controls appropriately
  355. EnableProxyControls(hDlg);
  356. break;
  357. case IDC_PROXYHTTP:
  358. case IDC_PORTHTTP:
  359. if ( GET_WM_COMMAND_CMD(wParam, lParam) == EN_KILLFOCUS )
  360. {
  361. // if heckbox state enabled, populate info but don't save it
  362. if (IsDlgButtonChecked(hDlg,IDC_PROXYSAME))
  363. {
  364. ReplicatePROXYHTTP(hDlg, FALSE);
  365. ReplicatePORTHTTP(hDlg, FALSE);
  366. }
  367. }
  368. break;
  369. }
  370. return TRUE;
  371. }
  372. /*******************************************************************
  373. NAME: SetupProxyInitProc
  374. SYNOPSIS: Called when proxy servers page is displayed
  375. ENTRY: hDlg - dialog window
  376. fFirstInit - TRUE if this is the first time the dialog
  377. is initialized, FALSE if this InitProc has been called
  378. before (e.g. went past this page and backed up)
  379. ********************************************************************/
  380. BOOL CALLBACK SetupProxyInitProc(HWND hDlg,BOOL fFirstInit)
  381. {
  382. if (fFirstInit)
  383. {
  384. TCHAR szTemp[MAX_RES_LEN*2];
  385. LoadString(ghInstance, IDS_SETUP_PROXY_INTRO, szTemp, MAX_RES_LEN*2);
  386. SetWindowText(GetDlgItem(hDlg, IDC_AUTODISCOVERY_TEXT), szTemp);
  387. // Set the auto discovery check box
  388. if (gpUserInfo->bAutoDiscovery)
  389. CheckDlgButton(hDlg,IDC_AUTODISCOVER, BST_CHECKED);
  390. // Set the autoconfig URL text box
  391. SetWindowText(GetDlgItem(hDlg, IDC_CONFIG_ADDR),
  392. gpUserInfo->szAutoConfigURL);
  393. // Set the Auto config URL checkbox
  394. CheckDlgButton(hDlg,IDC_CONFIGSCRIPT, gpUserInfo->bAutoConfigScript ? BST_CHECKED : BST_UNCHECKED);
  395. EnableWindow(GetDlgItem(hDlg, IDC_CONFIGADDR_TX), gpUserInfo->bAutoConfigScript);
  396. EnableWindow(GetDlgItem(hDlg, IDC_CONFIG_ADDR), gpUserInfo->bAutoConfigScript);
  397. // Set the manual checkbox
  398. CheckDlgButton(hDlg,IDC_MANUAL_PROXY,gpUserInfo->fProxyEnable);
  399. }
  400. gpWizardState->uCurrentPage = ORD_PAGE_SETUP_PROXY;
  401. return TRUE;
  402. }
  403. /*******************************************************************
  404. NAME: SetupProxyOKProc
  405. SYNOPSIS: Called when Next or Back btns pressed from proxy server page
  406. ENTRY: hDlg - dialog window
  407. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  408. puNextPage - if 'Next' was pressed,
  409. proc can fill this in with next page to go to. This
  410. parameter is ingored if 'Back' was pressed.
  411. pfKeepHistory - page will not be kept in history if
  412. proc fills this in with FALSE.
  413. EXIT: returns TRUE to allow page to be turned, FALSE
  414. to keep the same page.
  415. ********************************************************************/
  416. BOOL CALLBACK SetupProxyOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  417. BOOL * pfKeepHistory)
  418. {
  419. ASSERT(puNextPage);
  420. if (fForward && gpUserInfo)
  421. {
  422. // modify setting, later write to registry
  423. gpUserInfo->bAutoDiscovery = IsDlgButtonChecked(hDlg, IDC_AUTODISCOVER);
  424. gpUserInfo->bAutoConfigScript = IsDlgButtonChecked(hDlg, IDC_CONFIGSCRIPT);
  425. if (gpUserInfo->bAutoConfigScript)
  426. {
  427. GetWindowText(GetDlgItem(hDlg, IDC_CONFIG_ADDR),
  428. gpUserInfo->szAutoConfigURL,
  429. MAX_URL_STRING+1);
  430. }
  431. gpUserInfo->fProxyEnable = IsDlgButtonChecked(hDlg, IDC_MANUAL_PROXY);
  432. if (gpUserInfo->fProxyEnable)
  433. {
  434. *puNextPage = ORD_PAGE_PROXYSERVERS;
  435. }
  436. else
  437. {
  438. if( LoadAcctMgrUI(GetParent(hDlg),
  439. g_fIsWizard97 ? IDD_PAGE_SETUP_PROXY97 : IDD_PAGE_SETUP_PROXY,
  440. g_fIsWizard97 ? IDD_PAGE_CONNECTEDOK97FIRSTLAST : IDD_PAGE_CONNECTEDOK,
  441. g_fIsWizard97 ? WIZ_USE_WIZARD97 : 0) )
  442. {
  443. if( DialogIDAlreadyInUse( g_uAcctMgrUIFirst) )
  444. {
  445. // we're about to jump into the external apprentice, and we don't want
  446. // this page to show up in our history list
  447. *pfKeepHistory = FALSE;
  448. *puNextPage = g_uAcctMgrUIFirst;
  449. }
  450. else
  451. {
  452. DEBUGMSG("hmm, the first acctMgr dlg id is supposedly %d, but it's not marked as in use!",
  453. g_uAcctMgrUIFirst);
  454. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  455. }
  456. }
  457. else
  458. {
  459. DEBUGMSG("LoadAcctMgrUI returned false, guess we'd better skip over it!");
  460. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  461. }
  462. }
  463. }
  464. return TRUE;
  465. }
  466. /*******************************************************************
  467. NAME: SetupProxyCmdProc
  468. SYNOPSIS: Called when dlg control pressed on page
  469. ENTRY: hDlg - dialog window
  470. uCtrlID - control ID of control that was touched
  471. ********************************************************************/
  472. BOOL CALLBACK SetupProxyCmdProc(HWND hDlg,WPARAM wParam,LPARAM lParam)
  473. {
  474. switch (GET_WM_COMMAND_ID(wParam, lParam))
  475. {
  476. case IDC_CONFIGSCRIPT:
  477. {
  478. BOOL bChecked = IsDlgButtonChecked(hDlg, IDC_CONFIGSCRIPT);
  479. EnableWindow(GetDlgItem(hDlg, IDC_CONFIGADDR_TX), bChecked);
  480. EnableWindow(GetDlgItem(hDlg, IDC_CONFIG_ADDR), bChecked);
  481. }
  482. break;
  483. }
  484. return TRUE;
  485. }
  486. /*******************************************************************
  487. NAME: EnableProxyControls
  488. SYNOPSIS: Enables edit controls on Proxy Server page depending on
  489. whether or not 'use proxy...' checkbox is checked.
  490. ********************************************************************/
  491. VOID EnableProxyControls(HWND hDlg)
  492. {
  493. static BOOL fDifferentProxies = TRUE;
  494. BOOL fChanged = TRUE;
  495. fChanged = ( fDifferentProxies != !IsDlgButtonChecked(hDlg,IDC_PROXYSAME) );
  496. fDifferentProxies = !IsDlgButtonChecked(hDlg,IDC_PROXYSAME);
  497. EnableDlgItem(hDlg,IDC_TX_PROXYSECURE,fDifferentProxies);
  498. EnableDlgItem(hDlg,IDC_PROXYSECURE,fDifferentProxies);
  499. EnableDlgItem(hDlg,IDC_PORTSECURE,fDifferentProxies);
  500. EnableDlgItem(hDlg,IDC_TX_PROXYFTP,fDifferentProxies);
  501. EnableDlgItem(hDlg,IDC_PROXYFTP,fDifferentProxies);
  502. EnableDlgItem(hDlg,IDC_PORTFTP,fDifferentProxies);
  503. EnableDlgItem(hDlg,IDC_TX_PROXYGOPHER,fDifferentProxies);
  504. EnableDlgItem(hDlg,IDC_PROXYGOPHER,fDifferentProxies);
  505. EnableDlgItem(hDlg,IDC_PORTGOPHER,fDifferentProxies);
  506. EnableDlgItem(hDlg,IDC_TX_PROXYSOCKS,fDifferentProxies);
  507. EnableDlgItem(hDlg,IDC_PROXYSOCKS,fDifferentProxies);
  508. EnableDlgItem(hDlg,IDC_PORTSOCKS,fDifferentProxies);
  509. if( fChanged )
  510. {
  511. if( !fDifferentProxies )
  512. {
  513. //
  514. // 7/10/97 jmazner Olympus #9365
  515. // behave more like IE's proxy property sheet, copy the http
  516. // settings to all other fields except SOCKS, which should be empty.
  517. //
  518. ReplicatePROXYHTTP(hDlg, TRUE);
  519. ReplicatePORTHTTP(hDlg, TRUE);
  520. }
  521. else
  522. {
  523. //
  524. // reload the current settings for all protocols. First, however,
  525. // make a copy of any changes the user has made to http, then write
  526. // that back in after reloading the defaults.
  527. //
  528. TCHAR szHttpProxy[MAX_URL_STRING+1];
  529. TCHAR szHttpPort[INTERNET_MAX_PORT_LENGTH+1];
  530. GetDlgItemText(hDlg, IDC_PROXYHTTP, szHttpProxy, MAX_URL_STRING);
  531. GetDlgItemText(hDlg, IDC_PORTHTTP, szHttpPort, INTERNET_MAX_PORT_LENGTH);
  532. //
  533. // ParseProxyInfo will only update the PORT field if port info is
  534. // currently stored in the string. So clear out the PORT fields
  535. // ahead of time and let ParseProxyInfo fill them in as needed.
  536. //
  537. SetDlgItemText( hDlg, IDC_PORTSECURE, gszSecurePort );
  538. SetDlgItemText( hDlg, IDC_PORTFTP, gszFtpPort );
  539. SetDlgItemText( hDlg, IDC_PORTGOPHER, gszGopherPort );
  540. // 09/10/98 The behaviour of IE has changed. IE's proxy property
  541. // sheet will blank all fields.
  542. SetDlgItemText( hDlg, IDC_PROXYSECURE, gszSecureProxy );
  543. SetDlgItemText( hDlg, IDC_PROXYFTP, gszFtpProxy );
  544. SetDlgItemText( hDlg, IDC_PROXYGOPHER, gszGopherProxy );
  545. ParseProxyInfo(hDlg,gpUserInfo->szProxyServer);
  546. SetDlgItemText( hDlg, IDC_PROXYHTTP, szHttpProxy );
  547. SetDlgItemText( hDlg, IDC_PORTHTTP, szHttpPort );
  548. //
  549. // ParseProxyInfo may also check the PROXYSAME, so disable it here
  550. // for good measure.
  551. //
  552. CheckDlgButton( hDlg, IDC_PROXYSAME, FALSE );
  553. }
  554. }
  555. }
  556. //+----------------------------------------------------------------------------
  557. //
  558. // Function: ReplicatePROXYHTTP
  559. //
  560. // Synopsis: copies the value in the IDC_PROXYHTTP edit box to the all other
  561. // proxy name fields except for IDC_SOCKS
  562. //
  563. // Arguments: hDlg -- handle to dialog window which owns the controls
  564. // bSaveOrig -- save original info
  565. //
  566. // Returns: none
  567. //
  568. // History: 7/10/97 jmazner created for Olympus #9365
  569. //
  570. //-----------------------------------------------------------------------------
  571. void ReplicatePROXYHTTP( HWND hDlg, BOOL bSaveOrig)
  572. {
  573. TCHAR szHttpProxy[MAX_URL_STRING];
  574. GetDlgItemText(hDlg, IDC_PROXYHTTP, szHttpProxy, MAX_URL_STRING);
  575. if (bSaveOrig)
  576. {
  577. GetDlgItemText(hDlg, IDC_PROXYSECURE, gszSecureProxy, MAX_URL_STRING);
  578. GetDlgItemText(hDlg, IDC_PROXYFTP, gszFtpProxy, MAX_URL_STRING);
  579. GetDlgItemText(hDlg, IDC_PROXYGOPHER, gszGopherProxy, MAX_URL_STRING);
  580. }
  581. SetDlgItemText( hDlg, IDC_PROXYSECURE, szHttpProxy );
  582. SetDlgItemText( hDlg, IDC_PROXYFTP, szHttpProxy );
  583. SetDlgItemText( hDlg, IDC_PROXYGOPHER, szHttpProxy );
  584. SetDlgItemText( hDlg, IDC_PROXYSOCKS, TEXT("\0") );
  585. }
  586. //+----------------------------------------------------------------------------
  587. //
  588. // Function: ReplicatePORTHTTP
  589. //
  590. // Synopsis: copies the value in the IDC_PORTHTTP edit box to the all other
  591. // proxy port fields except for IDC_SOCKS
  592. //
  593. // Arguments: hDlg -- handle to dialog window which owns the controls
  594. // bSaveOrig -- save original info
  595. //
  596. // Returns: none
  597. //
  598. // History: 7/10/97 jmazner created for Olympus #9365
  599. //
  600. //-----------------------------------------------------------------------------
  601. void ReplicatePORTHTTP( HWND hDlg, BOOL bSaveOrig)
  602. {
  603. TCHAR szHttpPort[INTERNET_MAX_PORT_LENGTH+1];
  604. GetDlgItemText(hDlg, IDC_PORTHTTP, szHttpPort, INTERNET_MAX_PORT_LENGTH);
  605. if (bSaveOrig)
  606. {
  607. GetDlgItemText(hDlg, IDC_PORTSECURE, gszSecurePort, MAX_URL_STRING);
  608. GetDlgItemText(hDlg, IDC_PORTFTP, gszFtpPort, MAX_URL_STRING);
  609. GetDlgItemText(hDlg, IDC_PORTGOPHER, gszGopherPort, MAX_URL_STRING);
  610. }
  611. SetDlgItemText( hDlg, IDC_PORTSECURE, szHttpPort );
  612. SetDlgItemText( hDlg, IDC_PORTFTP, szHttpPort );
  613. SetDlgItemText( hDlg, IDC_PORTGOPHER, szHttpPort );
  614. SetDlgItemText( hDlg, IDC_PORTSOCKS, TEXT("\0") );
  615. }
  616. /*******************************************************************
  617. NAME: ProxyExceptionsInitProc
  618. SYNOPSIS: Called when Proxy Exceptions page is displayed
  619. ENTRY: hDlg - dialog window
  620. fFirstInit - TRUE if this is the first time the dialog
  621. is initialized, FALSE if this InitProc has been called
  622. before (e.g. went past this page and backed up)
  623. ********************************************************************/
  624. BOOL CALLBACK ProxyExceptionsInitProc(HWND hDlg,BOOL fFirstInit)
  625. {
  626. if (fFirstInit)
  627. {
  628. SendDlgItemMessage(hDlg,IDC_BYPASSPROXY,EM_LIMITTEXT,
  629. sizeof(gpUserInfo->szProxyOverride) - sizeof(cszLocalString),0L);
  630. BOOL fBypassLocal = RemoveLocalFromExceptionList(gpUserInfo->szProxyOverride);
  631. SetDlgItemText(hDlg,IDC_BYPASSPROXY,gpUserInfo->szProxyOverride);
  632. CheckDlgButton(hDlg,IDC_BYPASSLOCAL,fBypassLocal);
  633. }
  634. // if we've travelled through external apprentice pages,
  635. // it's easy for our current page pointer to get munged,
  636. // so reset it here for sanity's sake.
  637. gpWizardState->uCurrentPage = ORD_PAGE_PROXYEXCEPTIONS;
  638. return TRUE;
  639. }
  640. /*******************************************************************
  641. NAME: ProxyExceptionsOKProc
  642. SYNOPSIS: Called when Next or Back btns pressed from Proxy
  643. Exceptions page
  644. ENTRY: hDlg - dialog window
  645. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  646. puNextPage - if 'Next' was pressed,
  647. proc can fill this in with next page to go to. This
  648. parameter is ingored if 'Back' was pressed.
  649. pfKeepHistory - page will not be kept in history if
  650. proc fills this in with FALSE.
  651. EXIT: returns TRUE to allow page to be turned, FALSE
  652. to keep the same page.
  653. ********************************************************************/
  654. BOOL CALLBACK ProxyExceptionsOKProc(HWND hDlg,BOOL fForward,UINT * puNextPage,
  655. BOOL * pfKeepHistory)
  656. {
  657. ASSERT(puNextPage);
  658. // get proxy server override from UI
  659. GetDlgItemText(hDlg,IDC_BYPASSPROXY,gpUserInfo->szProxyOverride,
  660. ARRAYSIZE(gpUserInfo->szProxyOverride));
  661. if (IsDlgButtonChecked(hDlg, IDC_BYPASSLOCAL))
  662. {
  663. //
  664. // Add ; on the end if its NOT the first entry.
  665. //
  666. if ( gpUserInfo->szProxyOverride[0] != '\0' )
  667. {
  668. lstrcat(gpUserInfo->szProxyOverride, TEXT(";"));
  669. }
  670. //
  671. // Now Add <local> to end of string.
  672. //
  673. lstrcat(gpUserInfo->szProxyOverride, cszLocalString);
  674. }
  675. if (fForward)
  676. {
  677. if(( gpWizardState->dwRunFlags & RSW_APPRENTICE ) && !g_fIsICW)
  678. {
  679. // we're about to jump back to the external wizard, and we don't want
  680. // this page to show up in our history list
  681. *pfKeepHistory = FALSE;
  682. *puNextPage = g_uExternUINext;
  683. //Notify the main Wizard that this was the last page
  684. ASSERT( g_pExternalIICWExtension )
  685. if (g_fIsExternalWizard97)
  686. g_pExternalIICWExtension->SetFirstLastPage(0, IDD_PAGE_PROXYEXCEPTIONS97);
  687. else
  688. g_pExternalIICWExtension->SetFirstLastPage(0, IDD_PAGE_PROXYEXCEPTIONS);
  689. g_fConnectionInfoValid = TRUE;
  690. }
  691. else if( LoadAcctMgrUI(GetParent(hDlg),
  692. g_fIsWizard97 ? IDD_PAGE_PROXYEXCEPTIONS97 : IDD_PAGE_PROXYEXCEPTIONS,
  693. g_fIsWizard97 ? IDD_PAGE_CONNECTEDOK97FIRSTLAST : IDD_PAGE_CONNECTEDOK,
  694. g_fIsWizard97 ? WIZ_USE_WIZARD97 : 0) )
  695. {
  696. if( DialogIDAlreadyInUse( g_uAcctMgrUIFirst) )
  697. {
  698. // we're about to jump into the external apprentice, and we don't want
  699. // this page to show up in our history list
  700. *pfKeepHistory = FALSE;
  701. *puNextPage = g_uAcctMgrUIFirst;
  702. }
  703. else
  704. {
  705. DEBUGMSG("hmm, the first acctMgr dlg id is supposedly %d, but it's not marked as in use!",
  706. g_uAcctMgrUIFirst);
  707. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  708. }
  709. }
  710. else
  711. {
  712. DEBUGMSG("LoadAcctMgrUI returned false, guess we'd better skip over it!");
  713. *puNextPage = (g_fIsICW ? g_uExternUINext : ORD_PAGE_CONNECTEDOK);
  714. }
  715. }
  716. return TRUE;
  717. }
  718. BOOL DoNewProfileDlg(HWND hDlg)
  719. {
  720. // fill out structure to pass to dialog
  721. NEWPROFILEDLGINFO NewProfileDlgInfo;
  722. NewProfileDlgInfo.hwndCombo = GetDlgItem(hDlg,IDC_PROFILE_LIST);
  723. // create dialog to prompt for profile name
  724. BOOL fRet=(BOOL)DialogBoxParam(ghInstance,MAKEINTRESOURCE(IDD_NEWPROFILENAME),hDlg,
  725. NewProfileDlgProc,(LPARAM) &NewProfileDlgInfo);
  726. // if profile name chosen, add it to combo box
  727. if (fRet) {
  728. int iSel=ComboBox_AddString(NewProfileDlgInfo.hwndCombo,
  729. NewProfileDlgInfo.szNewProfileName);
  730. ASSERT(iSel >= 0);
  731. ComboBox_SetCurSel(NewProfileDlgInfo.hwndCombo,iSel);
  732. }
  733. return fRet;
  734. }
  735. /*******************************************************************
  736. NAME: NewProfileDlgProc
  737. SYNOPSIS: Dialog proc for choosing name for new profile
  738. ********************************************************************/
  739. INT_PTR CALLBACK NewProfileDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  740. LPARAM lParam)
  741. {
  742. switch (uMsg) {
  743. case WM_INITDIALOG:
  744. // lParam contains pointer to NEWPROFILEDLGINFO struct, set it
  745. // in window data
  746. ASSERT(lParam);
  747. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  748. return NewProfileDlgInit(hDlg,(NEWPROFILEDLGINFO *) lParam);
  749. break;
  750. case WM_COMMAND:
  751. switch (LOWORD(wParam)) {
  752. case IDOK:
  753. {
  754. NEWPROFILEDLGINFO * pNewProfileDlgInfo =
  755. (NEWPROFILEDLGINFO *) GetWindowLongPtr(hDlg,DWLP_USER);
  756. ASSERT(pNewProfileDlgInfo);
  757. BOOL fRet=NewProfileDlgOK(hDlg,pNewProfileDlgInfo);
  758. if (fRet) {
  759. EndDialog(hDlg,TRUE);
  760. }
  761. }
  762. break;
  763. case IDCANCEL:
  764. EndDialog(hDlg,FALSE);
  765. break;
  766. }
  767. break;
  768. }
  769. return FALSE;
  770. }
  771. #define MAX_DEFAULT_PROFILE_INDEX 50
  772. BOOL NewProfileDlgInit(HWND hDlg,NEWPROFILEDLGINFO * pNewProfileDlgInfo)
  773. {
  774. BOOL fHaveDefaultName = TRUE;
  775. ASSERT(pNewProfileDlgInfo);
  776. // limit edit field
  777. Edit_LimitText(GetDlgItem(hDlg,IDC_PROFILENAME),cchProfileNameMax);
  778. TCHAR szDefaultName[SMALL_BUF_LEN+1];
  779. LoadSz(IDS_PROFILENAME,szDefaultName,sizeof(szDefaultName));
  780. // see if the default name already exists in the combo box of profiles
  781. if (ComboBox_FindStringExact(pNewProfileDlgInfo->hwndCombo,0,szDefaultName)
  782. >= 0) {
  783. fHaveDefaultName = FALSE;
  784. // yep, it exists, try making a default name that doesn't exist
  785. int iIndex = 2; // start with "<default name> #2"
  786. TCHAR szBuf[SMALL_BUF_LEN+1];
  787. LoadSz(IDS_PROFILENAME1,szBuf,sizeof(szBuf));
  788. while (iIndex < MAX_DEFAULT_PROFILE_INDEX) {
  789. // build a name a la "<default name> #<#>"
  790. wsprintf(szDefaultName,szBuf,iIndex);
  791. // is it in combo box already?
  792. if (ComboBox_FindStringExact(pNewProfileDlgInfo->hwndCombo,0,szDefaultName)
  793. < 0) {
  794. fHaveDefaultName = TRUE;
  795. break;
  796. }
  797. iIndex ++;
  798. }
  799. }
  800. if (fHaveDefaultName) {
  801. SetDlgItemText(hDlg,IDC_PROFILENAME,szDefaultName);
  802. Edit_SetSel(GetDlgItem(hDlg,IDC_PROFILENAME),0,-1);
  803. }
  804. SetFocus(GetDlgItem(hDlg,IDC_PROFILENAME));
  805. return TRUE;
  806. }
  807. BOOL NewProfileDlgOK(HWND hDlg,NEWPROFILEDLGINFO * pNewProfileDlgInfo)
  808. {
  809. ASSERT(pNewProfileDlgInfo);
  810. // get new profile name out of edit control
  811. GetDlgItemText(hDlg,IDC_PROFILENAME,pNewProfileDlgInfo->szNewProfileName,
  812. ARRAYSIZE(pNewProfileDlgInfo->szNewProfileName));
  813. // name needs to be non-empty
  814. if (!lstrlen(pNewProfileDlgInfo->szNewProfileName)) {
  815. MsgBox(hDlg,IDS_NEED_PROFILENAME,MB_ICONINFORMATION,MB_OK);
  816. SetFocus(GetDlgItem(hDlg,IDC_PROFILENAME));
  817. return FALSE;
  818. }
  819. // name needs to be unique
  820. if (ComboBox_FindStringExact(pNewProfileDlgInfo->hwndCombo,
  821. 0,pNewProfileDlgInfo->szNewProfileName) >= 0) {
  822. MsgBox(hDlg,IDS_DUPLICATE_PROFILENAME,MB_ICONINFORMATION,MB_OK);
  823. SetFocus(GetDlgItem(hDlg,IDC_PROFILENAME));
  824. Edit_SetSel(GetDlgItem(hDlg,IDC_PROFILENAME),0,-1);
  825. return FALSE;
  826. }
  827. return TRUE;
  828. }
  829. /*******************************************************************
  830. NAME: NewProfileDlgProc
  831. Maps a scheme name/length to a scheme name type
  832. Arguments:
  833. lpszSchemeName - pointer to name of scheme to map
  834. dwSchemeNameLength - length of scheme (if -1, lpszSchemeName is ASCIZ)
  835. Return Value:
  836. INTERNET_SCHEME
  837. ********************************************************************/
  838. INTERNET_SCHEME MapUrlSchemeName(LPTSTR lpszSchemeName, DWORD dwSchemeNameLength)
  839. {
  840. if (dwSchemeNameLength == (DWORD)-1)
  841. {
  842. dwSchemeNameLength = (DWORD)lstrlen(lpszSchemeName);
  843. }
  844. int i = 0;
  845. do
  846. {
  847. if (UrlSchemeList[i].SchemeLength == dwSchemeNameLength)
  848. {
  849. TCHAR chBackup = lpszSchemeName[dwSchemeNameLength];
  850. lpszSchemeName[dwSchemeNameLength] = '\0';
  851. if(lstrcmpi(UrlSchemeList[i].SchemeName,lpszSchemeName) == 0)
  852. {
  853. lpszSchemeName[dwSchemeNameLength] = chBackup;
  854. return UrlSchemeList[i].SchemeType;
  855. }
  856. lpszSchemeName[dwSchemeNameLength] = chBackup;
  857. }
  858. i++;
  859. } while (UrlSchemeList[i].SchemeLength);
  860. return INTERNET_SCHEME_UNKNOWN;
  861. }
  862. /*******************************************************************
  863. NAME: MapUrlSchemeTypeToCtlId
  864. Routine Description:
  865. Maps a scheme to a dlg child control id.
  866. Arguments:
  867. Scheme - Scheme to Map
  868. fIdForPortCtl - If TRUE, means we really want the ID for a the PORT control
  869. not the ADDRESS control.
  870. Return Value:
  871. DWORD
  872. ********************************************************************/
  873. DWORD MapUrlSchemeTypeToCtlId(INTERNET_SCHEME SchemeType, BOOL fIdForPortCtl)
  874. {
  875. int i = 0;
  876. while (UrlSchemeList[i].SchemeLength)
  877. {
  878. if (SchemeType == UrlSchemeList[i].SchemeType)
  879. {
  880. return (fIdForPortCtl ? UrlSchemeList[i].dwPortControlId :
  881. UrlSchemeList[i].dwControlId );
  882. }
  883. i++;
  884. }
  885. return 0;
  886. }
  887. /*******************************************************************
  888. NAME: MapCtlIdUrlSchemeName
  889. Routine Description:
  890. Maps a dlg child control id to String represnting
  891. the name of the scheme.
  892. Arguments:
  893. dwEditCtlId - Edit Control to Map Out.
  894. lpszSchemeOut - Scheme to Map Out.
  895. WARNING: ASSUMED to be size of largest scheme type.
  896. Return Value:
  897. BOOL
  898. Success - TRUE
  899. Failure - FALSE
  900. ********************************************************************/
  901. BOOL MapCtlIdUrlSchemeName(DWORD dwEditCtlId, LPTSTR lpszSchemeOut)
  902. {
  903. ASSERT(lpszSchemeOut);
  904. int i = 0;
  905. while (UrlSchemeList[i].SchemeLength)
  906. {
  907. if (dwEditCtlId == UrlSchemeList[i].dwControlId )
  908. {
  909. lstrcpy(lpszSchemeOut, UrlSchemeList[i].SchemeName);
  910. return TRUE;
  911. }
  912. i++;
  913. }
  914. return FALSE;
  915. }
  916. /*******************************************************************
  917. NAME: MapAddrCtlIdToPortCtlId
  918. Routine Description:
  919. Maps a dlg child control id for addresses to
  920. a dlg control id for ports.
  921. Arguments:
  922. dwEditCtlId - Edit Control to Map Out.
  923. Return Value:
  924. DWORD
  925. Success - Correctly mapped ID.
  926. Failure - 0.
  927. ********************************************************************/
  928. DWORD MapAddrCtlIdToPortCtlId(DWORD dwEditCtlId)
  929. {
  930. int i = 0;
  931. while (UrlSchemeList[i].SchemeLength)
  932. {
  933. if (dwEditCtlId == UrlSchemeList[i].dwControlId )
  934. {
  935. return UrlSchemeList[i].dwPortControlId ;
  936. }
  937. i++;
  938. }
  939. return FALSE;
  940. }
  941. /*******************************************************************
  942. NAME: ParseProxyInfo
  943. Parses proxy server string and sets dialog fields appropriately
  944. Arguments:
  945. hDlg - Handle to dialog
  946. lpszProxy - Proxy server string
  947. lpszSchemeName - pointer to name of scheme to map
  948. dwSchemeNameLength - length of scheme (if -1, lpszSchemeName is ASCIZ)
  949. Return Value:
  950. INTERNET_SCHEME
  951. ********************************************************************/
  952. BOOL ParseProxyInfo(HWND hDlg, LPTSTR lpszProxy)
  953. {
  954. DWORD error = FALSE;
  955. DWORD entryLength = 0;
  956. LPTSTR protocolName = lpszProxy;
  957. DWORD protocolLength = 0;
  958. LPTSTR schemeName = NULL;
  959. DWORD schemeLength = 0;
  960. LPTSTR serverName = NULL;
  961. DWORD serverLength = 0;
  962. PARSER_STATE state = STATE_PROTOCOL;
  963. DWORD nSlashes = 0;
  964. UINT port = 0;
  965. BOOL done = FALSE;
  966. LPTSTR lpszList = lpszProxy;
  967. do
  968. {
  969. TCHAR ch = *lpszList++;
  970. if ((1 == nSlashes) && (ch != '/'))
  971. {
  972. state = STATE_ERROR;
  973. break; // do ... while
  974. }
  975. switch (ch)
  976. {
  977. case '=':
  978. if ((state == STATE_PROTOCOL) && (entryLength != 0))
  979. {
  980. protocolLength = entryLength;
  981. entryLength = 0;
  982. state = STATE_SCHEME;
  983. schemeName = lpszList;
  984. }
  985. else
  986. {
  987. //
  988. // '=' can't legally appear anywhere else
  989. //
  990. state = STATE_ERROR;
  991. }
  992. break;
  993. case ':':
  994. switch (state)
  995. {
  996. case STATE_PROTOCOL:
  997. if (*lpszList == '/')
  998. {
  999. schemeName = protocolName;
  1000. protocolName = NULL;
  1001. schemeLength = entryLength;
  1002. protocolLength = 0;
  1003. state = STATE_SCHEME;
  1004. }
  1005. else if (*lpszList != '\0')
  1006. {
  1007. serverName = protocolName;
  1008. protocolName = NULL;
  1009. serverLength = entryLength;
  1010. protocolLength = 0;
  1011. state = STATE_PORT;
  1012. }
  1013. else
  1014. {
  1015. state = STATE_ERROR;
  1016. }
  1017. entryLength = 0;
  1018. break;
  1019. case STATE_SCHEME:
  1020. if (*lpszList == '/')
  1021. {
  1022. schemeLength = entryLength;
  1023. }
  1024. else if (*lpszList != '\0')
  1025. {
  1026. serverName = schemeName;
  1027. serverLength = entryLength;
  1028. state = STATE_PORT;
  1029. }
  1030. else
  1031. {
  1032. state = STATE_ERROR;
  1033. }
  1034. entryLength = 0;
  1035. break;
  1036. case STATE_SERVER:
  1037. serverLength = entryLength;
  1038. state = STATE_PORT;
  1039. entryLength = 0;
  1040. break;
  1041. default:
  1042. state = STATE_ERROR;
  1043. break;
  1044. }
  1045. break;
  1046. case '/':
  1047. if ((state == STATE_SCHEME) && (nSlashes < 2) && (entryLength == 0))
  1048. {
  1049. if (++nSlashes == 2)
  1050. {
  1051. state = STATE_SERVER;
  1052. serverName = lpszList;
  1053. }
  1054. }
  1055. else
  1056. {
  1057. state = STATE_ERROR;
  1058. }
  1059. break;
  1060. case '\v': // vertical tab, 0x0b
  1061. case '\f': // form feed, 0x0c
  1062. if (!((state == STATE_PROTOCOL) && (entryLength == 0)))
  1063. {
  1064. //
  1065. // can't have embedded whitespace
  1066. //
  1067. state = STATE_ERROR;
  1068. }
  1069. break;
  1070. default:
  1071. if (state != STATE_PORT)
  1072. {
  1073. ++entryLength;
  1074. }
  1075. else if (isdigit(ch))
  1076. {
  1077. // calculate in DWORD to prevent overflow
  1078. DWORD dwPort = port * 10 + (ch - '0');
  1079. if (dwPort <= 65535)
  1080. port = (UINT)dwPort;
  1081. else
  1082. state = STATE_ERROR;
  1083. }
  1084. else
  1085. {
  1086. //
  1087. // STATE_PORT && non-digit character - error
  1088. //
  1089. state = STATE_ERROR;
  1090. }
  1091. break;
  1092. case '\0':
  1093. done = TRUE;
  1094. //
  1095. // fall through
  1096. //
  1097. case ' ':
  1098. case '\t':
  1099. case '\n':
  1100. case '\r':
  1101. case ';':
  1102. case ',':
  1103. if (serverLength == 0)
  1104. {
  1105. serverLength = entryLength;
  1106. }
  1107. if (serverLength != 0)
  1108. {
  1109. if (serverName == NULL)
  1110. {
  1111. serverName = (schemeName != NULL)
  1112. ? schemeName : protocolName;
  1113. }
  1114. ASSERT(serverName != NULL);
  1115. INTERNET_SCHEME protocol;
  1116. if (protocolLength != 0)
  1117. {
  1118. protocol = MapUrlSchemeName(protocolName, protocolLength);
  1119. }
  1120. else
  1121. {
  1122. protocol = INTERNET_SCHEME_DEFAULT;
  1123. }
  1124. INTERNET_SCHEME scheme;
  1125. if (schemeLength != 0)
  1126. {
  1127. scheme = MapUrlSchemeName(schemeName, schemeLength);
  1128. }
  1129. else
  1130. {
  1131. scheme = INTERNET_SCHEME_DEFAULT;
  1132. }
  1133. //
  1134. // add an entry if this is a protocol we handle and we don't
  1135. // already have an entry for it
  1136. //
  1137. if ((protocol != INTERNET_SCHEME_UNKNOWN)
  1138. && (scheme != INTERNET_SCHEME_UNKNOWN))
  1139. {
  1140. DWORD dwCtlId = 0;
  1141. DWORD dwPortCtlId = 0;
  1142. TCHAR chBackup;
  1143. error = ERROR_SUCCESS;
  1144. //
  1145. // we can only currently handle CERN proxies (unsecure or
  1146. // secure) so kick out anything that wants to go via a different
  1147. // proxy scheme
  1148. //
  1149. if (protocol == INTERNET_SCHEME_DEFAULT)
  1150. {
  1151. CheckDlgButton( hDlg, IDC_PROXYSAME, TRUE );
  1152. dwCtlId = IDC_PROXYHTTP;
  1153. dwPortCtlId = IDC_PORTHTTP;
  1154. }
  1155. else
  1156. {
  1157. dwCtlId = MapUrlSchemeTypeToCtlId(protocol,FALSE);
  1158. dwPortCtlId = MapUrlSchemeTypeToCtlId(protocol,TRUE);
  1159. }
  1160. //
  1161. // Set the Field Entry.
  1162. //
  1163. LPTSTR lpszProxyNameText;
  1164. if (scheme != INTERNET_SCHEME_DEFAULT)
  1165. {
  1166. ASSERT(schemeLength != 0);
  1167. lpszProxyNameText = schemeName;
  1168. }
  1169. else
  1170. lpszProxyNameText = serverName;
  1171. chBackup = serverName[serverLength];
  1172. serverName[serverLength] = '\0';
  1173. SetDlgItemText( hDlg, dwCtlId, lpszProxyNameText );
  1174. if ( port )
  1175. SetDlgItemInt( hDlg, dwPortCtlId, port, FALSE );
  1176. serverName[serverLength] = chBackup;
  1177. }
  1178. else
  1179. {
  1180. //
  1181. // bad/unrecognised protocol or scheme. Treat it as error
  1182. // for now
  1183. //
  1184. error = !ERROR_SUCCESS;
  1185. }
  1186. }
  1187. entryLength = 0;
  1188. protocolName = lpszList;
  1189. protocolLength = 0;
  1190. schemeName = NULL;
  1191. schemeLength = 0;
  1192. serverName = NULL;
  1193. serverLength = 0;
  1194. nSlashes = 0;
  1195. port = 0;
  1196. if (error == ERROR_SUCCESS)
  1197. {
  1198. state = STATE_PROTOCOL;
  1199. }
  1200. else
  1201. {
  1202. state = STATE_ERROR;
  1203. }
  1204. break;
  1205. }
  1206. if (state == STATE_ERROR)
  1207. {
  1208. break;
  1209. }
  1210. } while (!done);
  1211. if (state == STATE_ERROR)
  1212. {
  1213. error = ERROR_INVALID_PARAMETER;
  1214. }
  1215. if ( error == ERROR_SUCCESS )
  1216. error = TRUE;
  1217. else
  1218. error = FALSE;
  1219. return error;
  1220. }
  1221. /*******************************************************************
  1222. NAME: ParseEditCtlForPort
  1223. Routine Description:
  1224. Parses a Port Number off then end of a Proxy Server URL that is
  1225. located either in the Proxy Name Edit Box, or passed in as
  1226. a string pointer.
  1227. Arguments:
  1228. lpszProxyName - (OPTIONAL) string pointer with Proxy Name to parse, and
  1229. set into the Proxy Name edit ctl field.
  1230. hDlg - HWIN of the dialog to play with.
  1231. dwProxyNameCtlId - Res Ctl Id to play with.
  1232. dwProxyPortCtlId - Res Ctl Id of Port Number Edit Box.
  1233. Return Value:
  1234. BOOL
  1235. Success TRUE -
  1236. Failure FALSE
  1237. ********************************************************************/
  1238. BOOL ParseEditCtlForPort(
  1239. IN OUT LPTSTR lpszProxyName,
  1240. IN HWND hDlg,
  1241. IN DWORD dwProxyNameCtlId,
  1242. IN DWORD dwProxyPortCtlId
  1243. )
  1244. {
  1245. TCHAR szProxyUrl[MAX_URL_STRING+1];
  1246. LPTSTR lpszPort;
  1247. LPTSTR lpszProxyUrl;
  1248. ASSERT(IsWindow(hDlg));
  1249. if ( dwProxyPortCtlId == 0 )
  1250. {
  1251. dwProxyPortCtlId = MapAddrCtlIdToPortCtlId(dwProxyNameCtlId);
  1252. ASSERT(dwProxyPortCtlId);
  1253. }
  1254. //
  1255. // Get the Proxy String from the Edit Control
  1256. // (OR) from the Registry [passed in]
  1257. //
  1258. if ( lpszProxyName )
  1259. lpszProxyUrl = lpszProxyName;
  1260. else
  1261. {
  1262. //
  1263. // Need to Grab it out of the edit control.
  1264. //
  1265. GetDlgItemText(hDlg,
  1266. dwProxyNameCtlId,
  1267. szProxyUrl,
  1268. ARRAYSIZE(szProxyUrl));
  1269. lpszProxyUrl = szProxyUrl;
  1270. }
  1271. //
  1272. // Now find the port.
  1273. //
  1274. lpszPort = lpszProxyUrl;
  1275. GET_TERMINATOR(lpszPort);
  1276. lpszPort--;
  1277. //
  1278. // Walk backwards from the end of url looking
  1279. // for a port number sitting on the end like this
  1280. // http://proxy:1234
  1281. //
  1282. while ( (lpszPort > lpszProxyUrl) &&
  1283. (*lpszPort != ':') &&
  1284. (isdigit(*lpszPort)) )
  1285. {
  1286. lpszPort--;
  1287. }
  1288. //
  1289. // If we found a match for our rules
  1290. // then set the port, otherwise
  1291. // we assume the user knows what he's
  1292. // doing.
  1293. //
  1294. if ( *lpszPort == ':' && isdigit(*(lpszPort+1)) )
  1295. {
  1296. *lpszPort = '\0';
  1297. SetDlgItemText(hDlg, dwProxyPortCtlId, (lpszPort+1));
  1298. }
  1299. SetDlgItemText(hDlg, dwProxyNameCtlId, lpszProxyUrl);
  1300. return TRUE;
  1301. }
  1302. /*******************************************************************
  1303. NAME: FormatOutProxyEditCtl
  1304. Routine Description:
  1305. Combines Proxy URL components into a string that can be saved
  1306. in the registry. Can be called multiple times to build
  1307. a list of proxy servers, or once to special case a "default"
  1308. proxy.
  1309. Arguments:
  1310. hDlg - HWIN of the dialog to play with.
  1311. dwProxyNameCtlId - Res Ctl Id to play with.
  1312. dwProxyPortCtlId - Res Ctl Id of Port Number Edit Box.
  1313. lpszOutputStr - The start of the output string to send
  1314. the product of this function.
  1315. lpdwOutputStrSize - The amount of used space in lpszOutputStr
  1316. that is already used. New output should
  1317. start from (lpszOutputStr + *lpdwOutputStrSize)
  1318. fDefaultProxy - Default Proxy, don't add scheme= in front of the proxy
  1319. just use plop one proxy into the registry.
  1320. Return Value:
  1321. DWORD
  1322. Success ERROR_SUCCESS
  1323. Failure ERROR message
  1324. ********************************************************************/
  1325. DWORD FormatOutProxyEditCtl(
  1326. IN HWND hDlg,
  1327. IN DWORD dwProxyNameCtlId,
  1328. IN DWORD dwProxyPortCtlId,
  1329. OUT LPTSTR lpszOutputStr,
  1330. IN OUT LPDWORD lpdwOutputStrSize,
  1331. IN DWORD dwOutputStrLength,
  1332. IN BOOL fDefaultProxy
  1333. )
  1334. {
  1335. LPTSTR lpszOutput;
  1336. LPTSTR lpszEndOfOutputStr;
  1337. ASSERT(IsWindow(hDlg));
  1338. ASSERT(lpdwOutputStrSize);
  1339. lpszOutput = lpszOutputStr + *lpdwOutputStrSize;
  1340. lpszEndOfOutputStr = lpszOutputStr + dwOutputStrLength;
  1341. ASSERT( lpszEndOfOutputStr > lpszOutput );
  1342. if ( lpszEndOfOutputStr <= lpszOutput )
  1343. return ERROR_NOT_ENOUGH_MEMORY; // bail out, ran out of space
  1344. //
  1345. // Plop ';' if we're not the first in this string buffer.
  1346. //
  1347. if (*lpdwOutputStrSize != 0 )
  1348. {
  1349. *lpszOutput = ';';
  1350. lpszOutput++;
  1351. if ( lpszEndOfOutputStr <= lpszOutput )
  1352. return ERROR_NOT_ENOUGH_MEMORY; // bail out, ran out of space
  1353. }
  1354. //
  1355. // Put the schemetype= into the string
  1356. // ex: http=
  1357. //
  1358. if ( ! fDefaultProxy )
  1359. {
  1360. if ( lpszEndOfOutputStr <= (MAX_SCHEME_NAME_LENGTH + lpszOutput + 1) )
  1361. return ERROR_NOT_ENOUGH_MEMORY; // bail out, ran out of space
  1362. if (!MapCtlIdUrlSchemeName(dwProxyNameCtlId,lpszOutput))
  1363. return ERROR_NOT_ENOUGH_MEMORY;
  1364. lpszOutput += lstrlen(lpszOutput);
  1365. *lpszOutput = '=';
  1366. lpszOutput++;
  1367. }
  1368. //
  1369. // Need to Grab ProxyUrl out of the edit control.
  1370. //
  1371. GetDlgItemText(hDlg, dwProxyNameCtlId, lpszOutput, (int)(lpszEndOfOutputStr - lpszOutput) / sizeof(TCHAR));
  1372. if ( '\0' == *lpszOutput )
  1373. {
  1374. // Cancel out anything we may have added before returning
  1375. *(lpszOutputStr + *lpdwOutputStrSize) = '\0';
  1376. return ERROR_SERVER_NAME;
  1377. }
  1378. //
  1379. // Now seperate out the port so we can save them seperately.
  1380. // But go past the Proxy Url while we're at it.
  1381. // ex: http=http://netscape-proxy
  1382. //
  1383. if (!ParseEditCtlForPort(lpszOutput, hDlg, dwProxyNameCtlId, dwProxyPortCtlId))
  1384. return ERROR_PORT_NUM;
  1385. lpszOutput += lstrlen(lpszOutput);
  1386. //
  1387. // Now, add in a ':" for the port number, if we don't
  1388. // have a port we'll remove it.
  1389. //
  1390. *lpszOutput = ':';
  1391. lpszOutput++;
  1392. if ( lpszEndOfOutputStr <= lpszOutput )
  1393. return ERROR_NOT_ENOUGH_MEMORY; // bail out, ran out of space
  1394. //
  1395. // Grab Proxy Port if its around.
  1396. // Back out the ':' if its not.
  1397. //
  1398. GetDlgItemText(hDlg, dwProxyPortCtlId,lpszOutput, (int)(lpszEndOfOutputStr - lpszOutput) / sizeof(TCHAR));
  1399. // jmazner 11/9/96 Normandy #6937
  1400. // Don't accept non-numerical port numbers, since the Internet control panel
  1401. // will not display them.
  1402. int i;
  1403. for( i=0; lpszOutput[i] != NULL; i++ )
  1404. {
  1405. if( !isdigit(lpszOutput[i]) )
  1406. {
  1407. //DisplayFieldErrorMsg(hDlg,dwProxyPortCtlId,IDS_INVALID_PORTNUM);
  1408. return ERROR_PORT_NUM;
  1409. }
  1410. }
  1411. if ( '\0' == *lpszOutput )
  1412. {
  1413. lpszOutput--;
  1414. ASSERT(*lpszOutput == ':');
  1415. *lpszOutput = '\0';
  1416. }
  1417. lpszOutput += lstrlen(lpszOutput);
  1418. //
  1419. // Now we're done return our final sizes.
  1420. //
  1421. *lpdwOutputStrSize = (DWORD)(lpszOutput - lpszOutputStr);
  1422. return ERROR_SUCCESS;
  1423. }
  1424. /*******************************************************************
  1425. NAME: RemoveLocalFromExceptionList
  1426. Routine Description:
  1427. Scans a delimited list of entries, and removed "<local>
  1428. if found. If <local> is found we return TRUE.
  1429. Arguments:
  1430. lpszExceptionList - String List of proxy excepion entries.
  1431. Return Value:
  1432. BOOL
  1433. TRUE - If found <local>
  1434. FALSE - If local was not found.
  1435. ********************************************************************/
  1436. BOOL RemoveLocalFromExceptionList(LPTSTR lpszExceptionList)
  1437. {
  1438. LPTSTR lpszLocalInstToRemove;
  1439. BOOL fFoundLocal;
  1440. if ( !lpszExceptionList || ! *lpszExceptionList )
  1441. return FALSE;
  1442. fFoundLocal = FALSE;
  1443. lpszLocalInstToRemove = lpszExceptionList;
  1444. //
  1445. // Loop looking "<local>" entries in the list.
  1446. //
  1447. do {
  1448. lpszLocalInstToRemove = _tcsstr(lpszLocalInstToRemove,cszLocalString);
  1449. if ( lpszLocalInstToRemove )
  1450. {
  1451. fFoundLocal = TRUE;
  1452. //
  1453. // Nuke <local> out of the string. <local>;otherstuff\0
  1454. // Dest is: '<'local>;otherstuff\0
  1455. // ??? (OR) ';'<local> if the ; is the first character.???
  1456. // Src is: >'o'therstuff\0
  1457. // size is: sizeof(';otherstuff\0')
  1458. //
  1459. MoveMemory( lpszLocalInstToRemove,
  1460. (lpszLocalInstToRemove+(sizeof(cszLocalString)-sizeof('\0'))),
  1461. lstrlen(lpszLocalInstToRemove+(sizeof(cszLocalString)-sizeof('\0')))
  1462. + sizeof('\0')
  1463. );
  1464. }
  1465. } while (lpszLocalInstToRemove && *lpszLocalInstToRemove);
  1466. //
  1467. // If we produced a ; on the end, nuke it.
  1468. //
  1469. lpszLocalInstToRemove = lpszExceptionList;
  1470. GET_TERMINATOR(lpszLocalInstToRemove);
  1471. if ( lpszLocalInstToRemove != lpszExceptionList &&
  1472. *(lpszLocalInstToRemove-1) == ';' )
  1473. {
  1474. *(lpszLocalInstToRemove-1) = '\0';
  1475. }
  1476. return fFoundLocal;
  1477. }