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.

2313 lines
72 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // RNACALL.C - functions to call RNA dll to create connectoid
  7. //
  8. // HISTORY:
  9. //
  10. // 1/18/95 jeremys Cloned from RNA UI code
  11. // 96/01/31 markdu Renamed CONNENTDLG to OLDCONNENTDLG to avoid
  12. // conflicts with RNAP.H.
  13. // 96/02/23 markdu Replaced RNAValidateEntryName with
  14. // RASValidateEntryName
  15. // 96/02/24 markdu Re-wrote the implementation of ENUM_MODEM to
  16. // use RASEnumDevices() instead of RNAEnumDevices().
  17. // Also eliminated IsValidDevice() and RNAGetDeviceInfo().
  18. // 96/02/24 markdu Re-wrote the implementation of ENUM_CONNECTOID to
  19. // use RASEnumEntries() instead of RNAEnumConnEntries().
  20. // 96/02/26 markdu Replaced all remaining internal RNA APIs.
  21. // 96/03/07 markdu Extend ENUM_MODEM class, and use global modem
  22. // enum object.
  23. // 96/03/08 markdu Do complete verification of device name and type
  24. // strings passed in to CreateConnectoid.
  25. // 96/03/09 markdu Moved generic RASENTRY initialization into
  26. // its own function (InitRasEntry). Added a wait cursor
  27. // during loading of RNA.
  28. // 96/03/09 markdu Added LPRASENTRY parameter to CreateConnectoid()
  29. // 96/03/09 markdu Moved all references to 'need terminal window after
  30. // dial' into RASENTRY.dwfOptions.
  31. // Also no longer need GetConnectoidPhoneNumber function.
  32. // 96/03/10 markdu Moved all references to modem name into RASENTRY.
  33. // 96/03/10 markdu Moved all references to phone number into RASENTRY.
  34. // 96/03/11 markdu Moved code to set username and password out of
  35. // CreateConnectoid into SetConnectoidUsername so it can be reused.
  36. // 96/03/11 markdu Added some flags in InitRasEntry.
  37. // 96/03/13 markdu Change ValidateConncectoidName to take LPCSTR.
  38. // 96/03/16 markdu Added ReInit member function to re-enumerate modems.
  39. // 96/03/21 markdu Work around RNA bug in ENUM_MODEM::ReInit().
  40. // 96/03/24 markdu Replaced memset with ZeroMemory for consistency.
  41. // 96/03/24 markdu Replaced lstrcpy with lstrcpyn where appropriate.
  42. // 96/03/25 markdu Removed GetIPInfo and SetIPInfo.
  43. // 96/04/04 markdu Added phonebook name param to CreateConnectoid,
  44. // ValidateConnectoidName, and SetConnectoidUsername.
  45. // 96/04/07 markdu NASH BUG 15645 Work around RNA bug where area code
  46. // string is required even though it is not being used.
  47. // 96/04/26 markdu NASH BUG 18605 Handle ERROR_FILE_NOT_FOUND return
  48. // from ValidateConnectoidName.
  49. // 96/05/14 markdu NASH BUG 22730 Work around RNA bug. Flags for terminal
  50. // settings are swapped by RasSetEntryproperties.
  51. // 96/05/16 markdu NASH BUG 21810 Added function for IP address validation.
  52. // 96/06/04 markdu OSR BUG 7246 Add RASEO_SwCompression and
  53. // RASEO_ModemLights to default RASENTRY.
  54. //
  55. #include "wizard.h"
  56. #include "tapi.h"
  57. #include "wininet.h"
  58. // WARNING This flag is defined if WINVER is >= 0x500, but we do not want to build with WINVER >= 0x500
  59. // since we must be able to run on older platforms (Win 95, etc). This is defined original in ras.h
  60. #ifndef RASEO_ShowDialingProgress
  61. #define RASEO_ShowDialingProgress 0x04000000
  62. #endif
  63. // WARNING This flag is defined if WINVER is >= 401, but we do not want to build with WINVER >= 401
  64. // since we must be able to run on older platforms (Win 95, etc)
  65. #ifndef RASEO_SecureLocalFiles
  66. #define RASEO_SecureLocalFiles 0x00010000
  67. #endif
  68. typedef BOOL (WINAPI * INTERNETSETOPTION) (IN HINTERNET hInternet OPTIONAL,IN DWORD dwOption,IN LPVOID lpBuffer,IN DWORD dwBufferLength);
  69. static const TCHAR cszWininet[] = TEXT("WININET.DLL");
  70. static const CHAR cszInternetSetOption[] = "InternetSetOptionA";
  71. // instance handle must be in per-instance data segment
  72. #pragma data_seg(DATASEG_PERINSTANCE)
  73. // Global variables
  74. HINSTANCE ghInstRNADll=NULL; // handle to RNA dll we load explicitly
  75. HINSTANCE ghInstRNAPHDll=NULL; // handle to RNAPH dll we load explicitly
  76. DWORD dwRefCount=0;
  77. BOOL fRNALoaded=FALSE; // TRUE if RNA function addresses have been loaded
  78. TCHAR * gpCountryCodeBuf = NULL; // global list of COUNTRYCODE structures
  79. // global function pointers for RNA apis
  80. RASGETCOUNTRYINFO lpRasGetCountryInfo=NULL;
  81. RASENUMDEVICES lpRasEnumDevices=NULL;
  82. RASVALIDATEENTRYNAME lpRasValidateEntryName=NULL;
  83. RASGETENTRYDIALPARAMS lpRasGetEntryDialParams=NULL;
  84. RASSETENTRYDIALPARAMS lpRasSetEntryDialParams=NULL;
  85. RASGETERRORSTRING lpRasGetErrorString=NULL;
  86. RASSETENTRYPROPERTIES lpRasSetEntryProperties=NULL;
  87. RASGETENTRYPROPERTIES lpRasGetEntryProperties=NULL;
  88. RASENUMENTRIES lpRasEnumEntries=NULL;
  89. // API table for function addresses to fetch
  90. #define NUM_RNAAPI_PROCS 9
  91. APIFCN RnaApiList[NUM_RNAAPI_PROCS] =
  92. {
  93. { (PVOID *) &lpRasEnumDevices,szRasEnumDevices},
  94. { (PVOID *) &lpRasGetCountryInfo,szRasGetCountryInfo},
  95. { (PVOID *) &lpRasValidateEntryName,szRasValidateEntryName},
  96. { (PVOID *) &lpRasGetEntryDialParams,szRasGetEntryDialParams},
  97. { (PVOID *) &lpRasSetEntryDialParams,szRasSetEntryDialParams},
  98. { (PVOID *) &lpRasGetErrorString,szRasGetErrorString},
  99. { (PVOID *) &lpRasSetEntryProperties,szRasSetEntryProperties},
  100. { (PVOID *) &lpRasGetEntryProperties,szRasGetEntryProperties},
  101. { (PVOID *) &lpRasEnumEntries,szRasEnumEntries}
  102. };
  103. //BUGBUG 21-May-1995 bens use #define...sizeof() to define NUM_RNAAPI_PROCS
  104. #pragma data_seg(DATASEG_DEFAULT)
  105. VOID ShortenName(LPTSTR szLongName, LPTSTR szShortName, DWORD cbShort);
  106. BOOL GetApiProcAddresses(HMODULE hModDLL,APIFCN * pApiProcList,UINT nApiProcs);
  107. VOID SwapDwBytes(LPDWORD lpdw);
  108. void SwapDWBits(LPDWORD lpdw, DWORD dwBit1, DWORD dwBit2);
  109. #define NO_INTRO 0x00000080 // flag used by RNA wizard
  110. #define US_COUNTRY_CODE 1 // US country code is 1
  111. #define US_COUNTRY_ID 1 // US country ID is 1
  112. /*******************************************************************
  113. NAME: InitRNA
  114. SYNOPSIS: Loads the RNA dll (RASAPI32), gets proc addresses,
  115. and loads RNA engine
  116. EXIT: TRUE if successful, or FALSE if fails. Displays its
  117. own error message upon failure.
  118. NOTES: We load the RNA dll explicitly and get proc addresses
  119. because these are private APIs and not guaranteed to
  120. be supported beyond Windows 95. This way, if the DLL
  121. isn't there or the entry points we expect aren't there,
  122. we can display a coherent message instead of the weird
  123. Windows dialog you get if implicit function addresses
  124. can't be resolved.
  125. ********************************************************************/
  126. BOOL InitRNA(HWND hWnd)
  127. {
  128. DEBUGMSG("rnacall.c::InitRNA()");
  129. // only actually do init stuff on first call to this function
  130. // (when reference count is 0), just increase reference count
  131. // for subsequent calls
  132. if (dwRefCount == 0) {
  133. TCHAR szRNADll[SMALL_BUF_LEN];
  134. DEBUGMSG("Loading RNA DLL");
  135. // set an hourglass cursor
  136. WAITCURSOR WaitCursor;
  137. // get the filename (RASAPI32.DLL) out of resource
  138. LoadSz(IDS_RNADLL_FILENAME,szRNADll,ARRAYSIZE(szRNADll));
  139. // load the RNA api dll
  140. ghInstRNADll = LoadLibrary(szRNADll);
  141. if (!ghInstRNADll) {
  142. UINT uErr = GetLastError();
  143. DisplayErrorMessage(hWnd,IDS_ERRLoadRNADll1,uErr,ERRCLS_STANDARD,
  144. MB_ICONSTOP);
  145. return FALSE;
  146. }
  147. // cycle through the API table and get proc addresses for all the APIs we
  148. // need
  149. if (!GetApiProcAddresses(ghInstRNADll,RnaApiList,NUM_RNAAPI_PROCS)) {
  150. MsgBox(hWnd,IDS_ERRLoadRNADll2,MB_ICONSTOP,MB_OK);
  151. DeInitRNA();
  152. return FALSE;
  153. }
  154. }
  155. fRNALoaded = TRUE;
  156. dwRefCount ++;
  157. return TRUE;
  158. }
  159. /*******************************************************************
  160. NAME: DeInitRNA
  161. SYNOPSIS: Unloads RNA dll.
  162. ********************************************************************/
  163. VOID DeInitRNA()
  164. {
  165. DEBUGMSG("rnacall.c::DeInitRNA()");
  166. UINT nIndex;
  167. // decrement reference count
  168. if (dwRefCount)
  169. dwRefCount --;
  170. // when the reference count hits zero, do real deinitialization stuff
  171. if (dwRefCount == 0)
  172. {
  173. if (fRNALoaded)
  174. {
  175. // set function pointers to NULL
  176. for (nIndex = 0;nIndex<NUM_RNAAPI_PROCS;nIndex++)
  177. *RnaApiList[nIndex].ppFcnPtr = NULL;
  178. fRNALoaded = FALSE;
  179. }
  180. // free the RNA dll
  181. if (ghInstRNADll)
  182. {
  183. DEBUGMSG("Unloading RNA DLL");
  184. FreeLibrary(ghInstRNADll);
  185. ghInstRNADll = NULL;
  186. }
  187. // free the RNAPH dll
  188. if (ghInstRNAPHDll)
  189. {
  190. DEBUGMSG("Unloading RNAPH DLL");
  191. FreeLibrary(ghInstRNAPHDll);
  192. ghInstRNAPHDll = NULL;
  193. }
  194. }
  195. }
  196. /*******************************************************************
  197. NAME: CreateConnectoid
  198. SYNOPSIS: Creates a connectoid (phone book entry) with specified
  199. name and phone number
  200. ENTRY: pszConnectionName - name for the new connectoid
  201. pszUserName - optional. If non-NULL, this will be set for the
  202. user name in new connectoid
  203. pszPassword - optional. If non-NULL, this will be set for the
  204. password in new connectoid
  205. EXIT: returns ERROR_SUCCESS if successful, or an RNA error code
  206. HISTORY:
  207. 96/02/26 markdu Moved ClearConnectoidIPParams functionality
  208. into CreateConnectoid
  209. ********************************************************************/
  210. DWORD CreateConnectoid(LPCTSTR pszPhonebook, LPCTSTR pszConnectionName,
  211. LPRASENTRY lpRasEntry, LPCTSTR pszUserName,LPCTSTR pszPassword)
  212. {
  213. DEBUGMSG("rnacall.c::CreateConnectoid()");
  214. DWORD dwRet;
  215. ASSERT(pszConnectionName);
  216. // if we don't have a valid RasEntry, bail
  217. if ((NULL == lpRasEntry) || (sizeof(RASENTRY) != lpRasEntry->dwSize))
  218. {
  219. return ERROR_INVALID_PARAMETER;
  220. }
  221. // Load RNA if not already loaded
  222. dwRet = EnsureRNALoaded();
  223. if (ERROR_SUCCESS != dwRet)
  224. {
  225. return dwRet;
  226. }
  227. // Enumerate the modems.
  228. if (gpEnumModem)
  229. {
  230. // Re-enumerate the modems to be sure we have the most recent changes
  231. dwRet = gpEnumModem->ReInit();
  232. }
  233. else
  234. {
  235. // The object does not exist, so create it.
  236. gpEnumModem = new ENUM_MODEM;
  237. if (gpEnumModem)
  238. {
  239. dwRet = gpEnumModem->GetError();
  240. }
  241. else
  242. {
  243. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  244. }
  245. }
  246. if (ERROR_SUCCESS != dwRet)
  247. {
  248. return dwRet;
  249. }
  250. // Make sure there is at least one device
  251. if (0 == gpEnumModem->GetNumDevices())
  252. {
  253. return ERROR_DEVICE_DOES_NOT_EXIST;
  254. }
  255. // Validate the device if possible
  256. if (lstrlen(lpRasEntry->szDeviceName) && lstrlen(lpRasEntry->szDeviceType))
  257. {
  258. // Verify that there is a device with the given name and type
  259. if (!gpEnumModem->VerifyDeviceNameAndType(lpRasEntry->szDeviceName,
  260. lpRasEntry->szDeviceType))
  261. {
  262. // There was no device that matched both name and type,
  263. // so try to get the first device with matching name.
  264. LPTSTR szDeviceType =
  265. gpEnumModem->GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  266. if (szDeviceType)
  267. {
  268. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  269. }
  270. else
  271. {
  272. // There was no device that matched the given name,
  273. // so try to get the first device with matching type.
  274. // If this fails, fall through to recovery case below.
  275. LPTSTR szDeviceName =
  276. gpEnumModem->GetDeviceNameFromType(lpRasEntry->szDeviceType);
  277. if (szDeviceName)
  278. {
  279. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  280. }
  281. else
  282. {
  283. // There was no device that matched the given name OR
  284. // the given type. Reset the values so they will be
  285. // replaced with the first device.
  286. lpRasEntry->szDeviceName[0] = '\0';
  287. lpRasEntry->szDeviceType[0] = '\0';
  288. }
  289. }
  290. }
  291. }
  292. else if (lstrlen(lpRasEntry->szDeviceName))
  293. {
  294. // Only the name was given. Try to find a matching type.
  295. // If this fails, fall through to recovery case below.
  296. LPTSTR szDeviceType =
  297. gpEnumModem->GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  298. if (szDeviceType)
  299. {
  300. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  301. }
  302. }
  303. else if (lstrlen(lpRasEntry->szDeviceType))
  304. {
  305. // Only the type was given. Try to find a matching name.
  306. // If this fails, fall through to recovery case below.
  307. LPTSTR szDeviceName =
  308. gpEnumModem->GetDeviceNameFromType(lpRasEntry->szDeviceType);
  309. if (szDeviceName)
  310. {
  311. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  312. }
  313. }
  314. // If either name or type is missing, just get first device.
  315. // Since we already verified that there was at least one device,
  316. // we can assume that this will succeed.
  317. if(!lstrlen(lpRasEntry->szDeviceName) ||
  318. !lstrlen(lpRasEntry->szDeviceType))
  319. {
  320. lstrcpy (lpRasEntry->szDeviceName, gpEnumModem->Next());
  321. lstrcpy (lpRasEntry->szDeviceType,
  322. gpEnumModem->GetDeviceTypeFromName(lpRasEntry->szDeviceName));
  323. ASSERT(lstrlen(lpRasEntry->szDeviceName));
  324. ASSERT(lstrlen(lpRasEntry->szDeviceType));
  325. }
  326. // Verify the connectoid name
  327. dwRet = ValidateConnectoidName(pszPhonebook, pszConnectionName);
  328. if ((ERROR_SUCCESS != dwRet) &&
  329. (ERROR_ALREADY_EXISTS != dwRet))
  330. {
  331. DEBUGMSG("RasValidateEntryName returned %lu",dwRet);
  332. return dwRet;
  333. }
  334. // 99/04/13 vyung NT5 BUG 279833
  335. // New features in NT5 to show progress while dialing. Enable it by default
  336. if (IsNT5())
  337. {
  338. // For NT 5 and greater, File sharing is disabled per connectoid by setting this RAS option.
  339. lpRasEntry->dwfOptions |= RASEO_SecureLocalFiles;
  340. lpRasEntry->dwfOptions |= RASEO_ShowDialingProgress;
  341. }
  342. // 96/04/07 markdu NASH BUG 15645
  343. // If there is no area code string, and RASEO_UseCountryAndAreaCodes is not
  344. // set, then the area code will be ignored so put in a default otherwise the
  345. // call to RasSetEntryProperties will fail due to an RNA bug.
  346. // if RASEO_UseCountryAndAreaCodes is set, then area code is required, so not
  347. // having one is an error. Let RNA report the error.
  348. if (!lstrlen(lpRasEntry->szAreaCode) &&
  349. !(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes))
  350. {
  351. lstrcpy (lpRasEntry->szAreaCode, szDefaultAreaCode);
  352. }
  353. // 96/05/14 markdu NASH BUG 22730 Work around RNA bug. Flags for terminal
  354. // settings are swapped by RasSetEntryproperties, so we swap them before
  355. // the call.
  356. if (IsWin95())
  357. SwapDWBits(&lpRasEntry->dwfOptions, RASEO_TerminalBeforeDial,
  358. RASEO_TerminalAfterDial);
  359. // call RNA to create the connectoid
  360. ASSERT(lpRasSetEntryProperties);
  361. #ifdef UNICODE
  362. LPRASENTRY lpRasEntryTmp;
  363. lpRasEntryTmp = (LPRASENTRY)GlobalAlloc(GPTR, sizeof(RASENTRY) + 512);
  364. if(lpRasEntry)
  365. memcpy(lpRasEntryTmp, lpRasEntry, sizeof(RASENTRY));
  366. else
  367. lpRasEntryTmp = (LPRASENTRY)lpRasEntry;
  368. dwRet = lpRasSetEntryProperties(pszPhonebook, pszConnectionName,
  369. (LPBYTE)lpRasEntryTmp, sizeof(RASENTRY)+512, NULL, 0);
  370. if(lpRasEntryTmp && lpRasEntryTmp != (LPRASENTRY)lpRasEntry)
  371. {
  372. memcpy(lpRasEntry, lpRasEntryTmp, sizeof(RASENTRY));
  373. GlobalFree(lpRasEntryTmp);
  374. }
  375. #else
  376. dwRet = lpRasSetEntryProperties(pszPhonebook, pszConnectionName,
  377. (LPBYTE)lpRasEntry, sizeof(RASENTRY), NULL, 0);
  378. #endif
  379. // 96/05/14 markdu NASH BUG 22730 Work around RNA bug. Put the bits back
  380. // to the way they were originally,
  381. if (IsWin95())
  382. SwapDWBits(&lpRasEntry->dwfOptions, RASEO_TerminalBeforeDial,
  383. RASEO_TerminalAfterDial);
  384. // populate the connectoid with user's account name and password.
  385. if (dwRet == ERROR_SUCCESS)
  386. {
  387. if (pszUserName || pszPassword)
  388. {
  389. dwRet = SetConnectoidUsername(pszPhonebook, pszConnectionName,
  390. pszUserName, pszPassword);
  391. }
  392. }
  393. else
  394. {
  395. DEBUGMSG("RasSetEntryProperties returned %lu",dwRet);
  396. }
  397. if (dwRet == ERROR_SUCCESS)
  398. {
  399. // BUGBUG This prevents the make new connection wizard from being
  400. // launched the first time the user opens the RNA folder.
  401. // Now that we own the make new connection wizard, we
  402. // have to decide whether to do this or not.
  403. // set a flag to tell RNA not to run the RNA wizard automatically
  404. // when the folder is opened (they set this flag from their wizard
  405. // whenever they create a new connectoid). If this fails just
  406. // go on, not a critical error
  407. RegEntry reRNAFolder(szRegPathRNAWizard,HKEY_CURRENT_USER);
  408. ASSERT(reRNAFolder.GetError() == ERROR_SUCCESS);
  409. DWORD dwVal = NO_INTRO;
  410. RegSetValueEx(reRNAFolder.GetKey(),szRegValRNAWizard,
  411. 0,REG_BINARY,(LPBYTE) &dwVal,sizeof(dwVal));
  412. // We don't use auto discovery for referral and signup connectoid
  413. if (!g_bUseAutoProxyforConnectoid)
  414. {
  415. // VYUNG 12/16/1998
  416. // REMOVE AUTO DISCOVERY FROM THE DIALUP CONNECTOID
  417. INTERNET_PER_CONN_OPTION_LISTA list;
  418. DWORD dwBufSize = sizeof(list);
  419. // fill out list struct
  420. list.dwSize = sizeof(list);
  421. CHAR szConnectoid [RAS_MaxEntryName];
  422. #ifdef UNICODE
  423. wcstombs(szConnectoid, pszConnectionName, RAS_MaxEntryName);
  424. #else
  425. lstrcpyn(szConnectoid, pszConnectionName, lstrlen(pszConnectionName)+1);
  426. #endif
  427. list.pszConnection = szConnectoid;
  428. list.dwOptionCount = 1; // one option
  429. list.pOptions = new INTERNET_PER_CONN_OPTIONA[1];
  430. if(list.pOptions)
  431. {
  432. // set flags
  433. list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  434. list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT; // no proxy, autoconfig url, or autodiscovery
  435. // tell wininet
  436. HINSTANCE hInst = NULL;
  437. FARPROC fpInternetSetOption = NULL;
  438. dwRet = ERROR_SUCCESS;
  439. hInst = LoadLibrary(cszWininet);
  440. if (hInst)
  441. {
  442. fpInternetSetOption = GetProcAddress(hInst,cszInternetSetOption);
  443. if (fpInternetSetOption)
  444. {
  445. if( !((INTERNETSETOPTION)fpInternetSetOption) (NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize) )
  446. {
  447. dwRet = GetLastError();
  448. DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  449. }
  450. }
  451. else
  452. dwRet = GetLastError();
  453. FreeLibrary(hInst);
  454. }
  455. delete [] list.pOptions;
  456. }
  457. }
  458. }
  459. return dwRet;
  460. }
  461. /*******************************************************************
  462. NAME: InitModemList
  463. SYNOPSIS: Fills a combo box window with installed modems
  464. ENTRY: hCB - combo box window to fill
  465. ********************************************************************/
  466. HRESULT InitModemList (HWND hCB)
  467. {
  468. DEBUGMSG("rnacall.c::InitModemList()");
  469. LPTSTR pNext;
  470. int nIndex;
  471. DWORD dwRet;
  472. ASSERT(hCB);
  473. // Load RNA if not already loaded
  474. dwRet = EnsureRNALoaded();
  475. if (ERROR_SUCCESS != dwRet)
  476. {
  477. return dwRet;
  478. }
  479. // Enumerate the modems.
  480. if (gpEnumModem)
  481. {
  482. // Re-enumerate the modems to be sure we have the most recent changes
  483. dwRet = gpEnumModem->ReInit();
  484. }
  485. else
  486. {
  487. // The object does not exist, so create it.
  488. gpEnumModem = new ENUM_MODEM;
  489. if (gpEnumModem)
  490. {
  491. dwRet = gpEnumModem->GetError();
  492. }
  493. else
  494. {
  495. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  496. }
  497. }
  498. if (ERROR_SUCCESS != dwRet)
  499. {
  500. return dwRet;
  501. }
  502. // clear out the combo box
  503. ComboBox_ResetContent(hCB);
  504. while ( pNext = gpEnumModem->Next())
  505. {
  506. // Add the device to the combo box
  507. nIndex = ComboBox_AddString(hCB, pNext);
  508. ComboBox_SetItemData(hCB, nIndex, NULL);
  509. }
  510. // Select the default device
  511. ComboBox_SetCurSel(hCB, nIndex);
  512. return ERROR_SUCCESS;
  513. }
  514. /*******************************************************************
  515. NAME: InitConnectoidList
  516. SYNOPSIS: Fills a list box window with list of RNA connectoids
  517. ENTRY: hLB - list box window to fill
  518. lpszSelect - The connectoid name to select as default
  519. ********************************************************************/
  520. VOID InitConnectoidList(HWND hLB, LPTSTR lpszSelect)
  521. {
  522. DEBUGMSG("rnacall.c::InitConnectoidList()");
  523. ASSERT(hLB);
  524. LPTSTR pNext;
  525. // Load RNA if not already loaded
  526. if (EnsureRNALoaded() != ERROR_SUCCESS)
  527. return;
  528. ENUM_CONNECTOID EnumConnectoid; // class object for enum
  529. // clear out the list box
  530. ListBox_ResetContent(hLB);
  531. int index;
  532. BOOL fSelected = FALSE;
  533. // enumerate connectoids
  534. while ( pNext = EnumConnectoid.Next()) {
  535. // Add the connectoid to the combo box
  536. index = ListBox_AddString(hLB, pNext);
  537. if (!fSelected && !lstrcmpi(pNext, lpszSelect))
  538. {
  539. fSelected = TRUE;
  540. ListBox_SetCurSel(hLB, index);
  541. }
  542. }
  543. if (!fSelected)
  544. ListBox_SetSel(hLB, TRUE, 0);
  545. }
  546. /*******************************************************************
  547. NAME: GetConnectoidUsername
  548. SYNOPSIS: Get the username and password strings from the phonebook
  549. entry name specified.
  550. ENTRY: pszConnectoidName - phonebook entry name
  551. pszUserName - string to hold user name
  552. cbUserName - size of pszUserName buffer
  553. pszPassword - string to hold password
  554. cbPassword - size of pszPassword buffer
  555. EXIT: TRUE if username and password were copied successfully
  556. ********************************************************************/
  557. BOOL GetConnectoidUsername(TCHAR * pszConnectoidName,TCHAR * pszUserName,
  558. DWORD cbUserName,TCHAR * pszPassword,DWORD cbPassword)
  559. {
  560. DEBUGMSG("rnacall.c::GetConnectoidUsername()");
  561. ASSERT(pszConnectoidName);
  562. ASSERT(pszUserName);
  563. ASSERT(pszPassword);
  564. BOOL fRet = FALSE;
  565. // Load RNA if not already loaded
  566. DWORD dwRet = EnsureRNALoaded();
  567. if (dwRet != ERROR_SUCCESS) {
  568. return FALSE;
  569. }
  570. RASDIALPARAMS RasDialParams;
  571. ZeroMemory(&RasDialParams,sizeof(RASDIALPARAMS));
  572. RasDialParams.dwSize = sizeof(RASDIALPARAMS);
  573. lstrcpyn(RasDialParams.szEntryName,pszConnectoidName,
  574. ARRAYSIZE(RasDialParams.szEntryName));
  575. // call RNA to get user name and password
  576. ASSERT(lpRasGetEntryDialParams);
  577. BOOL fPasswordSaved;
  578. dwRet = lpRasGetEntryDialParams(NULL,&RasDialParams,&fPasswordSaved);
  579. if (dwRet == ERROR_SUCCESS) {
  580. // copy user name and password to caller's buffers
  581. lstrcpyn(pszUserName,RasDialParams.szUserName,cbUserName);
  582. lstrcpyn(pszPassword,RasDialParams.szPassword,cbPassword);
  583. fRet = TRUE;
  584. }
  585. return fRet;
  586. }
  587. /*******************************************************************
  588. NAME: SetConnectoidUsername
  589. SYNOPSIS: Set the username and password strings for the phonebook
  590. entry name specified.
  591. ENTRY: pszConnectoidName - phonebook entry name
  592. pszUserName - string with user name
  593. pszPassword - string with password
  594. EXIT: Return value of GetEntryDialParams or SetEntryDialParams
  595. ********************************************************************/
  596. DWORD SetConnectoidUsername(LPCTSTR pszPhonebook, LPCTSTR pszConnectoidName,
  597. LPCTSTR pszUserName, LPCTSTR pszPassword)
  598. {
  599. BOOL bSkipSetting;
  600. bSkipSetting = TRUE;
  601. DEBUGMSG("rnacall.c::SetConnectoidUsername()");
  602. ASSERT(pszConnectoidName);
  603. // allocate a struct to use to set dialing params
  604. LPRASDIALPARAMS pRASDialParams = new RASDIALPARAMS;
  605. if (!pRASDialParams)
  606. return ERROR_ALLOCATING_MEMORY;
  607. ZeroMemory(pRASDialParams,sizeof(RASDIALPARAMS)); // zero out structure
  608. pRASDialParams->dwSize = sizeof(RASDIALPARAMS);
  609. lstrcpyn(pRASDialParams->szEntryName,pszConnectoidName,
  610. ARRAYSIZE(pRASDialParams->szEntryName));
  611. // get the dialing params for this connectoid so we don't have
  612. // to reconstruct the fields in struct we aren't changing
  613. ASSERT(lpRasGetEntryDialParams);
  614. BOOL fPasswordSaved;
  615. DWORD dwRet = lpRasGetEntryDialParams(pszPhonebook,
  616. pRASDialParams,&fPasswordSaved);
  617. if (dwRet == ERROR_SUCCESS)
  618. {
  619. // set the user name and password fields in struct
  620. // user name and password are optional parameters to this function,
  621. // make sure pointer is valid
  622. if (0 != lstrcmp(pRASDialParams->szUserName,pszUserName))
  623. bSkipSetting = FALSE;
  624. if (0 != lstrcmp(pRASDialParams->szPassword,pszPassword))
  625. bSkipSetting = FALSE;
  626. if (pszUserName)
  627. lstrcpyn(pRASDialParams->szUserName,pszUserName,
  628. ARRAYSIZE(pRASDialParams->szUserName));
  629. if (pszPassword)
  630. lstrcpyn(pRASDialParams->szPassword,pszPassword,
  631. ARRAYSIZE(pRASDialParams->szPassword));
  632. // if no password is specified, then set fRemovePassword to TRUE
  633. // to remove any old password in the connectoid
  634. BOOL fRemovePassword = (pRASDialParams->szPassword[0] ?
  635. FALSE : TRUE);
  636. bSkipSetting = !fRemovePassword && bSkipSetting;
  637. // set these parameters for connectoid
  638. ASSERT(lpRasSetEntryDialParams);
  639. if (!bSkipSetting)
  640. {
  641. dwRet = lpRasSetEntryDialParams(pszPhonebook,pRASDialParams,
  642. fRemovePassword);
  643. if (dwRet != ERROR_SUCCESS)
  644. {
  645. DEBUGMSG("RasSetEntryDialParams returned %lu",dwRet);
  646. }
  647. }
  648. // ChrisK 9-20-96 Normandy 6096
  649. // For NT4.0 we also have to call RasSetCredentials
  650. // Check to see if we are running on NT.
  651. OSVERSIONINFO osver;
  652. FARPROC fp;
  653. fp = NULL;
  654. ZeroMemory(&osver,sizeof(osver));
  655. osver.dwOSVersionInfoSize = sizeof(osver);
  656. if (GetVersionEx(&osver))
  657. {
  658. if (VER_PLATFORM_WIN32_NT == osver.dwPlatformId)
  659. {
  660. // fill in credential structure
  661. RASCREDENTIALS rascred;
  662. ZeroMemory(&rascred,sizeof(rascred));
  663. rascred.dwSize = sizeof(rascred);
  664. rascred.dwMask = RASCM_UserName | RASCM_Password | RASCM_Domain;
  665. lstrcpyn(rascred.szUserName,pszUserName,UNLEN);
  666. lstrcpyn(rascred.szPassword,pszPassword,PWLEN);
  667. lstrcpyn(rascred.szDomain,TEXT(""),DNLEN);
  668. ASSERT(ghInstRNADll);
  669. // load API
  670. fp = GetProcAddress(ghInstRNADll,szRasSetCredentials);
  671. if (fp)
  672. {
  673. dwRet = ((RASSETCREDENTIALS)fp)(NULL,(LPTSTR)pszConnectoidName,&rascred,FALSE);
  674. DEBUGMSG("RasSetCredentials returned, %lu",dwRet);
  675. }
  676. else
  677. {
  678. DEBUGMSG("RasSetCredentials api not found.");
  679. }
  680. }
  681. }
  682. }
  683. else
  684. {
  685. DEBUGMSG("RasGetEntryDialParams returned %lu",dwRet);
  686. }
  687. delete pRASDialParams;
  688. return dwRet;
  689. }
  690. /*******************************************************************
  691. NAME: ValidateConnectoidName
  692. SYNOPSIS: Validates the phonebook entry name specified.
  693. ENTRY: pszConnectoidName - phonebook entry name
  694. EXIT: Result of RasValidateEntryName
  695. ********************************************************************/
  696. DWORD ValidateConnectoidName(LPCTSTR pszPhonebook, LPCTSTR pszConnectoidName)
  697. {
  698. DEBUGMSG("rnacall.c::ValidateConnectoidName()");
  699. ASSERT(pszConnectoidName);
  700. // Load RNA if not already loaded
  701. DWORD dwRet = EnsureRNALoaded();
  702. if (dwRet != ERROR_SUCCESS) {
  703. return dwRet;
  704. }
  705. ASSERT(lpRasValidateEntryName);
  706. // Although we require a const char *, RasValidateEntryName will
  707. // accept it, so we have to cast.
  708. dwRet = lpRasValidateEntryName(pszPhonebook, (LPTSTR)pszConnectoidName);
  709. // If there are no previous entries, RasValidateEntryName may return
  710. // ERROR_CANNOT_OPEN_PHONEBOOK. This is okay.
  711. if (ERROR_CANNOT_OPEN_PHONEBOOK == dwRet)
  712. dwRet = ERROR_SUCCESS;
  713. return dwRet;
  714. }
  715. /*******************************************************************
  716. NAME: GetEntry
  717. SYNOPSIS: Gets the phonebook entry specified. To get default
  718. entry, use "" as entry name.
  719. ENTRY: lpEntry - pointer to RASENTRY struct to fill
  720. szEntryName - phonebook entry name
  721. EXIT: Result of RasGetEntryProperties
  722. ********************************************************************/
  723. DWORD GetEntry(LPRASENTRY *lplpEntry, LPDWORD lpdwEntrySize, LPCTSTR szEntryName)
  724. {
  725. DEBUGMSG("rnacall.c::GetEntry()");
  726. ASSERT(fRNALoaded); // RNA should be loaded if we get here
  727. ASSERT(lplpEntry);
  728. ASSERT(szEntryName);
  729. // Allocate space if needed
  730. if (NULL == *lplpEntry)
  731. {
  732. *lpdwEntrySize = sizeof(RASENTRY);
  733. *lplpEntry = (LPRASENTRY) GlobalAlloc(GPTR,*lpdwEntrySize);
  734. if (NULL == *lplpEntry)
  735. {
  736. *lpdwEntrySize = 0;
  737. return ERROR_ALLOCATING_MEMORY;
  738. }
  739. }
  740. // get connectoid information from RNA
  741. DWORD dwSize = *lpdwEntrySize;
  742. (*lplpEntry)->dwSize = sizeof(RASENTRY);
  743. ASSERT(lpRasGetEntryProperties);
  744. DWORD dwRet = (lpRasGetEntryProperties) (NULL, szEntryName,
  745. (LPBYTE)*lplpEntry, &dwSize, NULL, NULL);
  746. // Allocate more space if needed
  747. if (ERROR_BUFFER_TOO_SMALL == dwRet)
  748. {
  749. LPRASENTRY lpNewEntry;
  750. lpNewEntry = (LPRASENTRY) GlobalReAlloc(*lplpEntry,dwSize,GMEM_MOVEABLE);
  751. if (NULL == lpNewEntry)
  752. {
  753. return ERROR_ALLOCATING_MEMORY;
  754. }
  755. *lplpEntry = lpNewEntry;
  756. *lpdwEntrySize = dwSize;
  757. dwRet = (lpRasGetEntryProperties) (NULL, szEntryName,
  758. (LPBYTE)*lplpEntry, &dwSize, NULL, NULL);
  759. }
  760. return dwRet;
  761. }
  762. VOID FAR PASCAL LineCallback(DWORD hDevice, DWORD dwMsg,
  763. DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2,
  764. DWORD dwParam3)
  765. {
  766. return;
  767. }
  768. //+----------------------------------------------------------------------------
  769. //
  770. // Function GetTapiCountryID
  771. //
  772. // Synopsis Get the currenty country ID for the tapi settings
  773. //
  774. // Arguments none
  775. //
  776. // Returns pdwCountryID - contains address of country ID
  777. // ERROR_SUCCESS - no errors
  778. //
  779. // History 1/8/97 ChrisK Copied from icwconn1/dialerr.cpp
  780. //
  781. //-----------------------------------------------------------------------------
  782. // Normandy 13097 - ChrisK 1/8/97
  783. // NT returns the country ID not the country code
  784. HRESULT GetTapiCountryID(LPDWORD pdwCountryID)
  785. {
  786. HRESULT hr = ERROR_SUCCESS;
  787. HLINEAPP hLineApp = NULL;
  788. DWORD dwCurDev;
  789. DWORD cDevices;
  790. DWORD dwAPI;
  791. LONG lrc;
  792. LPLINETRANSLATECAPS pTC = NULL;
  793. LPVOID pv = NULL;
  794. LPLINELOCATIONENTRY plle = NULL;
  795. LINEEXTENSIONID leid;
  796. DWORD dwCurLoc;
  797. // Get CountryID from TAPI
  798. //
  799. *pdwCountryID = 0;
  800. // Get the handle to the line app
  801. //
  802. lineInitialize(&hLineApp,ghInstance,LineCallback," ",&cDevices);
  803. if (!hLineApp)
  804. {
  805. hr = GetLastError();
  806. goto GetTapiCountryIDExit;
  807. }
  808. if (cDevices)
  809. {
  810. // Get the TAPI API version
  811. //
  812. dwCurDev = 0;
  813. dwAPI = 0;
  814. lrc = -1;
  815. while (lrc && dwCurDev < cDevices)
  816. {
  817. // NOTE: device ID's are 0 based
  818. lrc = lineNegotiateAPIVersion(hLineApp,dwCurDev,0x00010004,0x00010004,&dwAPI,&leid);
  819. dwCurDev++;
  820. }
  821. if (lrc)
  822. {
  823. // TAPI and us can't agree on anything so nevermind...
  824. hr = ERROR_GEN_FAILURE;
  825. goto GetTapiCountryIDExit;
  826. }
  827. // Find the CountryID in the translate cap structure
  828. //
  829. pTC = (LINETRANSLATECAPS FAR *)GlobalAlloc(GPTR,sizeof(LINETRANSLATECAPS));
  830. if (!pTC)
  831. {
  832. // we are in real trouble here, get out!
  833. hr = ERROR_NOT_ENOUGH_MEMORY;
  834. goto GetTapiCountryIDExit;
  835. }
  836. // Get the needed size
  837. //
  838. pTC->dwTotalSize = sizeof(LINETRANSLATECAPS);
  839. lrc = lineGetTranslateCaps(hLineApp,dwAPI,pTC);
  840. if(lrc)
  841. {
  842. hr = lrc;
  843. goto GetTapiCountryIDExit;
  844. }
  845. pv = (LPVOID) GlobalAlloc(GPTR,((size_t)pTC->dwNeededSize));
  846. if (!pv)
  847. {
  848. hr = ERROR_NOT_ENOUGH_MEMORY;
  849. goto GetTapiCountryIDExit;
  850. }
  851. ((LINETRANSLATECAPS FAR *)pv)->dwTotalSize = pTC->dwNeededSize;
  852. GlobalFree(pTC);
  853. pTC = (LINETRANSLATECAPS FAR *)pv;
  854. pv = NULL;
  855. lrc = lineGetTranslateCaps(hLineApp,dwAPI,pTC);
  856. if(lrc)
  857. {
  858. hr = lrc;
  859. goto GetTapiCountryIDExit;
  860. }
  861. plle = LPLINELOCATIONENTRY (LPTSTR(pTC) + pTC->dwLocationListOffset);
  862. for (dwCurLoc = 0; dwCurLoc < pTC->dwNumLocations; dwCurLoc++)
  863. {
  864. *pdwCountryID = plle->dwPermanentLocationID;
  865. if (pTC->dwCurrentLocationID == plle->dwPermanentLocationID)
  866. {
  867. *pdwCountryID = plle->dwCountryID;
  868. break; // for loop
  869. }
  870. plle++;
  871. }
  872. }
  873. GetTapiCountryIDExit:
  874. // 3/4/97 jmazner Olympus #1336
  875. if( hLineApp )
  876. {
  877. // we never call lineOpen, so no need to lineClose
  878. lineShutdown( hLineApp );
  879. hLineApp = NULL;
  880. }
  881. return hr;
  882. }
  883. /*******************************************************************
  884. NAME: InitRasEntry
  885. SYNOPSIS: Initializes some parts of the RASENTRY struct.
  886. ENTRY: lpEntry - pointer to RASENTRY struct to init
  887. NOTES: Since this may be called before RNA is loaded, must not
  888. make any RNA calls.
  889. 96/06/04 markdu OSR BUG 7246 Add RASEO_SwCompression and
  890. RASEO_ModemLights to default RASENTRY.
  891. ********************************************************************/
  892. void InitRasEntry(LPRASENTRY lpEntry)
  893. {
  894. DEBUGMSG("rnacall.c::InitRasEntry()");
  895. DWORD dwSize = sizeof(RASENTRY);
  896. ZeroMemory(lpEntry, dwSize);
  897. lpEntry->dwSize = dwSize;
  898. // default to use country code and area code
  899. lpEntry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  900. // default to use IP header compression
  901. lpEntry->dwfOptions |= RASEO_IpHeaderCompression;
  902. // default to use remote default gateway
  903. lpEntry->dwfOptions |= RASEO_RemoteDefaultGateway;
  904. // configure connectoid to not log on to network
  905. lpEntry->dwfOptions &= ~RASEO_NetworkLogon;
  906. // default to use software compression
  907. lpEntry->dwfOptions |= RASEO_SwCompression;
  908. // default to use modem lights
  909. lpEntry->dwfOptions |= RASEO_ModemLights;
  910. // set connectoid for PPP
  911. lpEntry->dwFramingProtocol = RASFP_Ppp;
  912. // only use TCP/IP protocol
  913. lpEntry->dwfNetProtocols = RASNP_Ip;
  914. // default to use TAPI area code and country code
  915. TCHAR szCountryCode[8]; // 8 is from tapiGetLocationInfo documentation
  916. if (ERROR_SUCCESS == tapiGetLocationInfo(szCountryCode, lpEntry->szAreaCode))
  917. {
  918. // Normandy 13097 - ChrisK 1/8/97
  919. // NT returns the country ID not the country code
  920. if (szCountryCode[0])
  921. {
  922. if (IsNT())
  923. {
  924. lpEntry->dwCountryID = myatoi(szCountryCode);
  925. lpEntry->dwCountryCode = US_COUNTRY_CODE;
  926. // Initialize data
  927. LINECOUNTRYLIST FAR * lpLineCountryList;
  928. DWORD dwSize;
  929. dwSize = 0;
  930. lpLineCountryList = (LINECOUNTRYLIST FAR *)
  931. GlobalAlloc(GPTR,sizeof(LINECOUNTRYLIST));
  932. if (NULL == lpLineCountryList)
  933. return;
  934. lpLineCountryList->dwTotalSize = sizeof(LINECOUNTRYENTRY);
  935. // Get size of data structre
  936. if(ERROR_SUCCESS != lineGetCountry(lpEntry->dwCountryID,0x10004,lpLineCountryList))
  937. {
  938. GlobalFree(lpLineCountryList);
  939. return;
  940. }
  941. dwSize = lpLineCountryList->dwNeededSize;
  942. GlobalFree(lpLineCountryList);
  943. lpLineCountryList = (LINECOUNTRYLIST FAR *)GlobalAlloc(GPTR,dwSize);
  944. if (NULL == lpLineCountryList)
  945. return;
  946. lpLineCountryList->dwTotalSize = dwSize;
  947. // Get Country information for given ID
  948. if(ERROR_SUCCESS != lineGetCountry(lpEntry->dwCountryID,0x10004,lpLineCountryList))
  949. {
  950. GlobalFree(lpLineCountryList);
  951. return;
  952. }
  953. lpEntry->dwCountryCode = ((LINECOUNTRYENTRY FAR *)((DWORD_PTR)lpLineCountryList +
  954. (DWORD)(lpLineCountryList->dwCountryListOffset)))->dwCountryCode;
  955. GlobalFree(lpLineCountryList);
  956. lpLineCountryList = NULL;
  957. }
  958. else
  959. {
  960. lpEntry->dwCountryCode = myatoi(szCountryCode);
  961. if (ERROR_SUCCESS != GetTapiCountryID(&lpEntry->dwCountryID))
  962. lpEntry->dwCountryID = US_COUNTRY_ID;
  963. }
  964. }
  965. }
  966. else
  967. {
  968. lpEntry->dwCountryCode = US_COUNTRY_CODE;
  969. }
  970. }
  971. /*******************************************************************
  972. NAME: InitCountryCodeList_w
  973. SYNOPSIS: Worker function that fills a specified combo box with
  974. country code selections
  975. ENTRY: hLB - HWND of combo box to fill
  976. dwSelectCountryID - if non-zero, the ID of country code
  977. to select as default
  978. fAll - if TRUE, all country codes are enumerated into
  979. combo box (potentially slow). If FALSE, only
  980. the country code in dwSelectCountryID is enumerated.
  981. NOTES: Cloned from RNA UI code
  982. ********************************************************************/
  983. void InitCountryCodeList_w (HWND hLB, DWORD dwSelectCountryID,BOOL fAll)
  984. {
  985. DEBUGMSG("rnacall.c::InitCountryCodeList_w()");
  986. LPRASCTRYINFO lpRasCtryInfo;
  987. LPCOUNTRYCODE pNext;
  988. DWORD cbSize;
  989. DWORD cbList;
  990. DWORD dwNextCountryID, dwRet;
  991. LPTSTR szCountryDesc;
  992. int nIndex, iSelect;
  993. ASSERT(fRNALoaded); // RNA should be loaded if we get here
  994. BUFFER Fmt(MAX_RES_LEN + SMALL_BUF_LEN);
  995. BUFFER CountryInfo(DEF_COUNTRY_INFO_SIZE);
  996. ASSERT(Fmt);
  997. ASSERT(CountryInfo);
  998. if (!Fmt || !CountryInfo)
  999. return;
  1000. // Load the display format
  1001. LoadSz(IDS_COUNTRY_FMT,Fmt.QueryPtr(),SMALL_BUF_LEN);
  1002. szCountryDesc = Fmt.QueryPtr()+SMALL_BUF_LEN;
  1003. cbList = (DWORD)(fAll ? sizeof(COUNTRYCODE)*MAX_COUNTRY : sizeof(COUNTRYCODE));
  1004. gpCountryCodeBuf = new TCHAR[cbList];
  1005. ASSERT(gpCountryCodeBuf);
  1006. if (!gpCountryCodeBuf)
  1007. return;
  1008. // Start enumerating the info from the first country
  1009. dwNextCountryID = (fAll || (dwSelectCountryID==0)) ?
  1010. 1 : dwSelectCountryID;
  1011. pNext = (LPCOUNTRYCODE) gpCountryCodeBuf;
  1012. iSelect = 0;
  1013. lpRasCtryInfo = (LPRASCTRYINFO) CountryInfo.QueryPtr();
  1014. lpRasCtryInfo->dwSize = sizeof(RASCTRYINFO);
  1015. ComboBox_ResetContent(hLB);
  1016. // For each country
  1017. while (dwNextCountryID != 0)
  1018. {
  1019. lpRasCtryInfo->dwCountryID = dwNextCountryID;
  1020. cbSize = CountryInfo.QuerySize();
  1021. // Get the current country information
  1022. ASSERT(lpRasGetCountryInfo);
  1023. dwRet = lpRasGetCountryInfo(lpRasCtryInfo, &cbSize);
  1024. if (ERROR_SUCCESS == dwRet)
  1025. {
  1026. TCHAR szCountryDisp[MAX_COUNTRY_NAME+1];
  1027. // Make a displayable name
  1028. ShortenName((LPTSTR)(((LPBYTE)lpRasCtryInfo)+lpRasCtryInfo->dwCountryNameOffset),
  1029. szCountryDisp, MAX_COUNTRY_NAME+1);
  1030. // Add the country to the list
  1031. wsprintf(szCountryDesc,Fmt.QueryPtr(), szCountryDisp, lpRasCtryInfo->dwCountryCode);
  1032. nIndex = ComboBox_AddString(hLB, szCountryDesc);
  1033. ASSERT(nIndex >= 0);
  1034. // Copy the country information to our short list
  1035. pNext->dwCountryID = lpRasCtryInfo->dwCountryID;
  1036. pNext->dwCountryCode = lpRasCtryInfo->dwCountryCode;
  1037. dwNextCountryID = lpRasCtryInfo->dwNextCountryID;
  1038. ComboBox_SetItemData(hLB, nIndex, pNext);
  1039. // If it is the specified country, make it a default one
  1040. if (pNext->dwCountryID == dwSelectCountryID)
  1041. ComboBox_SetCurSel(hLB, nIndex);
  1042. // if need only one item, bail out
  1043. //
  1044. if (!fAll)
  1045. break;
  1046. // Advance to the next country
  1047. pNext++;
  1048. }
  1049. else
  1050. {
  1051. // If the buffer is too small, reallocate a new one and retry
  1052. if (dwRet == ERROR_BUFFER_TOO_SMALL)
  1053. {
  1054. BOOL fRet=CountryInfo.Resize(cbSize);
  1055. ASSERT(fRet);
  1056. if (!fRet || !CountryInfo)
  1057. return;
  1058. lpRasCtryInfo = (LPRASCTRYINFO) CountryInfo.QueryPtr();
  1059. }
  1060. else
  1061. {
  1062. break;
  1063. }
  1064. }
  1065. }
  1066. // Select the default device
  1067. if ((dwRet == SUCCESS) && (ComboBox_GetCurSel(hLB) == CB_ERR))
  1068. ComboBox_SetCurSel(hLB, 0);
  1069. return;
  1070. }
  1071. /*******************************************************************
  1072. NAME: InitCountryCodeList
  1073. SYNOPSIS: Puts the (single) default country code in specified combo box
  1074. ENTRY: hLB - HWND of combo box to fill
  1075. NOTES: -Cloned from RNA UI code
  1076. -Calls InitCountryCodeList_w to do work
  1077. -Caller must call DeInitCountryCodeList when done to free buffer
  1078. -Caller should call FillCountryCodeList when the combo box
  1079. is touched to fill in the whole list of country codes
  1080. ********************************************************************/
  1081. void InitCountryCodeList(HWND hLB)
  1082. {
  1083. DEBUGMSG("rnacall.c::InitCountryCodeList()");
  1084. DWORD dwCountryCodeID;
  1085. // Load RNA if not already loaded
  1086. if (EnsureRNALoaded() != ERROR_SUCCESS)
  1087. return;
  1088. // if there is a global rasentry, set default country code to
  1089. // be the same as it... otherwise set default country code to US
  1090. if (sizeof(RASENTRY) == gpRasEntry->dwSize)
  1091. {
  1092. dwCountryCodeID = gpRasEntry->dwCountryID;
  1093. }
  1094. else
  1095. {
  1096. dwCountryCodeID = US_COUNTRY_CODE;
  1097. }
  1098. InitCountryCodeList_w(hLB,dwCountryCodeID,FALSE);
  1099. }
  1100. /*******************************************************************
  1101. NAME: FillCountryCodeList
  1102. SYNOPSIS: Fills the country code listbox with list of all
  1103. country codes
  1104. ENTRY: hLB - HWND of combo box to fill
  1105. NOTES: -Cloned from RNA UI code
  1106. -May take a while! (several seconds) This shouldn't
  1107. be called unless user plays with combo box
  1108. -Assumes InitCountryCodeList has been called
  1109. -Caller must call DeInitCountryCodeList when done to free buffer
  1110. ********************************************************************/
  1111. void FillCountryCodeList(HWND hLB)
  1112. {
  1113. DEBUGMSG("rnacall.c::FillCountryCodeList()");
  1114. LPCOUNTRYCODE lpcc;
  1115. DWORD dwSelectID;
  1116. ASSERT(fRNALoaded); // RNA should be loaded if we get here
  1117. // If we already complete the list, do nothing
  1118. if (ComboBox_GetCount(hLB) > 1)
  1119. return;
  1120. // Get the currently selected country code
  1121. if ((lpcc = (LPCOUNTRYCODE)ComboBox_GetItemData(hLB, 0)) != NULL)
  1122. {
  1123. dwSelectID = lpcc->dwCountryID;
  1124. }
  1125. else
  1126. {
  1127. dwSelectID = US_COUNTRY_CODE;
  1128. }
  1129. // free the country code buffer
  1130. DeInitCountryCodeList();
  1131. // set an hourglass cursor
  1132. WAITCURSOR WaitCursor;
  1133. // Enumerate full list of country codes
  1134. InitCountryCodeList_w(hLB, dwSelectID, TRUE);
  1135. }
  1136. /*******************************************************************
  1137. NAME: GetCountryCodeSelection
  1138. SYNOPSIS: Gets selected country code and ID based on combo box
  1139. selection and fills them in in phone number struct
  1140. ENTRY: hLB - handle of combo box
  1141. lpCountryCode - fill in with country code info
  1142. ********************************************************************/
  1143. void GetCountryCodeSelection(HWND hLB,LPCOUNTRYCODE* plpCountryCode)
  1144. {
  1145. DEBUGMSG("rnacall.c::GetCountryCodeSelection()");
  1146. ASSERT(hLB);
  1147. ASSERT(plpCountryCode);
  1148. // get index of selected item in combo box
  1149. int iSel = ComboBox_GetCurSel(hLB);
  1150. ASSERT(iSel >= 0); // should always be a selection
  1151. if (iSel >= 0)
  1152. {
  1153. // get data for item, which is pointer to country code struct
  1154. *plpCountryCode = (LPCOUNTRYCODE) ComboBox_GetItemData(hLB,iSel);
  1155. }
  1156. }
  1157. /*******************************************************************
  1158. NAME: SetCountryIDSelection
  1159. SYNOPSIS: Sets selected country code in combo box
  1160. EXIT: returns TRUE if successful, FALSE if country code not
  1161. in combo box
  1162. ********************************************************************/
  1163. BOOL SetCountryIDSelection(HWND hwndCB,DWORD dwCountryID)
  1164. {
  1165. DEBUGMSG("rnacall.c::SetCountryIDSelection()");
  1166. BOOL fRet = FALSE;
  1167. ASSERT(hwndCB);
  1168. int iCount,iIndex;
  1169. COUNTRYCODE * pcc;
  1170. // search through items in combo box until we find one that
  1171. // matches the specified country ID
  1172. iCount = ComboBox_GetCount(hwndCB);
  1173. for (iIndex = 0;iIndex < iCount;iIndex ++) {
  1174. pcc = (COUNTRYCODE *) ComboBox_GetItemData(hwndCB,iIndex);
  1175. if (pcc && pcc->dwCountryID == dwCountryID) {
  1176. ComboBox_SetCurSel(hwndCB,iIndex);
  1177. return TRUE;
  1178. }
  1179. }
  1180. return FALSE; // couldn't find country code in combo box
  1181. }
  1182. /*******************************************************************
  1183. NAME: DeInitCountryCodeList
  1184. SYNOPSIS: Frees buffer of country codes
  1185. NOTES: Call when done with combo box that displays country codes
  1186. ********************************************************************/
  1187. void DeInitCountryCodeList(VOID)
  1188. {
  1189. DEBUGMSG("rnacall.c::DeInitCountryCodeList()");
  1190. // free the country code buffer
  1191. ASSERT(gpCountryCodeBuf);
  1192. if (gpCountryCodeBuf)
  1193. {
  1194. delete gpCountryCodeBuf;
  1195. gpCountryCodeBuf = NULL;
  1196. }
  1197. }
  1198. /*******************************************************************
  1199. NAME: ShortenName
  1200. SYNOPSIS: Copies a name to a (potentially shorter) buffer;
  1201. if the name is too large it truncates it and adds "..."
  1202. NOTES: Cloned from RNA UI code
  1203. ********************************************************************/
  1204. void ShortenName(LPTSTR szLongName, LPTSTR szShortName, DWORD cbShort)
  1205. {
  1206. // DEBUGMSG("rnacall.c::ShortenName()");
  1207. static BOOL gfShortFmt = FALSE;
  1208. static TCHAR g_szShortFmt[SMALL_BUF_LEN];
  1209. static DWORD gdwShortFmt = 0;
  1210. ASSERT(szLongName);
  1211. ASSERT(szShortName);
  1212. // Get the shorten format
  1213. if (!gfShortFmt)
  1214. {
  1215. gdwShortFmt = LoadString(ghInstance, IDS_SHORT_FMT, g_szShortFmt,
  1216. SMALL_BUF_LEN);
  1217. gdwShortFmt -= 2; // lstrlen("%s")
  1218. gfShortFmt = TRUE;
  1219. };
  1220. // Check the size of the long name
  1221. if ((DWORD)lstrlen(szLongName)+1 <= cbShort)
  1222. {
  1223. // The name is shorter than the specified size, copy back the name
  1224. lstrcpy(szShortName, szLongName);
  1225. } else {
  1226. BUFFER bufShorten(cbShort*2);
  1227. ASSERT(bufShorten);
  1228. if (bufShorten) {
  1229. lstrcpyn(bufShorten.QueryPtr(), szLongName, cbShort-gdwShortFmt);
  1230. wsprintf(szShortName, g_szShortFmt,bufShorten.QueryPtr());
  1231. } else {
  1232. lstrcpyn(szShortName, szLongName, cbShort);
  1233. }
  1234. }
  1235. }
  1236. /*******************************************************************
  1237. NAME: EnsureRNALoaded
  1238. SYNOPSIS: Loads RNA if not already loaded
  1239. ********************************************************************/
  1240. DWORD EnsureRNALoaded(VOID)
  1241. {
  1242. DEBUGMSG("rnacall.c::EnsureRNALoaded()");
  1243. DWORD dwRet = ERROR_SUCCESS;
  1244. // load RNA if necessary
  1245. if (!fRNALoaded) {
  1246. if (InitRNA(NULL))
  1247. fRNALoaded = TRUE;
  1248. else return ERROR_FILE_NOT_FOUND;
  1249. }
  1250. return dwRet;
  1251. }
  1252. /*******************************************************************
  1253. NAME: ENUM_MODEM::ENUM_MODEM
  1254. SYNOPSIS: Constructor for class to enumerate modems
  1255. NOTES: Useful to have a class rather than C functions for
  1256. this, due to how the enumerators function
  1257. ********************************************************************/
  1258. ENUM_MODEM::ENUM_MODEM() :
  1259. m_dwError(ERROR_SUCCESS),m_lpData(NULL),m_dwIndex(0)
  1260. {
  1261. DWORD cbSize = 0;
  1262. // Use the reinit member function to do the work.
  1263. this->ReInit();
  1264. }
  1265. /*******************************************************************
  1266. NAME: ENUM_MODEM::ReInit
  1267. SYNOPSIS: Re-enumerate the modems, freeing the old memory.
  1268. ********************************************************************/
  1269. DWORD ENUM_MODEM::ReInit()
  1270. {
  1271. DWORD cbSize = 0;
  1272. // Clean up the old list
  1273. if (m_lpData)
  1274. {
  1275. delete m_lpData;
  1276. m_lpData = NULL;
  1277. }
  1278. m_dwNumEntries = 0;
  1279. m_dwIndex = 0;
  1280. // call RasEnumDevices with no buffer to find out required buffer size
  1281. ASSERT(lpRasEnumDevices);
  1282. m_dwError = lpRasEnumDevices(NULL, &cbSize, &m_dwNumEntries);
  1283. // Special case check to work around RNA bug where ERROR_BUFFER_TOO_SMALL
  1284. // is returned even if there are no devices.
  1285. // If there are no devices, we are finished.
  1286. if (0 == m_dwNumEntries)
  1287. {
  1288. m_dwError = ERROR_SUCCESS;
  1289. return m_dwError;
  1290. }
  1291. // Since we were just checking how much mem we needed, we expect
  1292. // a return value of ERROR_BUFFER_TOO_SMALL, or it may just return
  1293. // ERROR_SUCCESS (ChrisK 7/9/96).
  1294. if (ERROR_BUFFER_TOO_SMALL != m_dwError && ERROR_SUCCESS != m_dwError)
  1295. {
  1296. return m_dwError;
  1297. }
  1298. // Allocate the space for the data
  1299. m_lpData = (LPRASDEVINFO) new TCHAR[cbSize];
  1300. if (NULL == m_lpData)
  1301. {
  1302. DEBUGTRAP("ENUM_MODEM: Failed to allocate device list buffer");
  1303. m_dwError = ERROR_NOT_ENOUGH_MEMORY;
  1304. return m_dwError;
  1305. }
  1306. m_lpData->dwSize = sizeof(RASDEVINFO);
  1307. m_dwNumEntries = 0;
  1308. // enumerate the modems into buffer
  1309. m_dwError = lpRasEnumDevices(m_lpData, &cbSize,
  1310. &m_dwNumEntries);
  1311. if (ERROR_SUCCESS != m_dwError)
  1312. return m_dwError;
  1313. //
  1314. // ChrisK Olympus 4560 do not include VPN's in the list
  1315. //
  1316. DWORD dwTempNumEntries;
  1317. DWORD idx;
  1318. LPRASDEVINFO lpNextValidDevice;
  1319. dwTempNumEntries = m_dwNumEntries;
  1320. lpNextValidDevice = m_lpData;
  1321. //
  1322. // Walk through the list of devices and copy non-VPN device to the first
  1323. // available element of the array.
  1324. //
  1325. for (idx = 0;idx < dwTempNumEntries; idx++)
  1326. {
  1327. // We only want to show Modem and ISDN (or ADSL in future) device type
  1328. // in this dialog.
  1329. //
  1330. // char b[400];
  1331. // wsprintf(b, "Type:%s, Name:%s", m_lpData[idx].szDeviceType, m_lpData[idx].szDeviceName);
  1332. // MessageBox(0, b, "Devices", MB_OK);
  1333. //
  1334. if ((0 == lstrcmpi(TEXT("MODEM"),m_lpData[idx].szDeviceType)) ||
  1335. (0 == lstrcmpi(TEXT("ISDN"),m_lpData[idx].szDeviceType)))
  1336. {
  1337. if (lpNextValidDevice != &m_lpData[idx])
  1338. {
  1339. MoveMemory(lpNextValidDevice ,&m_lpData[idx],sizeof(RASDEVINFO));
  1340. }
  1341. lpNextValidDevice++;
  1342. }
  1343. else
  1344. {
  1345. m_dwNumEntries--;
  1346. }
  1347. }
  1348. return m_dwError;
  1349. }
  1350. /*******************************************************************
  1351. NAME: ENUM_MODEM::~ENUM_MODEM
  1352. SYNOPSIS: Destructor for class
  1353. ********************************************************************/
  1354. ENUM_MODEM::~ENUM_MODEM()
  1355. {
  1356. if (m_lpData)
  1357. {
  1358. delete m_lpData;
  1359. m_lpData = NULL;
  1360. }
  1361. }
  1362. /*******************************************************************
  1363. NAME: ENUM_MODEM::Next
  1364. SYNOPSIS: Enumerates next modem
  1365. EXIT: Returns a pointer to device info structure. Returns
  1366. NULL if no more modems or error occurred. Call GetError
  1367. to determine if error occurred.
  1368. ********************************************************************/
  1369. TCHAR * ENUM_MODEM::Next()
  1370. {
  1371. if (m_dwIndex < m_dwNumEntries)
  1372. {
  1373. return m_lpData[m_dwIndex++].szDeviceName;
  1374. }
  1375. return NULL;
  1376. }
  1377. /*******************************************************************
  1378. NAME: ENUM_MODEM::GetDeviceTypeFromName
  1379. SYNOPSIS: Returns type string for specified device.
  1380. EXIT: Returns a pointer to device type string for first
  1381. device name that matches. Returns
  1382. NULL if no device with specified name is found
  1383. ********************************************************************/
  1384. TCHAR * ENUM_MODEM::GetDeviceTypeFromName(LPTSTR szDeviceName)
  1385. {
  1386. DWORD dwIndex = 0;
  1387. while (dwIndex < m_dwNumEntries)
  1388. {
  1389. if (!lstrcmp(m_lpData[dwIndex].szDeviceName, szDeviceName))
  1390. {
  1391. return m_lpData[dwIndex].szDeviceType;
  1392. }
  1393. dwIndex++;
  1394. }
  1395. return NULL;
  1396. }
  1397. /*******************************************************************
  1398. NAME: ENUM_MODEM::GetDeviceNameFromType
  1399. SYNOPSIS: Returns type string for specified device.
  1400. EXIT: Returns a pointer to device name string for first
  1401. device type that matches. Returns
  1402. NULL if no device with specified Type is found
  1403. ********************************************************************/
  1404. TCHAR * ENUM_MODEM::GetDeviceNameFromType(LPTSTR szDeviceType)
  1405. {
  1406. DWORD dwIndex = 0;
  1407. while (dwIndex < m_dwNumEntries)
  1408. {
  1409. if (!lstrcmp(m_lpData[dwIndex].szDeviceType, szDeviceType))
  1410. {
  1411. return m_lpData[dwIndex].szDeviceName;
  1412. }
  1413. dwIndex++;
  1414. }
  1415. return NULL;
  1416. }
  1417. /*******************************************************************
  1418. NAME: ENUM_MODEM::VerifyDeviceNameAndType
  1419. SYNOPSIS: Determines whether there is a device with the name
  1420. and type given.
  1421. EXIT: Returns TRUE if the specified device was found,
  1422. FALSE otherwise.
  1423. ********************************************************************/
  1424. BOOL ENUM_MODEM::VerifyDeviceNameAndType(LPTSTR szDeviceName, LPTSTR szDeviceType)
  1425. {
  1426. DWORD dwIndex = 0;
  1427. while (dwIndex < m_dwNumEntries)
  1428. {
  1429. if (!lstrcmp(m_lpData[dwIndex].szDeviceType, szDeviceType) &&
  1430. !lstrcmp(m_lpData[dwIndex].szDeviceName, szDeviceName))
  1431. {
  1432. return TRUE;
  1433. }
  1434. dwIndex++;
  1435. }
  1436. return FALSE;
  1437. }
  1438. /*******************************************************************
  1439. NAME: ENUM_CONNECTOID::ENUM_CONNECTOID
  1440. SYNOPSIS: Constructor for class to enumerate connectoids
  1441. NOTES: Useful to have a class rather than C functions for
  1442. this, due to how the enumerators function
  1443. ********************************************************************/
  1444. ENUM_CONNECTOID::ENUM_CONNECTOID() :
  1445. m_dwError(ERROR_SUCCESS),m_dwNumEntries(0),m_lpData(NULL),m_dwIndex(0)
  1446. {
  1447. DWORD cbSize;
  1448. RASENTRYNAME rasEntryName;
  1449. cbSize = sizeof(RASENTRYNAME);
  1450. rasEntryName.dwSize = cbSize;
  1451. // call RasEnumEntries with a temp structure. this will not likely
  1452. // be big enough, but cbSize will be filled with the required size
  1453. ASSERT(lpRasEnumEntries);
  1454. m_dwError = lpRasEnumEntries(NULL, NULL, &rasEntryName,
  1455. &cbSize, &m_dwNumEntries);
  1456. if ((ERROR_BUFFER_TOO_SMALL != m_dwError) &&
  1457. (ERROR_SUCCESS != m_dwError))
  1458. {
  1459. return;
  1460. }
  1461. // Make sure that there is at least enough room for the structure
  1462. // (RasEnumEntries will return 0 as cbSize if there are no entries)
  1463. cbSize = (cbSize > sizeof(RASENTRYNAME)) ? cbSize : sizeof(RASENTRYNAME);
  1464. // Allocate the space for the data
  1465. m_lpData = (LPRASENTRYNAME) new TCHAR[cbSize];
  1466. if (NULL == m_lpData)
  1467. {
  1468. DEBUGTRAP("ENUM_CONNECTOID: Failed to allocate connectoid list buffer");
  1469. m_dwError = ERROR_NOT_ENOUGH_MEMORY;
  1470. return;
  1471. }
  1472. m_lpData->dwSize = sizeof(RASENTRYNAME);
  1473. m_dwNumEntries = 0;
  1474. // enumerate the connectoids into buffer
  1475. m_dwError = lpRasEnumEntries(NULL, NULL, m_lpData, &cbSize, &m_dwNumEntries);
  1476. if (IsNT5())
  1477. {
  1478. DWORD dwNumEntries = 0;
  1479. if (ERROR_SUCCESS == m_dwError && m_dwNumEntries)
  1480. {
  1481. for(DWORD dwIndx=0; dwIndx < m_dwNumEntries; dwIndx++)
  1482. {
  1483. LPRASENTRY lpRasEntry = NULL;
  1484. DWORD dwRasEntrySize = 0;
  1485. if (GetEntry(&lpRasEntry, &dwRasEntrySize, m_lpData[dwIndx].szEntryName) == ERROR_SUCCESS)
  1486. {
  1487. // check connection type
  1488. if ((0 != lstrcmpi(TEXT("MODEM"), lpRasEntry->szDeviceType)) &&
  1489. (0 != lstrcmpi(TEXT("ISDN"), lpRasEntry->szDeviceType)))
  1490. *(m_lpData[dwIndx].szEntryName) = 0;
  1491. else
  1492. dwNumEntries++;
  1493. }
  1494. //
  1495. // Release memory
  1496. //
  1497. if (NULL != lpRasEntry)
  1498. {
  1499. GlobalFree(lpRasEntry);
  1500. lpRasEntry = NULL;
  1501. }
  1502. } // End for loop
  1503. m_dwNumEntries = dwNumEntries;
  1504. }
  1505. }
  1506. }
  1507. /*******************************************************************
  1508. NAME: ENUM_CONNECTOID::~ENUM_CONNECTOID
  1509. SYNOPSIS: Destructor for class
  1510. ********************************************************************/
  1511. ENUM_CONNECTOID::~ENUM_CONNECTOID()
  1512. {
  1513. if (m_lpData)
  1514. {
  1515. delete m_lpData;
  1516. m_lpData = NULL;
  1517. }
  1518. }
  1519. /*******************************************************************
  1520. NAME: ENUM_CONNECTOID::Next
  1521. SYNOPSIS: Enumerates next connectoid
  1522. EXIT: Returns a pointer to connectoid name. Returns NULL
  1523. if no more connectoids or error occurred. Call GetError
  1524. to determine if error occurred.
  1525. ********************************************************************/
  1526. TCHAR * ENUM_CONNECTOID::Next()
  1527. {
  1528. while (m_dwIndex < m_dwNumEntries)
  1529. {
  1530. if (0 == *(m_lpData[m_dwIndex].szEntryName))
  1531. {
  1532. m_dwIndex++;
  1533. }
  1534. else
  1535. {
  1536. return m_lpData[m_dwIndex++].szEntryName;
  1537. }
  1538. }
  1539. return NULL;
  1540. }
  1541. /*******************************************************************
  1542. NAME: ENUM_CONNECTOID::NumEntries
  1543. SYNOPSIS: returns number of connectoids stored in this instance
  1544. EXIT: Returns value of m_dwNumEntries
  1545. HISTORY: 11/11/96 jmazner Created.
  1546. ********************************************************************/
  1547. DWORD ENUM_CONNECTOID::NumEntries()
  1548. {
  1549. return m_dwNumEntries;
  1550. }
  1551. //+----------------------------------------------------------------------------
  1552. // Function: FRasValidatePatch
  1553. //
  1554. // Synopsis: With all of the other Ras functions there exists a common entry
  1555. // point for WinNT and Win95, usually the A version. However,
  1556. // RasValidateEntryName only has an A and W version on WinNT and
  1557. // an unqualified version on Win95. Therefore we have to do some
  1558. // special processing to try to find it
  1559. //
  1560. // Input: ppFP - Location to save function point to
  1561. // hInst1 - First DLL to check for entry point
  1562. // hInst2 - Second DLL to check for entry point
  1563. // lpszName - Name of the function (if it isn't RasValidateEntryName)
  1564. // we just skip it and move on.
  1565. //
  1566. // Return: TRUE - success
  1567. //
  1568. // History: 7/3/96 Created, ChrisK
  1569. //
  1570. //-----------------------------------------------------------------------------
  1571. BOOL FRasValidatePatch(PVOID *ppFP, HINSTANCE hInst1, HINSTANCE hInst2, LPCSTR lpszName)
  1572. {
  1573. BOOL bRC = TRUE;
  1574. //
  1575. // Validate parameters
  1576. //
  1577. if (ppFP && hInst1 && lpszName)
  1578. {
  1579. //
  1580. // Check that we are really looking for RasValidateEntryName
  1581. //
  1582. if (0 == lstrcmpA(lpszName,szRasValidateEntryName))
  1583. {
  1584. //
  1585. // Find entry point with alternate name
  1586. //
  1587. *ppFP = GetProcAddress(hInst1,szRasValidateEntryName);
  1588. if (!*ppFP && hInst2)
  1589. *ppFP = GetProcAddress(hInst2,szRasValidateEntryName);
  1590. if (!*ppFP)
  1591. {
  1592. DEBUGMSG("INETCFG: FRasValidatePatch entry point not found is either DLL.\n");
  1593. bRC = FALSE;
  1594. }
  1595. }
  1596. else
  1597. {
  1598. bRC = FALSE;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. DEBUGMSG("INETCFG: FRasValidatePatch invalid parameters.\n");
  1604. bRC = FALSE;
  1605. }
  1606. //FRasValidatePatchExit:
  1607. return bRC;
  1608. }
  1609. /*******************************************************************
  1610. NAME: GetApiProcAddresses
  1611. SYNOPSIS: Gets proc addresses for a table of functions
  1612. EXIT: returns TRUE if successful, FALSE if unable to retrieve
  1613. any proc address in table
  1614. HISTORY:
  1615. 96/02/28 markdu If the api is not found in the module passed in,
  1616. try the backup (RNAPH.DLL)
  1617. ********************************************************************/
  1618. BOOL GetApiProcAddresses(HMODULE hModDLL,APIFCN * pApiProcList,UINT nApiProcs)
  1619. {
  1620. DEBUGMSG("rnacall.c::GetApiProcAddresses()");
  1621. UINT nIndex;
  1622. // cycle through the API table and get proc addresses for all the APIs we
  1623. // need
  1624. for (nIndex = 0;nIndex < nApiProcs;nIndex++)
  1625. {
  1626. if (!(*pApiProcList[nIndex].ppFcnPtr = (PVOID) GetProcAddress(hModDLL,
  1627. pApiProcList[nIndex].pszName)))
  1628. {
  1629. // Try to find the address in RNAPH.DLL. This is useful in the
  1630. // case thatRASAPI32.DLL did not contain the function that we
  1631. // were trying to load.
  1632. if (FALSE == IsNT())
  1633. {
  1634. if (!ghInstRNAPHDll)
  1635. {
  1636. TCHAR szRNAPHDll[SMALL_BUF_LEN];
  1637. LoadSz(IDS_RNAPHDLL_FILENAME,szRNAPHDll,ARRAYSIZE(szRNAPHDll));
  1638. ghInstRNAPHDll = LoadLibrary(szRNAPHDll);
  1639. }
  1640. if ((!ghInstRNAPHDll) || !(*pApiProcList[nIndex].ppFcnPtr =
  1641. (PVOID) GetProcAddress(ghInstRNAPHDll,pApiProcList[nIndex].pszName)))
  1642. {
  1643. if (!FRasValidatePatch(pApiProcList[nIndex].ppFcnPtr, hModDLL,
  1644. ghInstRNAPHDll, pApiProcList[nIndex].pszName))
  1645. {
  1646. DEBUGMSG("Unable to get address of function %s",
  1647. pApiProcList[nIndex].pszName);
  1648. for (nIndex = 0;nIndex<nApiProcs;nIndex++)
  1649. *pApiProcList[nIndex].ppFcnPtr = NULL;
  1650. return FALSE;
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. return TRUE;
  1657. }
  1658. /*******************************************************************
  1659. NAME: GetRNAErrorText
  1660. SYNOPSIS: Gets text string corresponding to RNA error code
  1661. ENTRY: uErr - RNA error code
  1662. pszErrText - buffer to retrieve error text description
  1663. cbErrText - size of pszErrText buffer
  1664. ********************************************************************/
  1665. VOID GetRNAErrorText(UINT uErr,TCHAR * pszErrText,DWORD cbErrText)
  1666. {
  1667. DEBUGMSG("rnacall.c::GetRNAErrorText()");
  1668. ASSERT(pszErrText);
  1669. ASSERT(lpRasGetErrorString);
  1670. DWORD dwRet = lpRasGetErrorString(uErr,pszErrText,cbErrText);
  1671. if (dwRet != ERROR_SUCCESS) {
  1672. // if we couldn't get real error text, then make generic string
  1673. // with the error number
  1674. TCHAR szFmt[SMALL_BUF_LEN+1];
  1675. LoadSz(IDS_GENERIC_RNA_ERROR,szFmt,ARRAYSIZE(szFmt));
  1676. wsprintf(pszErrText,szFmt,uErr);
  1677. }
  1678. }
  1679. /* S W A P D W B Y T E S Taken from rnaph.c */
  1680. /*----------------------------------------------------------------------------
  1681. %%Function: SwapDwBytes
  1682. Swap the bytes of a DWORD.
  1683. (BSWAP isn't available on a 386)
  1684. ----------------------------------------------------------------------------*/
  1685. VOID SwapDwBytes(LPDWORD lpdw)
  1686. {
  1687. IADDR iaddr;
  1688. iaddr.ia.a = ((PIADDR) lpdw)->ia.d;
  1689. iaddr.ia.b = ((PIADDR) lpdw)->ia.c;
  1690. iaddr.ia.c = ((PIADDR) lpdw)->ia.b;
  1691. iaddr.ia.d = ((PIADDR) lpdw)->ia.a;
  1692. *lpdw = iaddr.dw;
  1693. }
  1694. /* C O P Y D W 2 I A Taken from rnaph.c */
  1695. /*----------------------------------------------------------------------------
  1696. %%Function: CopyDw2Ia
  1697. Convert a DWORD to an Internet Address
  1698. ----------------------------------------------------------------------------*/
  1699. VOID CopyDw2Ia(DWORD dw, RASIPADDR* pia)
  1700. {
  1701. SwapDwBytes(&dw);
  1702. *pia = ((PIADDR) &dw)->ia;
  1703. }
  1704. /* D W F R O M I A Taken from rnaph.c */
  1705. /*----------------------------------------------------------------------------
  1706. %%Function: DwFromIa
  1707. Convert an Internet Address to a DWORD
  1708. ----------------------------------------------------------------------------*/
  1709. DWORD DwFromIa(RASIPADDR *pia)
  1710. {
  1711. IADDR iaddr;
  1712. iaddr.dw = * (LPDWORD) pia;
  1713. SwapDwBytes(&iaddr.dw);
  1714. return iaddr.dw;
  1715. }
  1716. /* F V A L I D I A Taken from rnaph.c */
  1717. /*----------------------------------------------------------------------------
  1718. %%Function: FValidIa
  1719. Return TRUE if the IP address is valid
  1720. ----------------------------------------------------------------------------*/
  1721. BOOL FValidIa(RASIPADDR *pia)
  1722. {
  1723. BYTE b;
  1724. b = ((PIADDR) pia)->ia.a;
  1725. if (b < MIN_IP_FIELD1 || b > MAX_IP_FIELD1 || b == 127)
  1726. return FALSE;
  1727. b = ((PIADDR) pia)->ia.d;
  1728. if (b > MAX_IP_FIELD4)
  1729. return FALSE;
  1730. return TRUE;
  1731. }
  1732. /*******************************************************************
  1733. NAME: SwapDwBits
  1734. SYNOPSIS: Swap the values of the specified bits
  1735. ENTRY: lpdw - address of DWORD with bits to be swapped
  1736. dwBit1 - mask for first bit
  1737. dwBit2 - mask for second bit
  1738. HISTORY:
  1739. 96/05/14 markdu NASH BUG 22730 Created to work around RNA bug.
  1740. ********************************************************************/
  1741. void SwapDWBits(LPDWORD lpdw, DWORD dwBit1, DWORD dwBit2)
  1742. {
  1743. ASSERT(lpdw);
  1744. // Only need to swap if exactly one of the two bits is set since
  1745. // otherwise the bits are identical.
  1746. if (((*lpdw & dwBit1) &&
  1747. !(*lpdw & dwBit2)) ||
  1748. (!(*lpdw & dwBit1) &&
  1749. (*lpdw & dwBit2)))
  1750. {
  1751. // Since only one of the two bits was set, we can simulate the swap
  1752. // by flipping each bit.
  1753. *lpdw ^= dwBit1;
  1754. *lpdw ^= dwBit2;
  1755. }
  1756. }
  1757. //+----------------------------------------------------------------------------
  1758. //
  1759. // Function: InitTAPILocation
  1760. //
  1761. // Synopsis: Ensure that TAPI location information is configured correctly;
  1762. // if not, prompt user to fill it in.
  1763. //
  1764. // Arguments: hwndParent -- parent window for TAPI dialog to use
  1765. // (_must_ be a valid window HWND, see note below)
  1766. //
  1767. // Returns: void
  1768. //
  1769. // Notes: The docs for lineTranslateDialog lie when they say that the
  1770. // fourth parameter (hwndOwner) can be null. In fact, if this
  1771. // is null, the call will return with LINEERR_INVALPARAM.
  1772. //
  1773. //
  1774. // History: 7/15/97 jmazner Created for Olympus #6294
  1775. //
  1776. //-----------------------------------------------------------------------------
  1777. BOOL InitTAPILocation(HWND hwndParent)
  1778. {
  1779. HLINEAPP hLineApp=NULL;
  1780. TCHAR szTempCountryCode[8];
  1781. TCHAR szTempCityCode[8];
  1782. BOOL bRetVal = TRUE;
  1783. DWORD dwTapiErr = 0;
  1784. DWORD cDevices=0;
  1785. DWORD dwCurDevice = 0;
  1786. ASSERT( IsWindow(hwndParent) );
  1787. //
  1788. // see if we can get location info from TAPI
  1789. //
  1790. dwTapiErr = tapiGetLocationInfo(szTempCountryCode,szTempCityCode);
  1791. if( 0 != dwTapiErr )
  1792. {
  1793. //
  1794. // GetLocation failed. let's try calling the TAPI mini dialog. Note
  1795. // that when called in this fashion, the dialog has _no_ cancel option,
  1796. // the user is forced to enter info and hit OK.
  1797. //
  1798. DEBUGMSG("InitTAPILocation, tapiGetLocationInfo failed");
  1799. dwTapiErr = lineInitialize(&hLineApp,ghInstance,LineCallback," ",&cDevices);
  1800. if (dwTapiErr == ERROR_SUCCESS)
  1801. {
  1802. //
  1803. // loop through all TAPI devices and try to call lineTranslateDialog
  1804. // The call might fail for VPN devices, thus we want to try every
  1805. // device until we get a success.
  1806. //
  1807. dwTapiErr = LINEERR_INVALPARAM;
  1808. while( (dwTapiErr != 0) && (dwCurDevice < cDevices) )
  1809. {
  1810. BOOL bIsNT5 = IsNT5();
  1811. if (bIsNT5)
  1812. EnableWindow(hwndParent, FALSE);
  1813. dwTapiErr = lineTranslateDialog(hLineApp,dwCurDevice,0x10004,hwndParent,NULL);
  1814. if (bIsNT5)
  1815. EnableWindow(hwndParent, TRUE);
  1816. if( 0 != dwTapiErr )
  1817. {
  1818. DEBUGMSG("InitTAPILocation, lineTranslateDialog on device %d failed with err = %d!",
  1819. dwCurDevice, dwTapiErr);
  1820. if (bIsNT5)
  1821. {
  1822. bRetVal = FALSE;
  1823. break;
  1824. }
  1825. }
  1826. dwCurDevice++;
  1827. }
  1828. }
  1829. else
  1830. {
  1831. DEBUGMSG("InitTAPILocation, lineInitialize failed with err = %d", dwTapiErr);
  1832. }
  1833. dwTapiErr = tapiGetLocationInfo(szTempCountryCode,szTempCityCode);
  1834. if( 0 != dwTapiErr )
  1835. {
  1836. DEBUGMSG("InitTAPILocation still failed on GetLocationInfo, bummer.");
  1837. }
  1838. else
  1839. {
  1840. DEBUGMSG("InitTAPILocation, TAPI location is initialized now");
  1841. }
  1842. }
  1843. if( hLineApp )
  1844. {
  1845. lineShutdown(hLineApp);
  1846. hLineApp = NULL;
  1847. }
  1848. return bRetVal;
  1849. }