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.

2765 lines
90 KiB

  1. ///////////////////////////////////////////////////////////////////////
  2. // Microsoft Windows //
  3. // Copyright(c) Microsoft Corp., 1995 //
  4. ///////////////////////////////////////////////////////////////////////
  5. //
  6. // CONNECTN.C - "Connection" Property Sheet
  7. //
  8. // HISTORY:
  9. //
  10. // 6/22/96 t-gpease moved to this file
  11. //
  12. #include "inetcplp.h"
  13. #include <inetcpl.h>
  14. #include <rasdlg.h>
  15. #include <mluisupp.h>
  16. HINSTANCE hInstRNADll = NULL;
  17. DWORD dwRNARefCount = 0;
  18. BOOL g_fWin95 = TRUE;
  19. BOOL g_fMillennium = FALSE;
  20. BOOL g_fWin2K = FALSE;
  21. static const TCHAR g_szSensPath[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Webcheck");
  22. // clsids used to jit in features
  23. static const CLSID clsidFeatureICW = { // {5A8D6EE0-3E18-11D0-821E-444553540000}
  24. 0x5A8D6EE0, 0x3E18, 0x11D0, {0x82, 0x1E, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
  25. static const CLSID clsidFeatureMobile = { // {3af36230-a269-11d1-b5bf-0000f8051515}
  26. 0x3af36230, 0xa269, 0x11d1, {0xb5, 0xbf, 0x00, 0x00, 0xf8, 0x05, 0x15, 0x15}};
  27. // RNA api function names
  28. static const CHAR szRasEditPhonebookEntryA[] = "RasEditPhonebookEntryA";
  29. static const CHAR szRasEditPhonebookEntryW[] = "RasEditPhonebookEntryW";
  30. static const CHAR szRasEnumEntriesA[] = "RasEnumEntriesA";
  31. static const CHAR szRasEnumEntriesW[] = "RasEnumEntriesW";
  32. static const CHAR szRasDeleteEntryA[] = "RasDeleteEntryA";
  33. static const CHAR szRasDeleteEntryW[] = "RasDeleteEntryW";
  34. static const CHAR szRasGetEntryDialParamsA[] = "RasGetEntryDialParamsA";
  35. static const CHAR szRasGetEntryDialParamsW[] = "RasGetEntryDialParamsW";
  36. static const CHAR szRasSetEntryDialParamsA[] = "RasSetEntryDialParamsA";
  37. static const CHAR szRasSetEntryDialParamsW[] = "RasSetEntryDialParamsW";
  38. static const CHAR szRasCreatePhonebookEntryA[] = "RasCreatePhonebookEntryA";
  39. static const CHAR szRasGetEntryPropertiesW[] = "RasGetEntryPropertiesW";
  40. static const CHAR szRnaActivateEngine[] = "RnaActivateEngine";
  41. static const CHAR szRnaDeactivateEngine[] = "RnaDeactivateEngine";
  42. static const CHAR szRnaDeleteEntry[] = "RnaDeleteConnEntry";
  43. RASEDITPHONEBOOKENTRYA lpRasEditPhonebookEntryA = NULL;
  44. RASEDITPHONEBOOKENTRYW lpRasEditPhonebookEntryW = NULL;
  45. RASENUMENTRIESA lpRasEnumEntriesA = NULL;
  46. RASENUMENTRIESW lpRasEnumEntriesW = NULL;
  47. RASDELETEENTRYA lpRasDeleteEntryA = NULL;
  48. RASDELETEENTRYW lpRasDeleteEntryW = NULL;
  49. RASGETENTRYDIALPARAMSA lpRasGetEntryDialParamsA = NULL;
  50. RASGETENTRYDIALPARAMSW lpRasGetEntryDialParamsW = NULL;
  51. RASSETENTRYDIALPARAMSA lpRasSetEntryDialParamsA = NULL;
  52. RASSETENTRYDIALPARAMSW lpRasSetEntryDialParamsW = NULL;
  53. RASCREATEPHONEBOOKENTRYA lpRasCreatePhonebookEntryA = NULL;
  54. RASGETENTRYPROPERTIESW lpRasGetEntryPropertiesW = NULL;
  55. RNAACTIVATEENGINE lpRnaActivateEngine = NULL;
  56. RNADEACTIVATEENGINE lpRnaDeactivateEngine = NULL;
  57. RNADELETEENTRY lpRnaDeleteEntry = NULL;
  58. #define NUM_RNAAPI_PROCS 15
  59. APIFCN RasApiList[NUM_RNAAPI_PROCS] = {
  60. { (PVOID *) &lpRasEditPhonebookEntryA, szRasEditPhonebookEntryA},
  61. { (PVOID *) &lpRasEditPhonebookEntryW, szRasEditPhonebookEntryW},
  62. { (PVOID *) &lpRasEnumEntriesA, szRasEnumEntriesA},
  63. { (PVOID *) &lpRasEnumEntriesW, szRasEnumEntriesW},
  64. { (PVOID *) &lpRasGetEntryDialParamsA, szRasGetEntryDialParamsA},
  65. { (PVOID *) &lpRasGetEntryDialParamsW, szRasGetEntryDialParamsW},
  66. { (PVOID *) &lpRasSetEntryDialParamsA, szRasSetEntryDialParamsA},
  67. { (PVOID *) &lpRasSetEntryDialParamsW, szRasSetEntryDialParamsW},
  68. { (PVOID *) &lpRasDeleteEntryA, szRasDeleteEntryA},
  69. { (PVOID *) &lpRasDeleteEntryW, szRasDeleteEntryW},
  70. { (PVOID *) &lpRasCreatePhonebookEntryA, szRasCreatePhonebookEntryA},
  71. { (PVOID *) &lpRasGetEntryPropertiesW, szRasGetEntryPropertiesW},
  72. { (PVOID *) &lpRnaActivateEngine, szRnaActivateEngine},
  73. { (PVOID *) &lpRnaDeactivateEngine, szRnaDeactivateEngine},
  74. { (PVOID *) &lpRnaDeleteEntry, szRnaDeleteEntry}
  75. };
  76. //
  77. // Connection dialog needs info
  78. //
  79. typedef struct _conninfo {
  80. HTREEITEM hDefault;
  81. TCHAR szEntryName[RAS_MaxEntryName+1];
  82. } CONNINFO, *PCONNINFO;
  83. //
  84. // dial dialog needs some info asssociated with its window
  85. //
  86. typedef struct _dialinfo {
  87. PROXYINFO proxy; // manual proxy info
  88. BOOL fClickedAutodetect; // did the user actually click autodetect?
  89. LPTSTR pszConnectoid;
  90. #ifdef UNIX
  91. TCHAR szEntryName[RAS_MaxEntryName+1];
  92. #endif
  93. } DIALINFO, *PDIALINFO;
  94. //
  95. // Private Functions
  96. //
  97. BOOL ConnectionDlgInit(HWND hDlg, PCONNINFO pConn);
  98. BOOL ConnectionDlgOK(HWND hDlg, PCONNINFO pConn);
  99. VOID EnableConnectionControls(HWND hDlg, PCONNINFO pConn, BOOL fSetText);
  100. BOOL LoadRNADll(VOID);
  101. VOID UnloadRNADll(VOID);
  102. DWORD PopulateRasEntries(HWND hDlg, PCONNINFO pConn);
  103. BOOL MakeNewConnectoid(HWND hDlg, PCONNINFO pConn);
  104. BOOL EditConnectoid(HWND hDlg);
  105. VOID FixAutodialSettings(HWND hDlg, PCONNINFO pConn);
  106. INT_PTR CALLBACK DialupDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
  107. INT_PTR CALLBACK AdvDialupDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
  108. INT_PTR CALLBACK AdvAutocnfgDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
  109. // Handy stuff for looking at proxy exceptions (from proxysup.cpp)
  110. BOOL RemoveLocalFromExceptionList(IN LPTSTR lpszExceptionList);
  111. extern const TCHAR cszLocalString[];
  112. // defines for tree view image list
  113. #define BITMAP_WIDTH 16
  114. #define BITMAP_HEIGHT 16
  115. #define CONN_BITMAPS 2
  116. #define IMAGE_LAN 0
  117. #define IMAGE_MODEM 1
  118. void GetConnKey(LPTSTR pszConn, LPTSTR pszBuffer, int iBuffLen)
  119. {
  120. if(NULL == pszConn || 0 == *pszConn) {
  121. // use lan reg location
  122. StrCpyN(pszBuffer, REGSTR_PATH_INTERNET_LAN_SETTINGS, iBuffLen);
  123. } else {
  124. // use connectoid reg location
  125. wnsprintf(pszBuffer, iBuffLen, TEXT("%s\\Profile\\%s"), REGSTR_PATH_REMOTEACCESS, pszConn);
  126. }
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. //
  130. // JitFeature - decide if a feature is present, not present but
  131. // jitable, or not present and not jitable. Actually JIT it
  132. // in if requested
  133. //
  134. /////////////////////////////////////////////////////////////////////////////
  135. #define JIT_PRESENT 0 // Installed
  136. #define JIT_AVAILABLE 1 // Can be JIT'ed
  137. #define JIT_NOT_AVAILABLE 2 // You're in trouble - can't be JIT'ed
  138. DWORD JitFeature(HWND hwnd, REFCLSID clsidFeature, BOOL fCheckOnly)
  139. {
  140. HRESULT hr = REGDB_E_CLASSNOTREG;
  141. uCLSSPEC classpec;
  142. DWORD dwFlags = 0;
  143. // figure out struct and flags
  144. classpec.tyspec = TYSPEC_CLSID;
  145. classpec.tagged_union.clsid = clsidFeature;
  146. if(fCheckOnly)
  147. dwFlags = FIEF_FLAG_PEEK;
  148. //
  149. // since we only come to install of JIT features
  150. // only via a UI code path in inetcpl, we want to
  151. // simply ignore any previous UI action
  152. //
  153. dwFlags |= FIEF_FLAG_FORCE_JITUI;
  154. // call jit code
  155. hr = FaultInIEFeature(hwnd, &classpec, NULL, dwFlags);
  156. if(S_OK == hr) {
  157. // feature present
  158. return JIT_PRESENT;
  159. }
  160. if(S_FALSE == hr || E_ACCESSDENIED == hr) {
  161. // jit doesn't know about this feature. Assume it's present.
  162. return JIT_PRESENT;
  163. }
  164. if(HRESULT_FROM_WIN32(ERROR_CANCELLED) == hr) {
  165. // user didn't want it - may try again sometime, however
  166. return JIT_AVAILABLE;
  167. }
  168. if(fCheckOnly) {
  169. if(HRESULT_FROM_WIN32(ERROR_PRODUCT_UNINSTALLED) == hr) {
  170. // not present but can get it
  171. return JIT_AVAILABLE;
  172. }
  173. }
  174. //
  175. // Actually tried to get it but didn't - return not available
  176. //
  177. return JIT_NOT_AVAILABLE;
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. //
  181. // RasEnumHelp
  182. //
  183. // Abstract grusome details of getting a correct enumeration of entries
  184. // from RAS. Works on all 9x and NT platforms correctly, maintaining unicode
  185. // whenever possible.
  186. //
  187. /////////////////////////////////////////////////////////////////////////////
  188. class RasEnumHelp
  189. {
  190. private:
  191. //
  192. // Win2k version of RASENTRYNAMEW struct
  193. //
  194. #define W2KRASENTRYNAMEW struct tagW2KRASENTRYNAMEW
  195. W2KRASENTRYNAMEW
  196. {
  197. DWORD dwSize;
  198. WCHAR szEntryName[ RAS_MaxEntryName + 1 ];
  199. DWORD dwFlags;
  200. WCHAR szPhonebookPath[MAX_PATH + 1];
  201. };
  202. #define LPW2KRASENTRYNAMEW W2KRASENTRYNAMEW*
  203. //
  204. // Possible ways we got info from RAS
  205. //
  206. typedef enum {
  207. ENUM_MULTIBYTE, // Win9x
  208. ENUM_UNICODE, // NT4
  209. ENUM_WIN2K // Win2K
  210. } ENUM_TYPE;
  211. //
  212. // How we got the info
  213. //
  214. ENUM_TYPE _EnumType;
  215. //
  216. // Any error we got during enumeration
  217. //
  218. DWORD _dwLastError;
  219. //
  220. // Number of entries we got
  221. //
  222. DWORD _dwEntries;
  223. //
  224. // Pointer to info retrieved from RAS
  225. //
  226. RASENTRYNAMEA * _preList;
  227. //
  228. // Last entry returned as multibyte or unicode when conversion required
  229. //
  230. WCHAR _szCurrentEntryW[RAS_MaxEntryName + 1];
  231. public:
  232. RasEnumHelp();
  233. ~RasEnumHelp();
  234. DWORD GetError();
  235. DWORD GetEntryCount();
  236. LPWSTR GetEntryW(DWORD dwEntry);
  237. };
  238. RasEnumHelp::RasEnumHelp()
  239. {
  240. DWORD dwBufSize, dwStructSize;
  241. OSVERSIONINFO ver;
  242. // init
  243. _dwEntries = 0;
  244. _dwLastError = 0;
  245. // figure out which kind of enumeration we're doing - start with multibyte
  246. _EnumType = ENUM_MULTIBYTE;
  247. dwStructSize = sizeof(RASENTRYNAMEA);
  248. ver.dwOSVersionInfoSize = sizeof(ver);
  249. if(GetVersionEx(&ver))
  250. {
  251. if(VER_PLATFORM_WIN32_NT == ver.dwPlatformId)
  252. {
  253. _EnumType = ENUM_UNICODE;
  254. dwStructSize = sizeof(RASENTRYNAMEW);
  255. if(ver.dwMajorVersion >= 5)
  256. {
  257. _EnumType = ENUM_WIN2K;
  258. dwStructSize = sizeof(W2KRASENTRYNAMEW);
  259. }
  260. }
  261. }
  262. // allocate space for 16 entries
  263. dwBufSize = 16 * dwStructSize;
  264. _preList = (LPRASENTRYNAMEA)GlobalAlloc(LMEM_FIXED, dwBufSize);
  265. if(_preList)
  266. {
  267. do
  268. {
  269. // set up list
  270. _preList[0].dwSize = dwStructSize;
  271. // call ras to enumerate
  272. _dwLastError = ERROR_UNKNOWN;
  273. if(ENUM_MULTIBYTE == _EnumType)
  274. {
  275. if(lpRasEnumEntriesA)
  276. {
  277. _dwLastError = lpRasEnumEntriesA(
  278. NULL,
  279. NULL,
  280. (LPRASENTRYNAMEA)_preList,
  281. &dwBufSize,
  282. &_dwEntries
  283. );
  284. }
  285. }
  286. else
  287. {
  288. if(lpRasEnumEntriesW)
  289. {
  290. _dwLastError = lpRasEnumEntriesW(
  291. NULL,
  292. NULL,
  293. (LPRASENTRYNAMEW)_preList,
  294. &dwBufSize,
  295. &_dwEntries
  296. );
  297. }
  298. }
  299. // reallocate buffer if necessary
  300. if(ERROR_BUFFER_TOO_SMALL == _dwLastError)
  301. {
  302. GlobalFree(_preList);
  303. _preList = (LPRASENTRYNAMEA)GlobalAlloc(LMEM_FIXED, dwBufSize);
  304. if(NULL == _preList)
  305. {
  306. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  307. break;
  308. }
  309. }
  310. else
  311. {
  312. break;
  313. }
  314. } while(TRUE);
  315. }
  316. else
  317. {
  318. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  319. }
  320. if(_preList && (ERROR_SUCCESS != _dwLastError))
  321. {
  322. GlobalFree(_preList);
  323. _preList = NULL;
  324. _dwEntries = 0;
  325. }
  326. return;
  327. }
  328. RasEnumHelp::~RasEnumHelp()
  329. {
  330. if(_preList)
  331. {
  332. GlobalFree(_preList);
  333. }
  334. }
  335. DWORD
  336. RasEnumHelp::GetError()
  337. {
  338. return _dwLastError;
  339. }
  340. DWORD
  341. RasEnumHelp::GetEntryCount()
  342. {
  343. return _dwEntries;
  344. }
  345. LPWSTR
  346. RasEnumHelp::GetEntryW(
  347. DWORD dwEntryNum
  348. )
  349. {
  350. LPWSTR pwszName = NULL;
  351. if(dwEntryNum >= _dwEntries)
  352. {
  353. return NULL;
  354. }
  355. switch(_EnumType)
  356. {
  357. case ENUM_MULTIBYTE:
  358. MultiByteToWideChar(CP_ACP, 0, _preList[dwEntryNum].szEntryName,
  359. -1, _szCurrentEntryW, RAS_MaxEntryName + 1);
  360. pwszName = _szCurrentEntryW;
  361. break;
  362. case ENUM_UNICODE:
  363. {
  364. LPRASENTRYNAMEW lpTemp = (LPRASENTRYNAMEW)_preList;
  365. pwszName = lpTemp[dwEntryNum].szEntryName;
  366. break;
  367. }
  368. case ENUM_WIN2K:
  369. {
  370. LPW2KRASENTRYNAMEW lpTemp = (LPW2KRASENTRYNAMEW)_preList;
  371. pwszName = lpTemp[dwEntryNum].szEntryName;
  372. break;
  373. }
  374. }
  375. return pwszName;
  376. }
  377. /////////////////////////////////////////////////////////////////////////////
  378. //
  379. // NAME: MakeNewConnectoid
  380. //
  381. // SYNOPSIS: Launches RNA new connectoid wizard; selects newly
  382. // created connectoid (if any) in combo box
  383. //
  384. /////////////////////////////////////////////////////////////////////////////
  385. typedef BOOL (*PFRED)(LPTSTR, LPTSTR, LPRASENTRYDLG);
  386. BOOL MakeNewConnectoid(HWND hDlg, PCONNINFO pConn)
  387. {
  388. BOOL fRet = FALSE, fDone = FALSE;
  389. DWORD dwRes = 0;
  390. ASSERT(lpRasCreatePhonebookEntryA);
  391. if(FALSE == g_fWin95) {
  392. // on NT, use RasEntryDlg so we know who we created and can edit
  393. // proxy info for that connectoid
  394. HMODULE hRasDlg = LoadLibrary(TEXT("rasdlg.dll"));
  395. if(hRasDlg) {
  396. #ifdef UNICODE
  397. PFRED pfred = (PFRED)GetProcAddress(hRasDlg, "RasEntryDlgW");
  398. #else
  399. PFRED pfred = (PFRED)GetProcAddress(hRasDlg, "RasEntryDlgA");
  400. #endif
  401. if(pfred) {
  402. RASENTRYDLG info;
  403. memset(&info, 0, sizeof(RASENTRYDLG));
  404. info.dwSize = sizeof(RASENTRYDLG);
  405. info.hwndOwner = hDlg;
  406. info.dwFlags = RASEDFLAG_NewEntry;
  407. dwRes = (pfred)(NULL, NULL, &info);
  408. if(dwRes) {
  409. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_DIALUP), hDlg,
  410. DialupDlgProc, (LPARAM)info.szEntry);
  411. dwRes = ERROR_SUCCESS;
  412. // save name as default
  413. lstrcpyn(pConn->szEntryName, info.szEntry, RAS_MaxEntryName);
  414. } else {
  415. dwRes = info.dwError;
  416. }
  417. fDone = TRUE;
  418. }
  419. FreeLibrary(hRasDlg);
  420. }
  421. }
  422. if(FALSE == fDone) {
  423. // on win95, show the ui to make new entry
  424. if(lpRasCreatePhonebookEntryA)
  425. {
  426. dwRes = (lpRasCreatePhonebookEntryA)(hDlg,NULL);
  427. }
  428. // if we're on millennium, refresh default
  429. if(g_fMillennium)
  430. {
  431. FixAutodialSettings(hDlg, pConn);
  432. }
  433. }
  434. if(ERROR_SUCCESS == dwRes) {
  435. // make sure dial default is turned on. If this is NT, default entry
  436. // is set above to new entry.
  437. if(IsDlgButtonChecked(hDlg, IDC_DIALUP_NEVER))
  438. {
  439. CheckRadioButton(hDlg, IDC_DIALUP_NEVER, IDC_DIALUP, IDC_DIALUP);
  440. }
  441. PopulateRasEntries(hDlg, pConn);
  442. EnableConnectionControls(hDlg, pConn, FALSE);
  443. fRet = TRUE;
  444. }
  445. return fRet;
  446. }
  447. ///////////////////////////////////////////////////////////////////////////
  448. //
  449. // NAME: PopulateRasEntries
  450. //
  451. // ENTRY: hwndDlg - dlg box window handle
  452. //
  453. // SYNOPSIS: Fills specified combo box with list of existing RNA
  454. // connectoids
  455. //
  456. ///////////////////////////////////////////////////////////////////////////
  457. #define DEF_ENTRY_BUF_SIZE 8192
  458. DWORD PopulateRasEntries(HWND hDlg, PCONNINFO pConn)
  459. {
  460. HWND hwndTree = GetDlgItem(hDlg, IDC_CONN_LIST);
  461. DWORD i;
  462. DWORD dwBufSize = 16 * sizeof(RASENTRYNAMEA);
  463. DWORD dwEntries = 0;
  464. TVITEM tvi;
  465. TVINSERTSTRUCT tvins;
  466. HTREEITEM hFirst = NULL;
  467. ASSERT(hwndTree);
  468. // init tvi and tvins
  469. tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  470. tvi.lParam = 0;
  471. tvins.hInsertAfter = (HTREEITEM)TVI_SORT;
  472. tvins.hParent = TVI_ROOT;
  473. // clear list
  474. TreeView_DeleteAllItems(hwndTree);
  475. // any old htree is now bogus - we'll get a new one
  476. pConn->hDefault = NULL;
  477. // enumerate
  478. RasEnumHelp reh;
  479. if(ERROR_SUCCESS == reh.GetError())
  480. {
  481. TCHAR szTemp[RAS_MaxEntryName + 64];
  482. BOOL fDefault, fFoundDefault = FALSE;
  483. LPTSTR pszEntryName;
  484. // insert connectoid names from buffer into combo box
  485. for(i=0; i<reh.GetEntryCount(); i++)
  486. {
  487. pszEntryName = reh.GetEntryW(i);
  488. fDefault = FALSE;
  489. // if there's only one entry, force it to be the default
  490. if(1 == dwEntries)
  491. {
  492. StrCpyN(pConn->szEntryName, pszEntryName, RAS_MaxEntryName);
  493. }
  494. if(*pConn->szEntryName && 0 == StrCmp(pszEntryName, pConn->szEntryName)) {
  495. // this is the default entry - stick it in the default
  496. // text control and append (Default) to it
  497. SetWindowText(GetDlgItem(hDlg, IDC_DIAL_DEF_ISP), pConn->szEntryName);
  498. StrCpyN(szTemp, pszEntryName, RAS_MaxEntryName);
  499. MLLoadString(IDS_DEFAULT_TEXT, szTemp + lstrlen(szTemp), 64);
  500. tvi.pszText = szTemp;
  501. fDefault = TRUE;
  502. fFoundDefault = TRUE;
  503. } else {
  504. tvi.pszText = pszEntryName;
  505. }
  506. tvi.iImage = IMAGE_MODEM;
  507. tvi.iSelectedImage = IMAGE_MODEM;
  508. tvi.lParam = i;
  509. tvins.item = tvi;
  510. HTREEITEM hItem = TreeView_InsertItem(hwndTree, &tvins);
  511. if(NULL == hFirst)
  512. hFirst = hItem;
  513. if(fDefault)
  514. pConn->hDefault = hItem;
  515. }
  516. // if we didn't match our default with a connectoid, kill it
  517. if(FALSE == fFoundDefault)
  518. {
  519. *pConn->szEntryName = 0;
  520. MLLoadString(IDS_NONE, szTemp, 64);
  521. SetWindowText(GetDlgItem(hDlg, IDC_DIAL_DEF_ISP), szTemp);
  522. }
  523. }
  524. // select default or first entry if there is one
  525. if(pConn->hDefault)
  526. {
  527. TreeView_Select(hwndTree, pConn->hDefault, TVGN_CARET);
  528. }
  529. else if(hFirst)
  530. {
  531. TreeView_Select(hwndTree, hFirst, TVGN_CARET);
  532. }
  533. return reh.GetEntryCount();
  534. }
  535. void PopulateProxyControls(HWND hDlg, LPPROXYINFO pInfo, BOOL fSetText)
  536. {
  537. BOOL fManual = FALSE, fScript = FALSE, fDisable, fTemp;
  538. // decide if everything is disabled
  539. fDisable = IsDlgButtonChecked(hDlg, IDC_DONT_USE_CONNECTION);
  540. //
  541. // disable proxy enable check box if proxy restricted
  542. //
  543. fTemp = fDisable || g_restrict.fProxy;
  544. EnableDlgItem(hDlg, IDC_MANUAL, !fTemp);
  545. if(FALSE == g_restrict.fProxy)
  546. {
  547. fManual = !fDisable && pInfo->fEnable;
  548. }
  549. //
  550. // Disable autoconfig if restricted
  551. //
  552. fScript = !fDisable && IsDlgButtonChecked(hDlg, IDC_CONFIGSCRIPT);
  553. fTemp = fDisable || g_restrict.fAutoConfig;
  554. EnableDlgItem(hDlg, IDC_CONFIGSCRIPT, !fTemp);
  555. EnableDlgItem(hDlg, IDC_AUTODISCOVER, !fTemp);
  556. if(fTemp)
  557. {
  558. fScript = FALSE;
  559. }
  560. // enable config script controls
  561. EnableDlgItem(hDlg, IDC_CONFIG_ADDR, fScript);
  562. EnableDlgItem(hDlg, IDC_CONFIGADDR_TX, fScript);
  563. EnableDlgItem(hDlg, IDC_AUTOCNFG_ADVANCED, fScript);
  564. // Button is always on and omit local addresses is available if proxy is checked
  565. EnableDlgItem(hDlg, IDC_PROXY_ADVANCED, fManual);
  566. EnableDlgItem(hDlg, IDC_PROXY_OMIT_LOCAL_ADDRESSES, fManual);
  567. // Enable dial controls as necessary
  568. EnableDlgItem(hDlg, IDC_USER, !fDisable && !pInfo->fCustomHandler);
  569. EnableDlgItem(hDlg, IDC_PASSWORD, !fDisable && !pInfo->fCustomHandler);
  570. EnableDlgItem(hDlg, IDC_DOMAIN, !fDisable && !pInfo->fCustomHandler);
  571. EnableDlgItem(hDlg, IDC_TX_USER, !fDisable && !pInfo->fCustomHandler);
  572. EnableDlgItem(hDlg, IDC_TX_PASSWORD, !fDisable && !pInfo->fCustomHandler);
  573. EnableDlgItem(hDlg, IDC_TX_DOMAIN, !fDisable && !pInfo->fCustomHandler);
  574. EnableDlgItem(hDlg, IDC_RAS_SETTINGS, !fDisable);
  575. EnableDlgItem(hDlg, IDC_DIAL_ADVANCED, !fDisable && !pInfo->fCustomHandler);
  576. // settings changed in here are enabled/disabled based on the actual proxy settings
  577. if(StrChr(pInfo->szProxy, TEXT('=')))
  578. {
  579. // different servers for each - disable fields on this dialog
  580. fManual = FALSE;
  581. if (fSetText)
  582. {
  583. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_ADDR), TEXT(""));
  584. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), TEXT(""));
  585. }
  586. }
  587. else if (fSetText)
  588. {
  589. TCHAR *pszColon, *pszColon2;
  590. //Is there a : in the proxy string ?
  591. pszColon = StrChr(pInfo->szProxy, TEXT(':'));
  592. if(pszColon)
  593. {
  594. //Yes, Find if we have another ':'
  595. pszColon2 = StrChr(pszColon + 1, TEXT(':'));
  596. if(pszColon2)
  597. {
  598. //Yes, so we have strig like http://itgproxy:80
  599. pszColon = pszColon2;
  600. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), pszColon + 1);
  601. *pszColon = 0;
  602. }
  603. else
  604. {
  605. //No, We dont have a second ':'
  606. int ilength = (int) (pszColon - pInfo->szProxy);
  607. //Are there atleast two characters left beyond the first ':'
  608. if (lstrlen(pInfo->szProxy) - ilength >= 2 )
  609. {
  610. //Yes, Are Those characters equal //
  611. if((pInfo->szProxy[++ilength] == TEXT('/')) &&
  612. (pInfo->szProxy[++ilength] == TEXT('/')))
  613. {
  614. //Yes then we have string like http://itgproxy
  615. //make the whole thing as the server and make port fiel empty
  616. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), TEXT(""));
  617. }
  618. else
  619. {
  620. //No, so we have string like itgproxy:80.
  621. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), pszColon + 1);
  622. *pszColon = 0;
  623. }
  624. }
  625. else
  626. {
  627. //No We dont have atleast two character so lets parse this as server and port
  628. // Assuming this strign to be something like itgproxy:8
  629. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), pszColon + 1);
  630. *pszColon = 0;
  631. }
  632. }
  633. }
  634. else
  635. {
  636. //No we dont have a : so treat the string as just the proxy server.
  637. //Case itgproxy
  638. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), TEXT(""));
  639. }
  640. SetWindowText(GetDlgItem(hDlg, IDC_PROXY_ADDR), pInfo->szProxy);
  641. }
  642. EnableDlgItem(hDlg, IDC_ADDRESS_TEXT, fManual);
  643. EnableDlgItem(hDlg, IDC_PORT_TEXT, fManual);
  644. EnableDlgItem(hDlg, IDC_PROXY_ADDR, fManual);
  645. EnableDlgItem(hDlg, IDC_PROXY_PORT, fManual);
  646. }
  647. void GetProxyInfo(HWND hDlg, PDIALINFO pDI)
  648. {
  649. pDI->proxy.fEnable = IsDlgButtonChecked(hDlg, IDC_MANUAL);
  650. if(NULL == StrChr(pDI->proxy.szProxy, TEXT('=')))
  651. {
  652. //
  653. // not per-protocol, so read edit boxes
  654. //
  655. TCHAR szProxy[MAX_URL_STRING];
  656. TCHAR szPort[INTERNET_MAX_PORT_NUMBER_LENGTH + 1];
  657. GetWindowText(GetDlgItem(hDlg, IDC_PROXY_ADDR), szProxy, ARRAYSIZE(szProxy) );
  658. GetWindowText(GetDlgItem(hDlg, IDC_PROXY_PORT), szPort, ARRAYSIZE(szPort) );
  659. // if we got a proxy and a port, combine in to one string
  660. if(*szProxy && *szPort)
  661. wnsprintf(pDI->proxy.szProxy, ARRAYSIZE(pDI->proxy.szProxy), TEXT("%s:%s"), szProxy, szPort);
  662. else
  663. StrCpyN(pDI->proxy.szProxy, szProxy, ARRAYSIZE(pDI->proxy.szProxy));
  664. }
  665. //
  666. // fix manual settings override
  667. //
  668. pDI->proxy.fOverrideLocal = IsDlgButtonChecked(hDlg, IDC_PROXY_OMIT_LOCAL_ADDRESSES);
  669. if(pDI->proxy.fOverrideLocal) {
  670. RemoveLocalFromExceptionList(pDI->proxy.szOverride);
  671. if(*pDI->proxy.szOverride)
  672. wnsprintf(pDI->proxy.szOverride, ARRAYSIZE(pDI->proxy.szOverride), TEXT("%s;%s"), pDI->proxy.szOverride, cszLocalString);
  673. else
  674. StrCpyN(pDI->proxy.szOverride, cszLocalString, ARRAYSIZE(pDI->proxy.szOverride));
  675. }
  676. }
  677. //////////////////////////////////////////////////////////////////////
  678. //
  679. // NAME: DeleteRasEntry
  680. //
  681. // SYNOPSIS: Delete a connectoid
  682. //
  683. //////////////////////////////////////////////////////////////////////
  684. void DeleteRasEntry(LPTSTR pszEntry)
  685. {
  686. // Use RasDeleteEntryW if possible
  687. if(lpRasDeleteEntryW)
  688. {
  689. (lpRasDeleteEntryW)(NULL, pszEntry);
  690. }
  691. else
  692. {
  693. CHAR szEntryA[MAX_PATH];
  694. SHUnicodeToAnsi(pszEntry, szEntryA, ARRAYSIZE(szEntryA));
  695. // Use RasDeleteEntryA if possible
  696. if(lpRasDeleteEntryA)
  697. {
  698. (lpRasDeleteEntryA)(NULL, szEntryA);
  699. }
  700. else
  701. {
  702. // no RasDeleteEntry - must by Win95 gold machine. Use RNA. Ick.
  703. if( lpRnaActivateEngine &&
  704. lpRnaDeleteEntry &&
  705. lpRnaDeactivateEngine &&
  706. ERROR_SUCCESS == (lpRnaActivateEngine)())
  707. {
  708. (lpRnaDeleteEntry)(szEntryA);
  709. (lpRnaDeactivateEngine)();
  710. }
  711. }
  712. }
  713. }
  714. //////////////////////////////////////////////////////////////////////
  715. //
  716. // NAME: ChangeDefault
  717. //
  718. // SYNOPSIS: Change default connectoid to currently selected one
  719. //
  720. //////////////////////////////////////////////////////////////////////
  721. void ChangeDefault(HWND hDlg, PCONNINFO pConn)
  722. {
  723. TVITEM tvi;
  724. HWND hwndTree = GetDlgItem(hDlg, IDC_CONN_LIST);
  725. HTREEITEM hCur;
  726. memset(&tvi, 0, sizeof(TVITEM));
  727. // find current selection - if there isn't one, bail
  728. hCur = TreeView_GetSelection(hwndTree);
  729. if(NULL == hCur)
  730. return;
  731. // remove (default) from current default
  732. if(pConn->hDefault) {
  733. tvi.mask = TVIF_HANDLE | TVIF_TEXT;
  734. tvi.hItem = pConn->hDefault;
  735. tvi.pszText = pConn->szEntryName;
  736. tvi.cchTextMax = RAS_MaxEntryName;
  737. TreeView_SetItem(hwndTree, &tvi);
  738. }
  739. // get text for current item
  740. tvi.mask = TVIF_HANDLE | TVIF_TEXT;
  741. tvi.hItem = hCur;
  742. tvi.pszText = pConn->szEntryName;
  743. tvi.cchTextMax = RAS_MaxEntryName;
  744. TreeView_GetItem(hwndTree, &tvi);
  745. // fill in default text field
  746. SetWindowText(GetDlgItem(hDlg, IDC_DIAL_DEF_ISP), pConn->szEntryName);
  747. // add (default) to current selection
  748. TCHAR szTemp[RAS_MaxEntryName + 64];
  749. StrCpyN(szTemp, pConn->szEntryName, RAS_MaxEntryName);
  750. MLLoadString(IDS_DEFAULT_TEXT, szTemp + lstrlen(szTemp), 64);
  751. // stick it back in the tree
  752. tvi.mask = TVIF_HANDLE | TVIF_TEXT;
  753. tvi.hItem = hCur;
  754. tvi.pszText = szTemp;
  755. tvi.cchTextMax = RAS_MaxEntryName;
  756. TreeView_SetItem(hwndTree, &tvi);
  757. // save htree
  758. pConn->hDefault = hCur;
  759. }
  760. //////////////////////////////////////////////////////////////////////
  761. //
  762. // NAME: ShowConnProps
  763. //
  764. // SYNOPSIS: Show properties for selected connection
  765. //
  766. //////////////////////////////////////////////////////////////////////
  767. HTREEITEM GetCurSel(PCONNINFO pConn, HWND hDlg, LPTSTR pszBuffer, int iLen, BOOL *pfChecked)
  768. {
  769. HWND hwndTree = GetDlgItem(hDlg, IDC_CONN_LIST);
  770. TVITEM tvi;
  771. tvi.hItem = TreeView_GetSelection(hwndTree);
  772. if(tvi.hItem) {
  773. tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
  774. tvi.stateMask = TVIS_STATEIMAGEMASK;
  775. // get test if needed
  776. if(pszBuffer) {
  777. tvi.mask |= TVIF_TEXT;
  778. tvi.pszText = pszBuffer;
  779. tvi.cchTextMax = iLen;
  780. }
  781. TreeView_GetItem(hwndTree, &tvi);
  782. if(pfChecked)
  783. *pfChecked = (BOOL)(tvi.state >> 12) - 1;
  784. }
  785. // if this is the default connectiod, return name without (default) part
  786. if(pszBuffer && tvi.hItem == pConn->hDefault) {
  787. StrCpyN(pszBuffer, pConn->szEntryName, iLen);
  788. }
  789. return tvi.hItem;
  790. }
  791. void ShowConnProps(HWND hDlg, PCONNINFO pConn, BOOL fLan)
  792. {
  793. HTREEITEM hItem = NULL;
  794. TCHAR szEntryName[RAS_MaxEntryName+1];
  795. BOOL fChecked = FALSE;
  796. // if not lan, apply current selections
  797. if(g_fMillennium && !fLan)
  798. {
  799. ConnectionDlgOK(hDlg, pConn);
  800. }
  801. // default to lan
  802. *szEntryName = 0;
  803. // find item of interest
  804. if(FALSE == fLan)
  805. hItem = GetCurSel(pConn, hDlg, szEntryName, RAS_MaxEntryName, &fChecked);
  806. if(hItem || fLan) {
  807. // show settings
  808. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_DIALUP), hDlg,
  809. DialupDlgProc, (LPARAM)szEntryName);
  810. }
  811. // if not lan, some settings may have been changed by RAS UI -- refresh
  812. if(g_fMillennium && !fLan )
  813. {
  814. FixAutodialSettings(hDlg, pConn);
  815. }
  816. }
  817. BOOL GetConnSharingDll(LPTSTR pszPath)
  818. {
  819. DWORD cb = SIZEOF(TCHAR) * MAX_PATH;
  820. return SHGetValue(HKEY_LOCAL_MACHINE,
  821. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
  822. TEXT("SharingDLL"), NULL, pszPath, &cb) == ERROR_SUCCESS;
  823. }
  824. BOOL IsConnSharingAvail()
  825. {
  826. TCHAR szPath[MAX_PATH];
  827. return GetConnSharingDll(szPath);
  828. }
  829. typedef HRESULT (WINAPI *PFNCONNECTIONSHARING)(HWND hwnd, DWORD dwFlags);
  830. void ShowConnSharing(HWND hDlg)
  831. {
  832. TCHAR szPath[MAX_PATH];
  833. if (GetConnSharingDll(szPath))
  834. {
  835. HMODULE hmod = LoadLibrary(szPath);
  836. if (hmod)
  837. {
  838. PFNCONNECTIONSHARING pfn = (PFNCONNECTIONSHARING)GetProcAddress(hmod, "InternetConnectionSharing");
  839. if (pfn)
  840. pfn(hDlg, 0);
  841. FreeLibrary(hmod);
  842. }
  843. }
  844. }
  845. //////////////////////////////////////////////////////////////////////
  846. //
  847. // NAME: ConnectionDlgProc
  848. //
  849. // SYNOPSIS: Connection property sheet dialog proc.
  850. //
  851. //////////////////////////////////////////////////////////////////////
  852. INT_PTR CALLBACK ConnectionDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  853. LPARAM lParam)
  854. {
  855. PCONNINFO pConn = (PCONNINFO)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  856. if (NULL == pConn && uMsg != WM_INITDIALOG)
  857. {
  858. return FALSE;
  859. }
  860. switch (uMsg)
  861. {
  862. case WM_INITDIALOG:
  863. // build and save conninfo struct
  864. pConn = new CONNINFO;
  865. if(NULL == pConn)
  866. return FALSE;
  867. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pConn);
  868. memset(pConn, 0, sizeof(CONNINFO));
  869. return ConnectionDlgInit(hDlg, pConn);
  870. case WM_DESTROY:
  871. {
  872. UnloadRNADll();
  873. // Free the image list used by the connection list
  874. HWND hwndConnList = GetDlgItem(hDlg, IDC_CONN_LIST);
  875. HIMAGELIST himl = TreeView_SetImageList(hwndConnList, NULL, TVSIL_NORMAL);
  876. if (himl)
  877. {
  878. ImageList_Destroy(himl);
  879. }
  880. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)NULL);
  881. delete pConn;
  882. return TRUE;
  883. }
  884. case WM_NOTIFY:
  885. {
  886. NMHDR * lpnm = (NMHDR *) lParam;
  887. switch (lpnm->code)
  888. {
  889. case TVN_KEYDOWN:
  890. {
  891. TV_KEYDOWN *pkey = (TV_KEYDOWN*)lpnm;
  892. if(pkey->wVKey == VK_SPACE)
  893. {
  894. ENABLEAPPLY(hDlg);
  895. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE); // eat the key
  896. return TRUE;
  897. }
  898. break;
  899. }
  900. case NM_CLICK:
  901. case NM_DBLCLK:
  902. { // is this click in our tree?
  903. if(lpnm->idFrom == IDC_CONN_LIST)
  904. {
  905. HWND hwndTree = GetDlgItem(hDlg, IDC_CONN_LIST);
  906. TV_HITTESTINFO ht;
  907. HTREEITEM hItem;
  908. GetCursorPos(&ht.pt);
  909. ScreenToClient(hwndTree, &ht.pt);
  910. hItem = TreeView_HitTest(hwndTree, &ht);
  911. if(hItem)
  912. {
  913. TreeView_SelectItem(hwndTree, hItem);
  914. // If it's a double click, show settings
  915. if(NM_DBLCLK == lpnm->code)
  916. {
  917. PostMessage(hDlg, WM_COMMAND, IDC_MODEM_SETTINGS, 0);
  918. }
  919. }
  920. }
  921. EnableConnectionControls(hDlg, pConn, FALSE);
  922. break;
  923. }
  924. case TVN_SELCHANGEDA:
  925. case TVN_SELCHANGEDW:
  926. EnableConnectionControls(hDlg, pConn, FALSE);
  927. break;
  928. case PSN_QUERYCANCEL:
  929. case PSN_KILLACTIVE:
  930. case PSN_RESET:
  931. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  932. return TRUE;
  933. case PSN_APPLY:
  934. {
  935. BOOL fRet = ConnectionDlgOK(hDlg, pConn);
  936. SetPropSheetResult(hDlg,!fRet);
  937. return !fRet;
  938. break;
  939. }
  940. }
  941. break;
  942. }
  943. case WM_COMMAND:
  944. switch (LOWORD(wParam))
  945. {
  946. case IDC_LAN_SETTINGS:
  947. ShowConnProps(hDlg, pConn, TRUE);
  948. break;
  949. case IDC_CON_SHARING:
  950. ShowConnSharing(hDlg);
  951. break;
  952. case IDC_DIALUP_ADD:
  953. MakeNewConnectoid(hDlg, pConn);
  954. break;
  955. case IDC_DIALUP_REMOVE:
  956. {
  957. TCHAR szEntryName[RAS_MaxEntryName+1];
  958. if (GetCurSel(pConn, hDlg, szEntryName, RAS_MaxEntryName, NULL) &&
  959. *szEntryName) {
  960. if(IDOK == MsgBox(hDlg, IDS_DELETECONNECTOID, MB_ICONWARNING, MB_OKCANCEL)) {
  961. DeleteRasEntry(szEntryName);
  962. PopulateRasEntries(hDlg, pConn);
  963. // fix controls
  964. EnableConnectionControls(hDlg, pConn, FALSE);
  965. }
  966. }
  967. break;
  968. }
  969. case IDC_DIALUP:
  970. case IDC_DIALUP_ON_NONET:
  971. case IDC_DIALUP_NEVER:
  972. // fix radio buttons
  973. CheckRadioButton(hDlg, IDC_DIALUP_NEVER, IDC_DIALUP, LOWORD(wParam));
  974. // enable/disable other controls appropriately
  975. EnableConnectionControls(hDlg, pConn, FALSE);
  976. ENABLEAPPLY(hDlg);
  977. break;
  978. case IDC_ENABLE_SECURITY:
  979. ENABLEAPPLY(hDlg);
  980. break;
  981. case IDC_SET_DEFAULT:
  982. ChangeDefault(hDlg, pConn);
  983. if(GetFocus() == GetDlgItem(hDlg, IDC_SET_DEFAULT))
  984. {
  985. // focus is currently on the button and it's about to be disabled
  986. SetFocus(GetDlgItem(hDlg, IDC_CONN_LIST));
  987. }
  988. EnableConnectionControls(hDlg, pConn, FALSE);
  989. ENABLEAPPLY(hDlg);
  990. break;
  991. case IDC_MODEM_SETTINGS:
  992. ShowConnProps(hDlg, pConn, FALSE);
  993. break;
  994. case IDC_CONNECTION_WIZARD:
  995. TCHAR szICWReg[MAX_PATH];
  996. TCHAR szICWPath[MAX_PATH + 1];
  997. DWORD cbSize = MAX_PATH, dwType;
  998. if (IsOS(OS_WHISTLERORGREATER))
  999. {
  1000. // This is the invocation path for the New Connection Wizard in Whistler
  1001. StrCpy(szICWPath, TEXT("rundll32.exe netshell.dll,StartNCW"));
  1002. }
  1003. else
  1004. {
  1005. // Try and get ICW from IOD. If it fails, try to run
  1006. // ICW anyway. We may luck out and get an old one.
  1007. DWORD dwRes = JitFeature(hDlg, clsidFeatureICW, FALSE);
  1008. // find path of ICW
  1009. MLLoadString(IDS_ICW_NAME, szICWPath, MAX_PATH);
  1010. wnsprintf(szICWReg, ARRAYSIZE(szICWReg), TEXT("%s\\%s"), REGSTR_PATH_APPPATHS, szICWPath);
  1011. // read app paths key
  1012. if(ERROR_SUCCESS != SHGetValue(HKEY_LOCAL_MACHINE, szICWReg, NULL, &dwType, szICWPath, &cbSize))
  1013. break;
  1014. }
  1015. // run connection wizard
  1016. STARTUPINFO si;
  1017. PROCESS_INFORMATION pi;
  1018. memset(&si, 0, sizeof(si));
  1019. si.cb = sizeof(si);
  1020. if(CreateProcess(NULL, szICWPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  1021. {
  1022. // successfully ran ICW - get rid of this dialog
  1023. CloseHandle(pi.hProcess);
  1024. CloseHandle(pi.hThread);
  1025. PropSheet_PressButton(GetParent(hDlg), PSBTN_CANCEL);
  1026. }
  1027. break;
  1028. }
  1029. break;
  1030. case WM_HELP: // F1
  1031. ResWinHelp((HWND) ((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1032. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1033. break;
  1034. case WM_CONTEXTMENU: // right mouse click
  1035. ResWinHelp((HWND)wParam, IDS_HELPFILE,
  1036. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1037. break;
  1038. default:
  1039. return FALSE;
  1040. }
  1041. return TRUE;
  1042. }
  1043. /*******************************************************************
  1044. NAME: ConnectionDlgOK
  1045. SYNOPSIS: OK button handler for connection prop page
  1046. ********************************************************************/
  1047. // prototype for IsNetworkAlive()
  1048. typedef BOOL (WINAPI *ISNETWORKALIVE)(LPDWORD);
  1049. BOOL ConnectionDlgOK(HWND hDlg, PCONNINFO pConn)
  1050. {
  1051. DWORD dwAutodial;
  1052. RegEntry re(REGSTR_PATH_INTERNETSETTINGS,HKEY_CURRENT_USER);
  1053. if(ERROR_SUCCESS == re.GetError()) {
  1054. // autodial
  1055. dwAutodial = AUTODIAL_MODE_NEVER;
  1056. if(IsDlgButtonChecked(hDlg, IDC_DIALUP))
  1057. {
  1058. dwAutodial = AUTODIAL_MODE_ALWAYS;
  1059. }
  1060. else if(IsDlgButtonChecked(hDlg, IDC_DIALUP_ON_NONET))
  1061. {
  1062. dwAutodial = AUTODIAL_MODE_NO_NETWORK_PRESENT;
  1063. DWORD dwRes = JitFeature(hDlg, clsidFeatureMobile, FALSE);
  1064. if(JIT_PRESENT != dwRes) {
  1065. // user doesn't want MOP, change to dial always.
  1066. dwAutodial = AUTODIAL_MODE_ALWAYS;
  1067. }
  1068. else
  1069. {
  1070. // Call IsNetworkAlive. This will start sens service
  1071. // and next instance of wininet will use it.
  1072. HINSTANCE hSens;
  1073. ISNETWORKALIVE pfnIsNetworkAlive;
  1074. DWORD dwFlags;
  1075. hSens = LoadLibrary(TEXT("sensapi.dll"));
  1076. if(hSens)
  1077. {
  1078. pfnIsNetworkAlive = (ISNETWORKALIVE)GetProcAddress(hSens, "IsNetworkAlive");
  1079. if(pfnIsNetworkAlive)
  1080. {
  1081. // Call it. Don't really care about the result.
  1082. pfnIsNetworkAlive(&dwFlags);
  1083. }
  1084. FreeLibrary(hSens);
  1085. }
  1086. }
  1087. }
  1088. // save autodial mode
  1089. InternetSetOption(NULL, INTERNET_OPTION_AUTODIAL_MODE, &dwAutodial, sizeof(dwAutodial));
  1090. // save default connectoid
  1091. if(*pConn->szEntryName)
  1092. {
  1093. InternetSetOption(NULL, INTERNET_OPTION_AUTODIAL_CONNECTION, pConn->szEntryName, lstrlen(pConn->szEntryName));
  1094. }
  1095. }
  1096. // save security check state on win95
  1097. if(g_fWin95)
  1098. {
  1099. DWORD dwValue = 0;
  1100. if(IsDlgButtonChecked(hDlg, IDC_ENABLE_SECURITY))
  1101. {
  1102. dwValue = 1;
  1103. }
  1104. re.SetValue(REGSTR_VAL_ENABLESECURITYCHECK, dwValue);
  1105. }
  1106. //
  1107. // Have wininet refresh it's connection settings
  1108. //
  1109. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  1110. UpdateAllWindows();
  1111. return TRUE;
  1112. }
  1113. /////////////////////////////////////////////////////////////////////////////
  1114. //
  1115. // NAME: EnableConnectionControls
  1116. //
  1117. // SYNOPSIS: Enables controls appropriately depending on what
  1118. // checkboxes are checked.
  1119. //
  1120. /////////////////////////////////////////////////////////////////////////////
  1121. VOID EnableConnectionControls(HWND hDlg, PCONNINFO pConn, BOOL fSetText)
  1122. {
  1123. TCHAR szEntryName[RAS_MaxEntryName + 1];
  1124. BOOL fList = FALSE, fDial = FALSE, fAutodial = FALSE;
  1125. BOOL fAdd = FALSE, fSettings = FALSE, fLan = TRUE, fSetDefault = TRUE;
  1126. BOOL fDialDefault = FALSE, fNT4SP3;
  1127. HTREEITEM hItem;
  1128. int iCount;
  1129. fNT4SP3 = IsNTSPx(FALSE, 4, 3);
  1130. if(fNT4SP3)
  1131. {
  1132. // no sens stuff on NT4SP3, so make sure on no net isn't picked
  1133. if(IsDlgButtonChecked(hDlg, IDC_DIALUP_ON_NONET))
  1134. {
  1135. CheckRadioButton(hDlg, IDC_DIALUP_NEVER, IDC_DIALUP, IDC_DIALUP);
  1136. }
  1137. }
  1138. //
  1139. // Check out how much stuff is in the tree view and what's selected
  1140. //
  1141. iCount = TreeView_GetCount(GetDlgItem(hDlg, IDC_CONN_LIST));
  1142. hItem = GetCurSel(pConn, hDlg, szEntryName, RAS_MaxEntryName, NULL);
  1143. if(dwRNARefCount) {
  1144. // Ras is loaded so enable list control
  1145. fList = TRUE;
  1146. // if anything is selected, turn on settings button
  1147. if(hItem)
  1148. {
  1149. fSettings = TRUE;
  1150. if(hItem == pConn->hDefault)
  1151. {
  1152. fSetDefault = FALSE;
  1153. }
  1154. }
  1155. // Ensure ras is loaded
  1156. if(iCount > 0)
  1157. fDial = TRUE;
  1158. }
  1159. // check to see if dial default is checked
  1160. if(fDial)
  1161. fDialDefault = !IsDlgButtonChecked(hDlg, IDC_DIALUP_NEVER);
  1162. if(fList && lpRasCreatePhonebookEntryA)
  1163. fAdd = TRUE;
  1164. // if dialing restriction is present, make sure user can't do nothing.
  1165. if(g_restrict.fDialing)
  1166. fAdd = fList = fDial = fDialDefault = fAutodial = fSettings = fLan = fSetDefault = FALSE;
  1167. // enable list controls
  1168. EnableDlgItem(hDlg, IDC_CONN_LIST, fList);
  1169. EnableDlgItem(hDlg, IDC_DIALUP_ADD, fAdd);
  1170. EnableDlgItem(hDlg, IDC_DIALUP_REMOVE, fSettings);
  1171. EnableDlgItem(hDlg, IDC_MODEM_SETTINGS, fSettings);
  1172. // enable lan controls
  1173. EnableDlgItem(hDlg, IDC_LAN_SETTINGS, fLan);
  1174. // enable default controls
  1175. EnableDlgItem(hDlg, IDC_DIALUP_NEVER, fDial);
  1176. EnableDlgItem(hDlg, IDC_DIALUP_ON_NONET, fDial && !fNT4SP3);
  1177. EnableDlgItem(hDlg, IDC_DIALUP, fDial);
  1178. EnableDlgItem(hDlg, IDC_DIAL_DEF_TXT, fDialDefault);
  1179. EnableDlgItem(hDlg, IDC_DIAL_DEF_ISP, fDialDefault);
  1180. EnableDlgItem(hDlg, IDC_ENABLE_SECURITY, fDialDefault);
  1181. EnableDlgItem(hDlg, IDC_SET_DEFAULT, fDialDefault && fSetDefault);
  1182. // if autodialing is disabled (no connectoids) make sure it's not checked
  1183. if(FALSE == fDial)
  1184. CheckRadioButton(hDlg, IDC_DIALUP_NEVER, IDC_DIALUP, IDC_DIALUP_NEVER);
  1185. //
  1186. // Fix connection wizard
  1187. //
  1188. if (g_restrict.fConnectionWizard)
  1189. {
  1190. EnableDlgItem(hDlg, IDC_CONNECTION_WIZARD, FALSE);
  1191. }
  1192. }
  1193. VOID FixAutodialSettings(HWND hDlg, PCONNINFO pConn)
  1194. {
  1195. // Find default connectoid
  1196. DWORD dwSize = RAS_MaxEntryName + 1;
  1197. if(FALSE == InternetQueryOption(NULL, INTERNET_OPTION_AUTODIAL_CONNECTION, pConn->szEntryName, &dwSize))
  1198. {
  1199. *pConn->szEntryName = 0;
  1200. }
  1201. // populate connectoids, will do the right thing with the default read above
  1202. PopulateRasEntries(hDlg, pConn);
  1203. // fix autodial radio buttons
  1204. int iSel;
  1205. DWORD dwAutodial;
  1206. dwSize = sizeof(DWORD);
  1207. if(FALSE == InternetQueryOption(NULL, INTERNET_OPTION_AUTODIAL_MODE, &dwAutodial, &dwSize))
  1208. {
  1209. dwAutodial = AUTODIAL_MODE_NEVER;
  1210. }
  1211. switch(dwAutodial)
  1212. {
  1213. case AUTODIAL_MODE_ALWAYS:
  1214. iSel = IDC_DIALUP;
  1215. break;
  1216. case AUTODIAL_MODE_NO_NETWORK_PRESENT:
  1217. iSel = IDC_DIALUP_ON_NONET;
  1218. break;
  1219. default :
  1220. iSel = IDC_DIALUP_NEVER;
  1221. break;
  1222. } /* switch */
  1223. CheckRadioButton(hDlg, IDC_DIALUP_NEVER, IDC_DIALUP, iSel);
  1224. // enable appropriate controls
  1225. EnableConnectionControls(hDlg, pConn, TRUE);
  1226. }
  1227. BOOL ConnectionDlgInit(HWND hDlg, PCONNINFO pConn)
  1228. {
  1229. BOOL fProxy = FALSE;
  1230. BOOL fDial = FALSE;
  1231. HIMAGELIST himl;
  1232. HICON hIcon;
  1233. // Get platform - we need this as there's no security check on NT.
  1234. OSVERSIONINFOA osvi;
  1235. osvi.dwOSVersionInfoSize = sizeof(osvi);
  1236. GetVersionExA(&osvi);
  1237. if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  1238. {
  1239. g_fWin95 = FALSE;
  1240. if(osvi.dwMajorVersion > 4)
  1241. {
  1242. g_fWin2K = TRUE;
  1243. }
  1244. }
  1245. else
  1246. {
  1247. if(osvi.dwMinorVersion >= 90)
  1248. {
  1249. g_fMillennium = TRUE;
  1250. }
  1251. }
  1252. // load ras (success checked later - see dwRNARefCount in EnableConnectionControls
  1253. LoadRNADll();
  1254. // create image list for tree view
  1255. himl = ImageList_Create(BITMAP_WIDTH, BITMAP_HEIGHT, ILC_COLOR | ILC_MASK, CONN_BITMAPS, 4 );
  1256. hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_LAN));
  1257. ImageList_AddIcon(himl, hIcon);
  1258. hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_PHONE));
  1259. ImageList_AddIcon(himl, hIcon);
  1260. TreeView_SetImageList(GetDlgItem(hDlg, IDC_CONN_LIST), himl, TVSIL_NORMAL);
  1261. // populate and configure autodial settings
  1262. FixAutodialSettings(hDlg, pConn);
  1263. // fix security check
  1264. if(g_fWin95)
  1265. {
  1266. RegEntry re(REGSTR_PATH_INTERNETSETTINGS,HKEY_CURRENT_USER);
  1267. if (re.GetError() == ERROR_SUCCESS)
  1268. {
  1269. if(re.GetNumber(REGSTR_VAL_ENABLESECURITYCHECK,0))
  1270. {
  1271. CheckDlgButton(hDlg, IDC_ENABLE_SECURITY, TRUE);
  1272. }
  1273. }
  1274. }
  1275. else
  1276. {
  1277. // no security check on NT so hide check box
  1278. ShowWindow(GetDlgItem(hDlg, IDC_ENABLE_SECURITY), SW_HIDE);
  1279. }
  1280. if (!IsConnSharingAvail())
  1281. ShowWindow(GetDlgItem(hDlg, IDC_CON_SHARING), SW_HIDE);
  1282. // disable wizard button if for some reason ICW cannot be JITed in
  1283. DWORD dwRes = JitFeature(hDlg, clsidFeatureICW, TRUE);
  1284. if(JIT_NOT_AVAILABLE == dwRes) {
  1285. // can never get ICW so grey button
  1286. EnableWindow(GetDlgItem(hDlg, IDC_CONNECTION_WIZARD), FALSE);
  1287. }
  1288. return TRUE;
  1289. }
  1290. ///////////////////////////////////////////////////////////////////////////
  1291. //
  1292. // NAME: LoadRNADll
  1293. //
  1294. // SYNOPSIS: Loads RNA dll if not already loaded and obtains pointers
  1295. // for function addresses.
  1296. //
  1297. // NOTES: Maintains a reference count so we know when to unload
  1298. //
  1299. ///////////////////////////////////////////////////////////////////////////
  1300. BOOL LoadRNADll(VOID)
  1301. {
  1302. // increase reference count
  1303. dwRNARefCount++;
  1304. if (hInstRNADll)
  1305. {
  1306. // already loaded, nothing to do
  1307. return TRUE;
  1308. }
  1309. // Ask wininet if Ras is installed. Always make this call even if ras
  1310. // dll doesn't load since it also forces wininet to migrate proxy
  1311. // settings if necessary.
  1312. DWORD dwFlags;
  1313. InternetGetConnectedStateExA(&dwFlags, NULL, 0, 0);
  1314. if(0 == (dwFlags & INTERNET_RAS_INSTALLED)) {
  1315. // not installed - none of the functions will work so bail
  1316. dwRNARefCount--;
  1317. return FALSE;
  1318. }
  1319. // get the file name from resource
  1320. TCHAR szDllFilename[SMALL_BUF_LEN+1];
  1321. if (!MLLoadString(IDS_RNADLL_FILENAME,szDllFilename,ARRAYSIZE(szDllFilename))) {
  1322. dwRNARefCount--;
  1323. return FALSE;
  1324. }
  1325. // load the DLL
  1326. hInstRNADll = LoadLibrary(szDllFilename);
  1327. if (!hInstRNADll) {
  1328. dwRNARefCount--;
  1329. return FALSE;
  1330. }
  1331. // cycle through the API table and get proc addresses for all the APIs we
  1332. // need
  1333. UINT nIndex;
  1334. for (nIndex = 0;nIndex < NUM_RNAAPI_PROCS;nIndex++)
  1335. {
  1336. if (!(*RasApiList[nIndex].ppFcnPtr = (PVOID) GetProcAddress(hInstRNADll,
  1337. RasApiList[nIndex].pszName)))
  1338. {
  1339. // no longer fatal - no RasDeleteEntry on Win95 gold.
  1340. TraceMsg(TF_GENERAL, "Unable to get address of function %s", RasApiList[nIndex].pszName);
  1341. // UnloadRNADll();
  1342. // return FALSE;
  1343. }
  1344. }
  1345. if(g_fWin95)
  1346. {
  1347. // make sure we don't use any W versions that may be around on Win9x.
  1348. // They'll almost certainly be stubs.
  1349. lpRasEditPhonebookEntryW = NULL;
  1350. lpRasEnumEntriesW = NULL;
  1351. lpRasDeleteEntryW = NULL;
  1352. lpRasGetEntryDialParamsW = NULL;
  1353. lpRasSetEntryDialParamsW = NULL;
  1354. lpRasGetEntryPropertiesW = NULL;
  1355. }
  1356. return TRUE;
  1357. }
  1358. /////////////////////////////////////////////////////////////////////////////
  1359. //
  1360. // NAME: UnloadRNADll
  1361. //
  1362. // SYNOPSIS: Decrements RNA dll reference count and unloads it if
  1363. // zero
  1364. //
  1365. /////////////////////////////////////////////////////////////////////////////
  1366. VOID UnloadRNADll(VOID)
  1367. {
  1368. // decrease reference count
  1369. if (dwRNARefCount)
  1370. dwRNARefCount --;
  1371. // unload DLL if reference count hits zero
  1372. if (!dwRNARefCount && hInstRNADll)
  1373. {
  1374. // set function pointers to NULL
  1375. UINT nIndex;
  1376. for (nIndex = 0;nIndex < NUM_RNAAPI_PROCS;nIndex++)
  1377. *RasApiList[nIndex].ppFcnPtr = NULL;
  1378. // free the library
  1379. FreeLibrary(hInstRNADll);
  1380. hInstRNADll = NULL;
  1381. }
  1382. }
  1383. /////////////////////////////////////////////////////////////////////////////
  1384. /////////////////////////////////////////////////////////////////////////////
  1385. //
  1386. // Dialup Dialog ie modem settings
  1387. //
  1388. /////////////////////////////////////////////////////////////////////////////
  1389. /////////////////////////////////////////////////////////////////////////////
  1390. #define W2KRASENTRYW struct tagW2KRASENTRYW
  1391. W2KRASENTRYW
  1392. {
  1393. DWORD dwSize;
  1394. DWORD dwfOptions;
  1395. DWORD dwCountryID;
  1396. DWORD dwCountryCode;
  1397. WCHAR szAreaCode[ RAS_MaxAreaCode + 1 ];
  1398. WCHAR szLocalPhoneNumber[ RAS_MaxPhoneNumber + 1 ];
  1399. DWORD dwAlternateOffset;
  1400. RASIPADDR ipaddr;
  1401. RASIPADDR ipaddrDns;
  1402. RASIPADDR ipaddrDnsAlt;
  1403. RASIPADDR ipaddrWins;
  1404. RASIPADDR ipaddrWinsAlt;
  1405. DWORD dwFrameSize;
  1406. DWORD dwfNetProtocols;
  1407. DWORD dwFramingProtocol;
  1408. WCHAR szScript[ MAX_PATH ];
  1409. WCHAR szAutodialDll[ MAX_PATH ];
  1410. WCHAR szAutodialFunc[ MAX_PATH ];
  1411. WCHAR szDeviceType[ RAS_MaxDeviceType + 1 ];
  1412. WCHAR szDeviceName[ RAS_MaxDeviceName + 1 ];
  1413. WCHAR szX25PadType[ RAS_MaxPadType + 1 ];
  1414. WCHAR szX25Address[ RAS_MaxX25Address + 1 ];
  1415. WCHAR szX25Facilities[ RAS_MaxFacilities + 1 ];
  1416. WCHAR szX25UserData[ RAS_MaxUserData + 1 ];
  1417. DWORD dwChannels;
  1418. DWORD dwReserved1;
  1419. DWORD dwReserved2;
  1420. DWORD dwSubEntries;
  1421. DWORD dwDialMode;
  1422. DWORD dwDialExtraPercent;
  1423. DWORD dwDialExtraSampleSeconds;
  1424. DWORD dwHangUpExtraPercent;
  1425. DWORD dwHangUpExtraSampleSeconds;
  1426. DWORD dwIdleDisconnectSeconds;
  1427. DWORD dwType;
  1428. DWORD dwEncryptionType;
  1429. DWORD dwCustomAuthKey;
  1430. GUID guidId;
  1431. WCHAR szCustomDialDll[MAX_PATH];
  1432. DWORD dwVpnStrategy;
  1433. };
  1434. BOOL GetConnectoidInfo(HWND hDlg, LPTSTR pszEntryName)
  1435. {
  1436. BOOL fPassword = FALSE;
  1437. if(g_fWin2K && lpRasGetEntryPropertiesW)
  1438. {
  1439. W2KRASENTRYW re[2];
  1440. DWORD dwSize;
  1441. // get props for this connectoid and see if it has a custom dial dll
  1442. re[0].dwSize = sizeof(W2KRASENTRYW);
  1443. dwSize = sizeof(re);
  1444. if(ERROR_SUCCESS == (lpRasGetEntryPropertiesW)(NULL, pszEntryName,
  1445. (LPRASENTRYW)re, &dwSize, NULL, NULL))
  1446. {
  1447. if(0 != re[0].szCustomDialDll[0])
  1448. {
  1449. // Win2K handler exists - flag that we need to grey out
  1450. // credential fields
  1451. return TRUE;
  1452. }
  1453. }
  1454. }
  1455. else
  1456. {
  1457. // on down level platforms, check registry for cdh
  1458. TCHAR szTemp[MAX_PATH];
  1459. GetConnKey(pszEntryName, szTemp, MAX_PATH);
  1460. RegEntry re(szTemp, HKEY_CURRENT_USER);
  1461. if(ERROR_SUCCESS == re.GetError())
  1462. {
  1463. if(re.GetString(REGSTR_VAL_AUTODIALDLLNAME, szTemp, MAX_PATH) && *szTemp)
  1464. {
  1465. // CDH exists - flag that we need to grey credentials
  1466. return TRUE;
  1467. }
  1468. }
  1469. }
  1470. if(lpRasGetEntryDialParamsW)
  1471. {
  1472. RASDIALPARAMSW params;
  1473. WCHAR *pszUser = L"", *pszPassword = L"", *pszDomain = L"";
  1474. memset(&params, 0, sizeof(params));
  1475. params.dwSize = sizeof(params);
  1476. StrCpyN(params.szEntryName, pszEntryName, RAS_MaxEntryName);
  1477. if(ERROR_SUCCESS == (lpRasGetEntryDialParamsW)(NULL, (LPRASDIALPARAMSW)&params, &fPassword))
  1478. {
  1479. pszUser = params.szUserName;
  1480. if(' ' != params.szDomain[0] || IsNTSPx(TRUE, 4, 6)) // NT4SP6 or greater?
  1481. pszDomain = params.szDomain;
  1482. if(fPassword)
  1483. pszPassword = params.szPassword;
  1484. }
  1485. SetWindowText(GetDlgItem(hDlg, IDC_USER), pszUser);
  1486. SetWindowText(GetDlgItem(hDlg, IDC_DOMAIN), pszDomain);
  1487. SetWindowText(GetDlgItem(hDlg, IDC_PASSWORD), pszPassword);
  1488. }
  1489. else if(lpRasGetEntryDialParamsA)
  1490. {
  1491. RASDIALPARAMSA params;
  1492. CHAR *pszUser = "", *pszPassword = "", *pszDomain = "";
  1493. memset(&params, 0, sizeof(params));
  1494. params.dwSize = sizeof(params);
  1495. SHUnicodeToAnsi(pszEntryName, params.szEntryName, ARRAYSIZE(params.szEntryName));
  1496. if(ERROR_SUCCESS == (lpRasGetEntryDialParamsA)(NULL, &params, &fPassword))
  1497. {
  1498. pszUser = params.szUserName;
  1499. if(' ' != params.szDomain[0] || IsNTSPx(TRUE, 4, 6)) // NT4SP6 or greater?
  1500. pszDomain = params.szDomain;
  1501. if(fPassword)
  1502. pszPassword = params.szPassword;
  1503. }
  1504. SetWindowTextA(GetDlgItem(hDlg, IDC_USER), pszUser);
  1505. SetWindowTextA(GetDlgItem(hDlg, IDC_DOMAIN), pszDomain);
  1506. SetWindowTextA(GetDlgItem(hDlg, IDC_PASSWORD), pszPassword);
  1507. }
  1508. return FALSE;
  1509. }
  1510. #ifndef WS_EX_LAYOUTRTL
  1511. #define WS_EX_LAYOUTRTL 0x00400000L // Right to left mirroring
  1512. #else
  1513. #error "WS_EX_LAYOUTRTL is already defined in winuser.h"
  1514. #endif // WS_EX_LAYOUTRTL
  1515. ///////////////////////////////////////////////////////////////////
  1516. //
  1517. // NAME: FixDialogForLan
  1518. //
  1519. // SYNOPSIS: Remove dialing section of dialog box
  1520. //
  1521. ///////////////////////////////////////////////////////////////////
  1522. void FixDialogForLan(HWND hDlg)
  1523. {
  1524. RECT rectParent, rectDial, rectNet, rectCur;
  1525. POINT pt;
  1526. int i;
  1527. static int iHideIDs[] = {
  1528. IDC_GRP_DIAL, IDC_RAS_SETTINGS, IDC_TX_USER, IDC_USER, IDC_TX_PASSWORD,
  1529. IDC_PASSWORD, IDC_TX_DOMAIN, IDC_DOMAIN, IDC_DIAL_ADVANCED,
  1530. IDC_DONT_USE_CONNECTION
  1531. };
  1532. #define NUM_HIDE (sizeof(iHideIDs) / sizeof(int))
  1533. static int iMoveIDs[] = {
  1534. IDCANCEL, IDOK
  1535. };
  1536. #define NUM_MOVE (sizeof(iMoveIDs) / sizeof(int))
  1537. // hide relevant windows
  1538. for(i=0; i<NUM_HIDE; i++) {
  1539. ShowWindow(GetDlgItem(hDlg, iHideIDs[i]), SW_HIDE);
  1540. }
  1541. // move relevant windows (yuck)
  1542. GetWindowRect(hDlg, &rectParent);
  1543. GetWindowRect(GetDlgItem(hDlg, IDC_GRP_DIAL), &rectDial);
  1544. GetWindowRect(GetDlgItem(hDlg, IDC_GRP_PROXY), &rectNet);
  1545. for(i=0; i<NUM_MOVE; i++) {
  1546. GetWindowRect(GetDlgItem(hDlg, iMoveIDs[i]), &rectCur);
  1547. pt.x = (GetWindowLong(hDlg, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) ? rectCur.right : rectCur.left;
  1548. pt.y = rectCur.top;
  1549. ScreenToClient(hDlg, &pt);
  1550. MoveWindow(GetDlgItem(hDlg, iMoveIDs[i]), pt.x,
  1551. pt.y - (rectDial.bottom - rectNet.bottom),
  1552. rectCur.right - rectCur.left,
  1553. rectCur.bottom - rectCur.top,
  1554. TRUE);
  1555. }
  1556. // adjust dialog box size
  1557. MoveWindow(hDlg, rectParent.left, rectParent.top,
  1558. rectParent.right - rectParent.left,
  1559. rectParent.bottom - rectParent.top - (rectDial.bottom - rectNet.bottom),
  1560. TRUE);
  1561. }
  1562. ///////////////////////////////////////////////////////////////////
  1563. //
  1564. // NAME: DialupDlgInit
  1565. //
  1566. // SYNOPSIS: Does initalization for dialup dialog
  1567. //
  1568. ////////////////////////////////////////////////////////////////////
  1569. BOOL DialupDlgInit(HWND hDlg, LPTSTR pszConnectoid)
  1570. {
  1571. PDIALINFO pDI;
  1572. TCHAR szTemp[MAX_PATH], szSettings[64];
  1573. DWORD dwIEAK = 0, cb;
  1574. // set up dailinfo struct
  1575. pDI = new DIALINFO;
  1576. if(NULL == pDI)
  1577. return FALSE;
  1578. memset(pDI, 0, sizeof(DIALINFO)); // new already zero init?
  1579. #ifndef UNIX
  1580. pDI->pszConnectoid = pszConnectoid;
  1581. #else
  1582. // Can't pass lparam from PSheet because we put dialup dialog directly
  1583. // on the tab.
  1584. pszConnectoid = TEXT("");
  1585. pDI->pszConnectoid = pDI->szEntryName;
  1586. #endif
  1587. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pDI);
  1588. // Fix window title
  1589. if(0 == *(pDI->pszConnectoid)) {
  1590. if (MLLoadString(IDS_LAN_SETTINGSPROXY, szTemp, MAX_PATH))
  1591. {
  1592. SetDlgItemText(hDlg, IDC_MANUAL, szTemp);
  1593. }
  1594. MLLoadString(IDS_LAN_SETTINGS, szTemp, MAX_PATH);
  1595. } else {
  1596. MLLoadString(IDS_SETTINGS, szSettings, 64);
  1597. wnsprintf(szTemp, ARRAYSIZE(szTemp), TEXT("%s %s"), pDI->pszConnectoid, szSettings);
  1598. }
  1599. SetWindowText(hDlg, szTemp);
  1600. #ifndef UNIX
  1601. // Different stuff if we're editing a connectoid vs. lan settings
  1602. if(NULL == pszConnectoid || 0 == *pszConnectoid) {
  1603. // remove dialing goo from dialog
  1604. FixDialogForLan(hDlg);
  1605. } else {
  1606. // fill in username/password/domain
  1607. pDI->proxy.fCustomHandler = GetConnectoidInfo(hDlg, pszConnectoid);
  1608. }
  1609. #endif
  1610. // hide advanced button for autoconfig info if IEAK restriction is not set
  1611. cb = sizeof(dwIEAK);
  1612. if ((SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_INETCPL_RESTRICTIONS, REGSTR_VAL_INETCPL_IEAK,
  1613. NULL, (LPVOID)&dwIEAK, &cb) != ERROR_SUCCESS) || !dwIEAK)
  1614. ShowWindow(GetDlgItem(hDlg, IDC_AUTOCNFG_ADVANCED), SW_HIDE);
  1615. // hide advanced button on millennium
  1616. if(g_fMillennium)
  1617. {
  1618. ShowWindow(GetDlgItem(hDlg, IDC_DIAL_ADVANCED), SW_HIDE);
  1619. EnableWindow(GetDlgItem(hDlg, IDC_DIAL_ADVANCED), FALSE);
  1620. }
  1621. //
  1622. // Read proxy and autoconfig settings for this connection
  1623. //
  1624. INTERNET_PER_CONN_OPTION_LIST list;
  1625. DWORD dwBufSize = sizeof(list);
  1626. list.pszConnection = (pszConnectoid && *pszConnectoid) ? pszConnectoid : NULL;
  1627. list.dwSize = sizeof(list);
  1628. list.dwOptionCount = 4;
  1629. list.pOptions = new INTERNET_PER_CONN_OPTION[4];
  1630. if(NULL == list.pOptions)
  1631. {
  1632. return FALSE;
  1633. }
  1634. list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  1635. list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  1636. list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  1637. list.pOptions[3].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
  1638. if(FALSE == InternetQueryOption(NULL,
  1639. INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize))
  1640. {
  1641. delete [] list.pOptions;
  1642. return FALSE;
  1643. }
  1644. //
  1645. // move options to pDI struct
  1646. //
  1647. pDI->proxy.fEnable = (list.pOptions[0].Value.dwValue & PROXY_TYPE_PROXY);
  1648. if(list.pOptions[1].Value.pszValue)
  1649. {
  1650. StrCpyN(pDI->proxy.szProxy, list.pOptions[1].Value.pszValue, MAX_URL_STRING);
  1651. GlobalFree(list.pOptions[1].Value.pszValue);
  1652. list.pOptions[1].Value.pszValue = NULL;
  1653. }
  1654. if(list.pOptions[2].Value.pszValue)
  1655. {
  1656. StrCpyN(pDI->proxy.szOverride, list.pOptions[2].Value.pszValue, MAX_URL_STRING);
  1657. GlobalFree(list.pOptions[2].Value.pszValue);
  1658. list.pOptions[2].Value.pszValue = NULL;
  1659. }
  1660. //
  1661. // fill in dialog fields
  1662. //
  1663. // proxy enable
  1664. if(pDI->proxy.fEnable)
  1665. {
  1666. CheckDlgButton(hDlg, IDC_MANUAL, TRUE);
  1667. }
  1668. // autoconfig enable and url
  1669. if(list.pOptions[0].Value.dwValue & PROXY_TYPE_AUTO_PROXY_URL)
  1670. {
  1671. CheckDlgButton(hDlg, IDC_CONFIGSCRIPT, TRUE);
  1672. }
  1673. if(list.pOptions[3].Value.pszValue)
  1674. {
  1675. SetWindowText(GetDlgItem(hDlg, IDC_CONFIG_ADDR), list.pOptions[3].Value.pszValue);
  1676. GlobalFree(list.pOptions[3].Value.pszValue);
  1677. list.pOptions[3].Value.pszValue = NULL;
  1678. }
  1679. // autodiscovery enable
  1680. if(list.pOptions[0].Value.dwValue & PROXY_TYPE_AUTO_DETECT)
  1681. {
  1682. CheckDlgButton(hDlg, IDC_AUTODISCOVER, TRUE);
  1683. }
  1684. // all done with options list
  1685. delete [] list.pOptions;
  1686. // check enable and override and parse out server and port
  1687. pDI->proxy.fOverrideLocal = RemoveLocalFromExceptionList(pDI->proxy.szOverride);
  1688. CheckDlgButton(hDlg, IDC_PROXY_ENABLE, pDI->proxy.fEnable);
  1689. CheckDlgButton(hDlg, IDC_PROXY_OMIT_LOCAL_ADDRESSES, pDI->proxy.fOverrideLocal);
  1690. PopulateProxyControls(hDlg, &pDI->proxy, TRUE);
  1691. return TRUE;
  1692. }
  1693. ///////////////////////////////////////////////////////////////////
  1694. //
  1695. // NAME: DialupDlgOk
  1696. //
  1697. // SYNOPSIS: Apply settings for dial up dialog box
  1698. //
  1699. ////////////////////////////////////////////////////////////////////
  1700. BOOL DialupDlgOk(HWND hDlg, PDIALINFO pDI)
  1701. {
  1702. DWORD dwValue = 0;
  1703. //
  1704. // Save proxy settings
  1705. //
  1706. INTERNET_PER_CONN_OPTION_LIST list;
  1707. DWORD dwBufSize = sizeof(list);
  1708. DWORD dwOptions = 2; // always save FLAGS & DISCOVERY_FLAGS
  1709. TCHAR szAutoConfig[MAX_URL_STRING];
  1710. list.pszConnection = (pDI->pszConnectoid && *pDI->pszConnectoid) ? pDI->pszConnectoid : NULL;
  1711. list.dwSize = sizeof(list);
  1712. list.dwOptionCount = 1;
  1713. list.pOptions = new INTERNET_PER_CONN_OPTION[5];
  1714. if(NULL == list.pOptions)
  1715. {
  1716. return FALSE;
  1717. }
  1718. list.pOptions[0].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
  1719. //
  1720. // Query autodiscover flags - we just need to set one bit in there
  1721. //
  1722. if(FALSE == InternetQueryOption(NULL,
  1723. INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize))
  1724. {
  1725. delete [] list.pOptions;
  1726. return FALSE;
  1727. }
  1728. //
  1729. // save off all other options
  1730. //
  1731. list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
  1732. list.pOptions[1].Value.dwValue = PROXY_TYPE_DIRECT;
  1733. //
  1734. // save proxy settings
  1735. //
  1736. GetProxyInfo(hDlg, pDI);
  1737. if(pDI->proxy.fEnable)
  1738. {
  1739. list.pOptions[1].Value.dwValue |= PROXY_TYPE_PROXY;
  1740. }
  1741. list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  1742. list.pOptions[2].Value.pszValue = pDI->proxy.szProxy;
  1743. list.pOptions[3].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  1744. list.pOptions[3].Value.pszValue = pDI->proxy.szOverride;
  1745. dwOptions += 2;
  1746. //
  1747. // save autodetect
  1748. //
  1749. if(IsDlgButtonChecked(hDlg, IDC_AUTODISCOVER))
  1750. {
  1751. list.pOptions[1].Value.dwValue |= PROXY_TYPE_AUTO_DETECT;
  1752. if(pDI->fClickedAutodetect)
  1753. {
  1754. list.pOptions[0].Value.dwValue |= AUTO_PROXY_FLAG_USER_SET;
  1755. }
  1756. }
  1757. else
  1758. {
  1759. list.pOptions[0].Value.dwValue &= ~AUTO_PROXY_FLAG_DETECTION_RUN;
  1760. }
  1761. //
  1762. // save autoconfig
  1763. //
  1764. if(IsDlgButtonChecked(hDlg, IDC_CONFIGSCRIPT) &&
  1765. GetWindowText(GetDlgItem(hDlg, IDC_CONFIG_ADDR), szAutoConfig, MAX_URL_STRING))
  1766. {
  1767. list.pOptions[1].Value.dwValue |= PROXY_TYPE_AUTO_PROXY_URL;
  1768. list.pOptions[dwOptions].Value.pszValue = szAutoConfig;
  1769. list.pOptions[dwOptions].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
  1770. dwOptions++;
  1771. }
  1772. // update wininet
  1773. list.dwOptionCount = dwOptions;
  1774. InternetSetOption(NULL,
  1775. INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
  1776. // tell wininet that the proxy info has changed
  1777. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  1778. // all done with options list
  1779. delete [] list.pOptions;
  1780. // all done if we're editing lan settings
  1781. if(NULL == pDI->pszConnectoid || 0 == *pDI->pszConnectoid)
  1782. return TRUE;
  1783. // no credentials to store if we have a w2k custom handler
  1784. if(pDI->proxy.fCustomHandler)
  1785. {
  1786. return TRUE;
  1787. }
  1788. //
  1789. // save connectoid information - use wide version if possible
  1790. //
  1791. BOOL fDeletePassword = FALSE;
  1792. if(lpRasSetEntryDialParamsW)
  1793. {
  1794. RASDIALPARAMSW params;
  1795. memset(&params, 0, sizeof(RASDIALPARAMSW));
  1796. params.dwSize = sizeof(RASDIALPARAMSW);
  1797. StrCpyN(params.szEntryName, pDI->pszConnectoid, RAS_MaxEntryName+1);
  1798. GetWindowText(GetDlgItem(hDlg, IDC_USER), params.szUserName, UNLEN);
  1799. GetWindowText(GetDlgItem(hDlg, IDC_PASSWORD), params.szPassword, PWLEN);
  1800. if(0 == params.szPassword[0])
  1801. fDeletePassword = TRUE;
  1802. GetWindowText(GetDlgItem(hDlg, IDC_DOMAIN), params.szDomain, DNLEN);
  1803. if(0 == params.szDomain[0] && !IsNTSPx(TRUE, 4, 6)) { // NT4SP6 or greater?
  1804. // user wants empty domain
  1805. params.szDomain[0] = TEXT(' ');
  1806. }
  1807. (lpRasSetEntryDialParamsW)(NULL, &params, fDeletePassword);
  1808. }
  1809. else if(lpRasSetEntryDialParamsA)
  1810. {
  1811. RASDIALPARAMSA params;
  1812. memset(&params, 0, sizeof(RASDIALPARAMSA));
  1813. params.dwSize = sizeof(RASDIALPARAMSA);
  1814. SHUnicodeToAnsi(pDI->pszConnectoid, params.szEntryName, ARRAYSIZE(params.szEntryName));
  1815. GetWindowTextA(GetDlgItem(hDlg, IDC_USER), params.szUserName, UNLEN);
  1816. GetWindowTextA(GetDlgItem(hDlg, IDC_PASSWORD), params.szPassword, PWLEN);
  1817. if(0 == params.szPassword[0])
  1818. fDeletePassword = TRUE;
  1819. GetWindowTextA(GetDlgItem(hDlg, IDC_DOMAIN), params.szDomain, DNLEN);
  1820. if(0 == params.szDomain[0] && !IsNTSPx(TRUE, 4, 6)) { // NT4SP6 or greater?
  1821. // user wants empty domain
  1822. params.szDomain[0] = TEXT(' ');
  1823. }
  1824. (lpRasSetEntryDialParamsA)(NULL, &params, fDeletePassword);
  1825. }
  1826. return TRUE;
  1827. }
  1828. ///////////////////////////////////////////////////////////////////
  1829. //
  1830. // NAME: DialupDlgProc
  1831. //
  1832. // SYNOPSIS: Dialog proc for dial up dialog
  1833. //
  1834. ////////////////////////////////////////////////////////////////////
  1835. INT_PTR CALLBACK DialupDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
  1836. {
  1837. PDIALINFO pDI = (PDIALINFO)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  1838. switch (uMsg) {
  1839. case WM_INITDIALOG:
  1840. ASSERT(lParam);
  1841. DialupDlgInit(hDlg, (LPTSTR)lParam);
  1842. return FALSE;
  1843. case WM_DESTROY:
  1844. delete pDI;
  1845. break;
  1846. case WM_COMMAND:
  1847. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1848. case IDC_AUTODISCOVER:
  1849. pDI->fClickedAutodetect = TRUE;
  1850. break;
  1851. case IDC_AUTOCNFG_ADVANCED:
  1852. if(GET_WM_COMMAND_CMD(wParam, lParam) != BN_CLICKED)
  1853. break;
  1854. // show advanced dialog box
  1855. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_AUTOCNFG_SETTINGS), hDlg,
  1856. AdvAutocnfgDlgProc, (LPARAM) pDI->pszConnectoid);
  1857. break;
  1858. case IDC_PROXY_ADVANCED:
  1859. if(GET_WM_COMMAND_CMD(wParam, lParam) != BN_CLICKED)
  1860. break;
  1861. GetProxyInfo(hDlg, pDI);
  1862. // remove local so it doesn't show up in advanced dialog
  1863. RemoveLocalFromExceptionList(pDI->proxy.szOverride);
  1864. // show advanced dialog box
  1865. if (DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_PROXY_SETTINGS), hDlg,
  1866. ProxyDlgProc, (LPARAM) &pDI->proxy) == IDOK)
  1867. {
  1868. if(FALSE == pDI->proxy.fEnable)
  1869. {
  1870. // user disabled proxy in advanced dialog
  1871. CheckDlgButton(hDlg, IDC_MANUAL, FALSE);
  1872. }
  1873. PopulateProxyControls(hDlg, &pDI->proxy, TRUE);
  1874. }
  1875. break;
  1876. case IDC_RAS_SETTINGS:
  1877. if (g_fWin95) //jeffsi
  1878. {
  1879. if(lpRasEditPhonebookEntryW)
  1880. {
  1881. (lpRasEditPhonebookEntryW)(hDlg, NULL, pDI->pszConnectoid);
  1882. }
  1883. else if(lpRasEditPhonebookEntryA)
  1884. {
  1885. CHAR szConnectoid[MAX_PATH];
  1886. SHUnicodeToAnsi(pDI->pszConnectoid, szConnectoid, ARRAYSIZE(szConnectoid));
  1887. (lpRasEditPhonebookEntryA)(hDlg, NULL, szConnectoid);
  1888. }
  1889. }
  1890. else
  1891. {
  1892. PFRED pfred = NULL;
  1893. HMODULE hRasDlg = LoadLibrary(TEXT("rasdlg.dll"));
  1894. RASENTRYDLG info;
  1895. if (!hRasDlg)
  1896. {
  1897. break;
  1898. }
  1899. #ifdef UNICODE
  1900. pfred = (PFRED)GetProcAddress(hRasDlg, "RasEntryDlgW");
  1901. #else
  1902. pfred = (PFRED)GetProcAddress(hRasDlg, "RasEntryDlgA");
  1903. #endif
  1904. if (!pfred)
  1905. {
  1906. FreeLibrary(hRasDlg);
  1907. break;
  1908. }
  1909. memset(&info, 0, sizeof(RASENTRYDLG));
  1910. info.dwSize = sizeof(RASENTRYDLG);
  1911. info.hwndOwner = hDlg;
  1912. #ifdef UNICODE
  1913. (pfred)(NULL, pDI->pszConnectoid, &info);
  1914. #else
  1915. CHAR szConnectoid[MAX_PATH];
  1916. SHUnicodeToAnsi(pDI->pszConnectoid, szConnectoid, ARRAYSIZE(szConnectoid));
  1917. (pfred)(NULL, szConnectoid, &info);
  1918. #endif
  1919. FreeLibrary(hRasDlg);
  1920. }
  1921. break;
  1922. case IDC_DIAL_ADVANCED:
  1923. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_DIALUP_ADVANCED), hDlg,
  1924. AdvDialupDlgProc, (LPARAM) pDI->pszConnectoid);
  1925. break;
  1926. case IDC_MANUAL:
  1927. if(IsDlgButtonChecked(hDlg, IDC_MANUAL))
  1928. {
  1929. pDI->proxy.fEnable = TRUE;
  1930. SetFocus(GetDlgItem(hDlg, IDC_PROXY_ADDR));
  1931. SendMessage(GetDlgItem(hDlg, IDC_PROXY_ADDR), EM_SETSEL, 0, -1);
  1932. }
  1933. else
  1934. {
  1935. pDI->proxy.fEnable = FALSE;
  1936. }
  1937. PopulateProxyControls(hDlg, &pDI->proxy, FALSE);
  1938. #ifdef UNIX
  1939. ENABLEAPPLY(hDlg);
  1940. #endif
  1941. break;
  1942. case IDC_CONFIGSCRIPT:
  1943. if(IsDlgButtonChecked(hDlg, IDC_CONFIGSCRIPT))
  1944. {
  1945. // set focus to config script url
  1946. SetFocus(GetDlgItem(hDlg, IDC_CONFIG_ADDR));
  1947. SendMessage(GetDlgItem(hDlg, IDC_CONFIG_ADDR), EM_SETSEL, 0, -1);
  1948. }
  1949. PopulateProxyControls(hDlg, &pDI->proxy, FALSE);
  1950. #ifdef UNIX
  1951. ENABLEAPPLY(hDlg);
  1952. #endif
  1953. break;
  1954. #ifdef UNIX
  1955. case IDC_AUTODISCOVER:
  1956. case IDC_PROXY_OMIT_LOCAL_ADDRESSES:
  1957. ENABLEAPPLY(hDlg);
  1958. break;
  1959. case IDC_PROXY_PORT:
  1960. case IDC_PROXY_ADDR:
  1961. case IDC_CONFIG_ADDR:
  1962. switch (HIWORD(wParam))
  1963. {
  1964. case EN_CHANGE:
  1965. ENABLEAPPLY(hDlg);
  1966. break;
  1967. }
  1968. break;
  1969. #endif
  1970. case IDC_DONT_USE_CONNECTION:
  1971. PopulateProxyControls(hDlg, &pDI->proxy, FALSE);
  1972. break;
  1973. case IDOK:
  1974. if(FALSE == DialupDlgOk(hDlg, pDI))
  1975. // something is wrong... don't exit yet
  1976. break;
  1977. // fall through
  1978. case IDCANCEL:
  1979. return EndDialog(hDlg, 0);
  1980. }
  1981. break;
  1982. case WM_HELP: // F1
  1983. ResWinHelp((HWND) ((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1984. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1985. break;
  1986. case WM_CONTEXTMENU: // right mouse click
  1987. ResWinHelp((HWND)wParam, IDS_HELPFILE,
  1988. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1989. break;
  1990. #ifdef UNIX
  1991. case WM_NOTIFY:
  1992. {
  1993. NMHDR * lpnm = (NMHDR *) lParam;
  1994. switch (lpnm->code)
  1995. {
  1996. case PSN_APPLY:
  1997. {
  1998. if(FALSE == DialupDlgOk(hDlg, pDI))
  1999. // something is wrong... don't exit yet
  2000. break;
  2001. // fall through
  2002. }
  2003. }
  2004. }
  2005. #endif
  2006. }
  2007. return FALSE;
  2008. }
  2009. /////////////////////////////////////////////////////////////////////////////
  2010. /////////////////////////////////////////////////////////////////////////////
  2011. //
  2012. // Advanced dial-up settings dialog
  2013. //
  2014. /////////////////////////////////////////////////////////////////////////////
  2015. /////////////////////////////////////////////////////////////////////////////
  2016. ///////////////////////////////////////////////////////////////////
  2017. //
  2018. // NAME: AdvDialupDlgProc
  2019. //
  2020. // SYNOPSIS: Dialog proc for dial up dialog
  2021. //
  2022. ////////////////////////////////////////////////////////////////////
  2023. void EnableAdvDialControls(HWND hDlg)
  2024. {
  2025. BOOL fIdle = IsDlgButtonChecked(hDlg, IDC_ENABLE_AUTODISCONNECT);
  2026. // on if we have idle disconnect...
  2027. EnableDlgItem(hDlg, IDC_IDLE_TIMEOUT, fIdle);
  2028. EnableDlgItem(hDlg, IDC_IDLE_SPIN, fIdle);
  2029. }
  2030. BOOL AdvDialupDlgInit(HWND hDlg, LPTSTR pszConnectoid)
  2031. {
  2032. TCHAR szTemp[MAX_PATH];
  2033. DWORD dwRedialAttempts, dwRedialInterval, dwAutodisconnectTime;
  2034. BOOL fExit, fDisconnect;
  2035. // save connectoid name
  2036. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pszConnectoid);
  2037. // figure out our registry key
  2038. GetConnKey(pszConnectoid, szTemp, MAX_PATH);
  2039. // open connectoid or lan settings
  2040. RegEntry reCon(szTemp, HKEY_CURRENT_USER);
  2041. if(ERROR_SUCCESS != reCon.GetError())
  2042. return FALSE;
  2043. //
  2044. // Read autodial / redial stuff
  2045. //
  2046. // We get this stuff from the connectoid if possible. We assume it's all
  2047. // saved to the connectoid together so if EnableAutodial is present there,
  2048. // read everything from there else read everything from the IE4 settings.
  2049. //
  2050. dwRedialInterval = reCon.GetNumber(REGSTR_VAL_REDIALINTERVAL, DEF_REDIAL_WAIT);
  2051. dwRedialAttempts = reCon.GetNumber(REGSTR_VAL_REDIALATTEMPTS, DEF_REDIAL_TRIES);
  2052. // autodisconnect
  2053. fDisconnect = (BOOL)reCon.GetNumber(REGSTR_VAL_ENABLEAUTODIALDISCONNECT, 0);
  2054. dwAutodisconnectTime = reCon.GetNumber(REGSTR_VAL_DISCONNECTIDLETIME, DEF_AUTODISCONNECT_TIME);
  2055. fExit = (BOOL)reCon.GetNumber(REGSTR_VAL_ENABLEEXITDISCONNECT, 0);
  2056. //
  2057. // Check if the mobile pack is installed and if it is not - then do not have it checked
  2058. //
  2059. DWORD dwRes = JitFeature(hDlg, clsidFeatureMobile, TRUE);
  2060. if(JIT_PRESENT != dwRes)
  2061. {
  2062. fDisconnect = FALSE;
  2063. fExit = FALSE;
  2064. // check to see if offline pack is installed and disable the disconnect
  2065. // options if user has bailed on it
  2066. if(JIT_NOT_AVAILABLE == dwRes) {
  2067. // can't get offline pack so disable options
  2068. CheckDlgButton(hDlg, IDC_ENABLE_AUTODISCONNECT, FALSE);
  2069. CheckDlgButton(hDlg, IDC_EXIT_DISCONNECT, FALSE);
  2070. EnableWindow(GetDlgItem(hDlg, IDC_ENABLE_AUTODISCONNECT), FALSE);
  2071. EnableWindow(GetDlgItem(hDlg, IDC_TX_AUTODISCONNECT), FALSE);
  2072. EnableWindow(GetDlgItem(hDlg, IDC_EXIT_DISCONNECT), FALSE);
  2073. }
  2074. }
  2075. //
  2076. // Populate controls
  2077. //
  2078. CheckDlgButton(hDlg, IDC_ENABLE_AUTODISCONNECT, fDisconnect);
  2079. CheckDlgButton(hDlg, IDC_EXIT_DISCONNECT, fExit);
  2080. SendDlgItemMessage(hDlg, IDC_IDLE_SPIN, UDM_SETPOS, 0, dwAutodisconnectTime);
  2081. SendDlgItemMessage(hDlg, IDC_CONNECT_SPIN,UDM_SETPOS, 0, dwRedialAttempts);
  2082. SendDlgItemMessage(hDlg, IDC_INTERVAL_SPIN,UDM_SETPOS, 0, dwRedialInterval);
  2083. //
  2084. // Set control limits
  2085. //
  2086. Edit_LimitText(GetDlgItem(hDlg,IDC_IDLE_TIMEOUT), 2); // limit edit ctrl to 2 chars
  2087. Edit_LimitText(GetDlgItem(hDlg,IDC_IDLE_SPIN), 2);
  2088. Edit_LimitText(GetDlgItem(hDlg,IDC_CONNECT_SPIN), 2);
  2089. // set spin control min/max
  2090. SendDlgItemMessage(hDlg,IDC_IDLE_SPIN,UDM_SETRANGE,0,
  2091. MAKELPARAM(MAX_AUTODISCONNECT_TIME,MIN_AUTODISCONNECT_TIME));
  2092. SendDlgItemMessage(hDlg,IDC_CONNECT_SPIN,UDM_SETRANGE,0,
  2093. MAKELPARAM(MAX_REDIAL_TRIES,MIN_REDIAL_TRIES));
  2094. SendDlgItemMessage(hDlg,IDC_INTERVAL_SPIN,UDM_SETRANGE,0,
  2095. MAKELPARAM(MAX_REDIAL_WAIT,MIN_REDIAL_WAIT));
  2096. // enable controls
  2097. EnableAdvDialControls(hDlg);
  2098. return TRUE;
  2099. }
  2100. BOOL AdvDialupDlgOk(HWND hDlg, LPTSTR pszConnectoid)
  2101. {
  2102. TCHAR szTemp[MAX_PATH];
  2103. GetConnKey(pszConnectoid, szTemp, MAX_PATH);
  2104. // open connectoid or lan settings
  2105. RegEntry reCon(szTemp, HKEY_CURRENT_USER);
  2106. if(ERROR_SUCCESS != reCon.GetError())
  2107. return FALSE;
  2108. // Save autodisconnect values
  2109. BOOL fExit = IsDlgButtonChecked(hDlg,IDC_EXIT_DISCONNECT);
  2110. BOOL fDisconnect = IsDlgButtonChecked(hDlg,IDC_ENABLE_AUTODISCONNECT);
  2111. if(fExit || fDisconnect) {
  2112. // make sure offline pack is installed or this feature won't work.
  2113. DWORD dwRes = JitFeature(hDlg, clsidFeatureMobile, FALSE);
  2114. if(JIT_PRESENT != dwRes) {
  2115. // user doesn't want to download it so turn off autodisconnect
  2116. fExit = FALSE;
  2117. fDisconnect = FALSE;
  2118. }
  2119. }
  2120. reCon.SetValue(REGSTR_VAL_ENABLEAUTODIALDISCONNECT, (DWORD)fDisconnect);
  2121. reCon.SetValue(REGSTR_VAL_ENABLEEXITDISCONNECT, (DWORD)fExit);
  2122. if(fDisconnect)
  2123. {
  2124. // get autodisconnect time from edit control
  2125. // Sundown: coercion to 32b since values are range checked
  2126. DWORD dwAutoDisconnectTime = (DWORD) SendDlgItemMessage(hDlg, IDC_IDLE_SPIN,
  2127. UDM_GETPOS,0,0);
  2128. if(HIWORD(dwAutoDisconnectTime)) {
  2129. MsgBox(hDlg, IDS_INVALID_AUTODISCONNECT_TIME, 0, MB_OK);
  2130. // decide if it's too big or too small and fix it appropriately
  2131. if(GetDlgItemInt(hDlg, IDC_IDLE_TIMEOUT, NULL, FALSE) < MIN_AUTODISCONNECT_TIME)
  2132. dwAutoDisconnectTime = MIN_AUTODISCONNECT_TIME;
  2133. else
  2134. dwAutoDisconnectTime = MAX_AUTODISCONNECT_TIME;
  2135. SendDlgItemMessage(hDlg, IDC_IDLE_SPIN, UDM_SETPOS, 0, dwAutoDisconnectTime);
  2136. SetFocus(GetDlgItem(hDlg, IDC_IDLE_TIMEOUT));
  2137. return FALSE;
  2138. }
  2139. // save it to registry
  2140. reCon.SetValue(REGSTR_VAL_DISCONNECTIDLETIME, dwAutoDisconnectTime);
  2141. // also save this value to MSN autodisconnect value, to
  2142. // avoid confusion. At some point in the future we'll
  2143. // combine our UI...
  2144. RegEntry reMSN(REGSTR_PATH_MOSDISCONNECT,HKEY_CURRENT_USER);
  2145. if (reMSN.GetError() == ERROR_SUCCESS)
  2146. {
  2147. reMSN.SetValue(REGSTR_VAL_MOSDISCONNECT,dwAutoDisconnectTime);
  2148. }
  2149. }
  2150. // save redial info
  2151. DWORD_PTR dwRedialTry = SendDlgItemMessage(hDlg, IDC_CONNECT_SPIN, UDM_GETPOS, 0, 0);
  2152. DWORD_PTR dwRedialWait = SendDlgItemMessage(hDlg, IDC_INTERVAL_SPIN, UDM_GETPOS, 0, 0);
  2153. if(HIWORD(dwRedialTry)) {
  2154. MsgBox(hDlg, IDS_INVALID_REDIAL_ATTEMPTS, 0, MB_OK);
  2155. if(GetDlgItemInt(hDlg, IDC_CONNECT, NULL, FALSE) < MIN_REDIAL_TRIES)
  2156. dwRedialTry = MIN_REDIAL_TRIES;
  2157. else
  2158. dwRedialTry = MAX_REDIAL_TRIES;
  2159. SendDlgItemMessage(hDlg, IDC_CONNECT_SPIN, UDM_SETPOS, 0, dwRedialTry);
  2160. SetFocus(GetDlgItem(hDlg, IDC_CONNECT));
  2161. return FALSE;
  2162. }
  2163. if(HIWORD(dwRedialWait)) {
  2164. MsgBox(hDlg, IDS_INVALID_REDIAL_WAIT, 0, MB_OK);
  2165. if(GetDlgItemInt(hDlg, IDC_INTERVAL, NULL, FALSE) < MIN_REDIAL_WAIT)
  2166. dwRedialWait = MIN_REDIAL_WAIT;
  2167. else
  2168. dwRedialWait = MAX_REDIAL_WAIT;
  2169. SendDlgItemMessage(hDlg, IDC_INTERVAL_SPIN, UDM_SETPOS, 0, dwRedialWait);
  2170. SetFocus(GetDlgItem(hDlg, IDC_INTERVAL));
  2171. return FALSE;
  2172. }
  2173. reCon.SetValue(REGSTR_VAL_REDIALATTEMPTS, (DWORD) dwRedialTry);
  2174. reCon.SetValue(REGSTR_VAL_REDIALINTERVAL, (DWORD) dwRedialWait);
  2175. return TRUE;
  2176. }
  2177. INT_PTR CALLBACK AdvDialupDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
  2178. {
  2179. LPTSTR pszConn = (LPTSTR) GetWindowLongPtr(hDlg, GWLP_USERDATA);
  2180. switch (uMsg) {
  2181. case WM_INITDIALOG:
  2182. ASSERT(lParam);
  2183. AdvDialupDlgInit(hDlg, (LPTSTR)lParam);
  2184. return FALSE;
  2185. case WM_COMMAND:
  2186. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2187. case IDC_ENABLE_AUTODISCONNECT:
  2188. EnableAdvDialControls(hDlg);
  2189. break;
  2190. case IDOK:
  2191. if(FALSE == AdvDialupDlgOk(hDlg, pszConn))
  2192. // something is wrong... don't exit yet
  2193. break;
  2194. // fall through
  2195. case IDCANCEL:
  2196. return EndDialog(hDlg, 0);
  2197. }
  2198. break;
  2199. case WM_HELP: // F1
  2200. ResWinHelp((HWND) ((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  2201. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2202. break;
  2203. case WM_CONTEXTMENU: // right mouse click
  2204. ResWinHelp((HWND)wParam, IDS_HELPFILE,
  2205. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2206. break;
  2207. }
  2208. return FALSE;
  2209. }
  2210. /////////////////////////////////////////////////////////////////////////////
  2211. /////////////////////////////////////////////////////////////////////////////
  2212. //
  2213. // Advanced autoconfig settings dialog (only used by IEAK)
  2214. //
  2215. /////////////////////////////////////////////////////////////////////////////
  2216. /////////////////////////////////////////////////////////////////////////////
  2217. BOOL AdvAutocnfgDlgInit(HWND hDlg, LPTSTR pszConnectoid)
  2218. {
  2219. INTERNET_PER_CONN_OPTION_LIST list;
  2220. DWORD dwBufSize = sizeof(list);
  2221. // save connectoid name
  2222. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pszConnectoid);
  2223. list.pszConnection = (pszConnectoid && *pszConnectoid) ? pszConnectoid : NULL;
  2224. list.dwSize = sizeof(list);
  2225. list.dwOptionCount = 3;
  2226. list.pOptions = new INTERNET_PER_CONN_OPTION[3];
  2227. if(NULL == list.pOptions)
  2228. {
  2229. return FALSE;
  2230. }
  2231. list.pOptions[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL;
  2232. list.pOptions[1].dwOption = INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS;
  2233. list.pOptions[2].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
  2234. if(FALSE == InternetQueryOption(NULL,
  2235. INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize))
  2236. {
  2237. delete [] list.pOptions;
  2238. return FALSE;
  2239. }
  2240. // autoproxy url (js)
  2241. if(list.pOptions[0].Value.pszValue)
  2242. {
  2243. SetWindowText(GetDlgItem(hDlg, IDC_CONFIGJS_ADDR), list.pOptions[0].Value.pszValue);
  2244. }
  2245. // autoconfig timer interval
  2246. if(list.pOptions[1].Value.dwValue)
  2247. {
  2248. TCHAR szTimerInterval[16];
  2249. wsprintf(szTimerInterval, TEXT("%d"), list.pOptions[1].Value.dwValue);
  2250. SetWindowText(GetDlgItem(hDlg, IDC_CONFIGTIMER), szTimerInterval);
  2251. }
  2252. // autoconfig optimization
  2253. CheckDlgButton(hDlg, IDC_CONFIGOPTIMIZE,
  2254. (list.pOptions[2].Value.dwValue & AUTO_PROXY_FLAG_CACHE_INIT_RUN ) ? BST_CHECKED : BST_UNCHECKED);
  2255. // all done with options list
  2256. if (list.pOptions[0].Value.pszValue)
  2257. {
  2258. GlobalFree(list.pOptions[0].Value.pszValue);
  2259. }
  2260. delete [] list.pOptions;
  2261. return TRUE;
  2262. }
  2263. BOOL AdvAutocnfgDlgOk(HWND hDlg, LPTSTR pszConnectoid)
  2264. {
  2265. INTERNET_PER_CONN_OPTION_LIST list;
  2266. DWORD dwBufSize = sizeof(list);
  2267. TCHAR szAutoconfig[MAX_URL_STRING];
  2268. TCHAR szTimerInterval[16];
  2269. list.pszConnection = (pszConnectoid && *pszConnectoid) ? pszConnectoid : NULL;
  2270. list.dwSize = sizeof(list);
  2271. list.dwOptionCount = 1;
  2272. list.pOptions = new INTERNET_PER_CONN_OPTION[3];
  2273. if(NULL == list.pOptions)
  2274. {
  2275. return FALSE;
  2276. }
  2277. list.pOptions[0].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
  2278. //
  2279. // Query autodiscover flags - we just need to set one bit in there
  2280. //
  2281. if(FALSE == InternetQueryOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize))
  2282. {
  2283. delete [] list.pOptions;
  2284. return FALSE;
  2285. }
  2286. // save autoconfiguration optimization field
  2287. if (IsDlgButtonChecked(hDlg, IDC_CONFIGOPTIMIZE) == BST_CHECKED)
  2288. list.pOptions[0].Value.dwValue |= AUTO_PROXY_FLAG_CACHE_INIT_RUN ;
  2289. else
  2290. list.pOptions[0].Value.dwValue &= ~AUTO_PROXY_FLAG_CACHE_INIT_RUN ;
  2291. //
  2292. // save autoproxy url
  2293. //
  2294. list.pOptions[1].dwOption = INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL;
  2295. GetWindowText(GetDlgItem(hDlg, IDC_CONFIGJS_ADDR), szAutoconfig, sizeof(szAutoconfig));
  2296. list.pOptions[1].Value.pszValue = szAutoconfig;
  2297. //
  2298. // save autoconfig timer
  2299. //
  2300. list.pOptions[2].dwOption = INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS;
  2301. list.pOptions[2].Value.dwValue = 0;
  2302. if(GetWindowText(GetDlgItem(hDlg, IDC_CONFIGTIMER), szTimerInterval, sizeof(szTimerInterval)))
  2303. list.pOptions[2].Value.dwValue = StrToInt(szTimerInterval);
  2304. // update wininet
  2305. list.dwOptionCount = 3;
  2306. InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
  2307. // tell wininet that the proxy info has changed
  2308. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  2309. delete [] list.pOptions;
  2310. return TRUE;
  2311. }
  2312. ///////////////////////////////////////////////////////////////////
  2313. //
  2314. // NAME: AdvAutocnfgProc
  2315. //
  2316. // SYNOPSIS: Dialog proc for autoconfig dialog
  2317. //
  2318. ////////////////////////////////////////////////////////////////////
  2319. INT_PTR CALLBACK AdvAutocnfgDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
  2320. {
  2321. LPTSTR pszConn = (LPTSTR) GetWindowLongPtr(hDlg, GWLP_USERDATA);
  2322. switch (uMsg) {
  2323. case WM_INITDIALOG:
  2324. AdvAutocnfgDlgInit(hDlg, (LPTSTR)lParam);
  2325. return FALSE;
  2326. case WM_COMMAND:
  2327. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  2328. case IDOK:
  2329. if(FALSE == AdvAutocnfgDlgOk(hDlg, pszConn))
  2330. // something is wrong... don't exit yet
  2331. break;
  2332. // fall through
  2333. case IDCANCEL:
  2334. return EndDialog(hDlg, 0);
  2335. }
  2336. break;
  2337. case WM_HELP: // F1
  2338. ResWinHelp((HWND) ((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  2339. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2340. break;
  2341. case WM_CONTEXTMENU: // right mouse click
  2342. ResWinHelp((HWND)wParam, IDS_HELPFILE,
  2343. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2344. break;
  2345. }
  2346. return FALSE;
  2347. }