Source code of Windows XP (NT5)
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.

617 lines
17 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright (c) 1994-1998 Microsoft Corporation
  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. // instance handle must be in per-instance data segment
  58. #pragma data_seg(DATASEG_PERINSTANCE)
  59. // Global variables
  60. HINSTANCE ghInstRNADll=NULL; // handle to RNA dll we load explicitly
  61. HINSTANCE ghInstRNAPHDll=NULL; // handle to RNAPH dll we load explicitly
  62. DWORD dwRefCount=0;
  63. BOOL fRNALoaded=FALSE; // TRUE if RNA function addresses have been loaded
  64. // global function pointers for RNA apis
  65. RASENUMDEVICES lpRasEnumDevices=NULL;
  66. RASENUMENTRIES lpRasEnumEntries=NULL;
  67. // API table for function addresses to fetch
  68. #define NUM_RNAAPI_PROCS 2
  69. APIFCN RnaApiList[NUM_RNAAPI_PROCS] =
  70. {
  71. { (PVOID *) &lpRasEnumDevices,"RasEnumDevicesA"},
  72. { (PVOID *) &lpRasEnumEntries,"RasEnumEntriesA"}
  73. };
  74. #pragma data_seg(DATASEG_DEFAULT)
  75. ENUM_MODEM * gpEnumModem=NULL; // pointer modem enumeration object
  76. BOOL GetApiProcAddresses(HMODULE hModDLL,APIFCN * pApiProcList,UINT nApiProcs);
  77. static const CHAR szRegValRNAWizard[] = "wizard";
  78. static const CHAR szRegPathRNAWizard[] = REGSTR_PATH_REMOTEACCESS;
  79. /*******************************************************************
  80. NAME: InitRNA
  81. SYNOPSIS: Loads the RNA dll (RASAPI32), gets proc addresses,
  82. and loads RNA engine
  83. EXIT: TRUE if successful, or FALSE if fails. Displays its
  84. own error message upon failure.
  85. NOTES: We load the RNA dll explicitly and get proc addresses
  86. because these are private APIs and not guaranteed to
  87. be supported beyond Windows 95. This way, if the DLL
  88. isn't there or the entry points we expect aren't there,
  89. we can display a coherent message instead of the weird
  90. Windows dialog you get if implicit function addresses
  91. can't be resolved.
  92. ********************************************************************/
  93. BOOL InitRNA(HWND hWnd)
  94. {
  95. DEBUGMSG("rnacall.c::InitRNA()");
  96. // only actually do init stuff on first call to this function
  97. // (when reference count is 0), just increase reference count
  98. // for subsequent calls
  99. if (dwRefCount == 0) {
  100. CHAR szRNADll[SMALL_BUF_LEN];
  101. DEBUGMSG("Loading RNA DLL");
  102. // set an hourglass cursor
  103. WAITCURSOR WaitCursor;
  104. // get the filename (RASAPI32.DLL) out of resource
  105. LoadSz(IDS_RNADLL_FILENAME,szRNADll,sizeof(szRNADll));
  106. // load the RNA api dll
  107. ghInstRNADll = LoadLibrary(szRNADll);
  108. if (!ghInstRNADll) {
  109. UINT uErr = GetLastError();
  110. DisplayErrorMessage(hWnd,IDS_ERRLoadRNADll1,uErr,ERRCLS_STANDARD,
  111. MB_ICONSTOP);
  112. return FALSE;
  113. }
  114. // cycle through the API table and get proc addresses for all the APIs we
  115. // need
  116. if (!GetApiProcAddresses(ghInstRNADll,RnaApiList,NUM_RNAAPI_PROCS)) {
  117. MsgBox(hWnd,IDS_ERRLoadRNADll2,MB_ICONSTOP,MB_OK);
  118. DeInitRNA();
  119. return FALSE;
  120. }
  121. }
  122. fRNALoaded = TRUE;
  123. dwRefCount ++;
  124. return TRUE;
  125. }
  126. /*******************************************************************
  127. NAME: DeInitRNA
  128. SYNOPSIS: Unloads RNA dll.
  129. ********************************************************************/
  130. VOID DeInitRNA()
  131. {
  132. DEBUGMSG("rnacall.c::DeInitRNA()");
  133. UINT nIndex;
  134. // decrement reference count
  135. if (dwRefCount)
  136. dwRefCount --;
  137. // when the reference count hits zero, do real deinitialization stuff
  138. if (dwRefCount == 0)
  139. {
  140. if (fRNALoaded)
  141. {
  142. // set function pointers to NULL
  143. for (nIndex = 0;nIndex<NUM_RNAAPI_PROCS;nIndex++)
  144. *RnaApiList[nIndex].ppFcnPtr = NULL;
  145. fRNALoaded = FALSE;
  146. }
  147. // free the RNA dll
  148. if (ghInstRNADll)
  149. {
  150. DEBUGMSG("Unloading RNA DLL");
  151. FreeLibrary(ghInstRNADll);
  152. ghInstRNADll = NULL;
  153. }
  154. // free the RNAPH dll
  155. if (ghInstRNAPHDll)
  156. {
  157. DEBUGMSG("Unloading RNAPH DLL");
  158. FreeLibrary(ghInstRNAPHDll);
  159. ghInstRNAPHDll = NULL;
  160. }
  161. }
  162. }
  163. VOID FAR PASCAL LineCallback(DWORD hDevice, DWORD dwMsg,
  164. DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2,
  165. DWORD dwParam3)
  166. {
  167. return;
  168. }
  169. /*******************************************************************
  170. NAME: EnsureRNALoaded
  171. SYNOPSIS: Loads RNA if not already loaded
  172. ********************************************************************/
  173. DWORD EnsureRNALoaded(VOID)
  174. {
  175. DEBUGMSG("rnacall.c::EnsureRNALoaded()");
  176. DWORD dwRet = ERROR_SUCCESS;
  177. // load RNA if necessary
  178. if (!fRNALoaded) {
  179. if (InitRNA(NULL))
  180. fRNALoaded = TRUE;
  181. else return ERROR_FILE_NOT_FOUND;
  182. }
  183. return dwRet;
  184. }
  185. /*******************************************************************
  186. NAME: ENUM_MODEM::ENUM_MODEM
  187. SYNOPSIS: Constructor for class to enumerate modems
  188. NOTES: Useful to have a class rather than C functions for
  189. this, due to how the enumerators function
  190. ********************************************************************/
  191. ENUM_MODEM::ENUM_MODEM() :
  192. m_dwError(ERROR_SUCCESS),m_lpData(NULL),m_dwIndex(0)
  193. {
  194. DWORD cbSize = 0;
  195. // Use the reinit member function to do the work.
  196. this->ReInit();
  197. }
  198. /*******************************************************************
  199. NAME: ENUM_MODEM::ReInit
  200. SYNOPSIS: Re-enumerate the modems, freeing the old memory.
  201. ********************************************************************/
  202. DWORD ENUM_MODEM::ReInit()
  203. {
  204. DWORD cbSize = 0;
  205. // Clean up the old list
  206. if (m_lpData)
  207. {
  208. delete m_lpData;
  209. m_lpData = NULL;
  210. }
  211. m_dwNumEntries = 0;
  212. m_dwIndex = 0;
  213. // call RasEnumDevices with no buffer to find out required buffer size
  214. ASSERT(lpRasEnumDevices);
  215. m_dwError = lpRasEnumDevices(NULL, &cbSize, &m_dwNumEntries);
  216. // Special case check to work around RNA bug where ERROR_BUFFER_TOO_SMALL
  217. // is returned even if there are no devices.
  218. // If there are no devices, we are finished.
  219. if (0 == m_dwNumEntries)
  220. {
  221. m_dwError = ERROR_SUCCESS;
  222. return m_dwError;
  223. }
  224. // Since we were just checking how much mem we needed, we expect
  225. // a return value of ERROR_BUFFER_TOO_SMALL, or it may just return
  226. // ERROR_SUCCESS (ChrisK 7/9/96).
  227. if (ERROR_BUFFER_TOO_SMALL != m_dwError && ERROR_SUCCESS != m_dwError)
  228. {
  229. return m_dwError;
  230. }
  231. // Allocate the space for the data
  232. m_lpData = (LPRASDEVINFO) new CHAR[cbSize];
  233. if (NULL == m_lpData)
  234. {
  235. DEBUGTRAP("ENUM_MODEM: Failed to allocate device list buffer");
  236. m_dwError = ERROR_NOT_ENOUGH_MEMORY;
  237. return m_dwError;
  238. }
  239. m_lpData->dwSize = sizeof(RASDEVINFO);
  240. m_dwNumEntries = 0;
  241. // enumerate the modems into buffer
  242. m_dwError = lpRasEnumDevices(m_lpData, &cbSize,
  243. &m_dwNumEntries);
  244. if (ERROR_SUCCESS != m_dwError)
  245. return m_dwError;
  246. //
  247. // ChrisK Olympus 4560 do not include VPN's in the list
  248. //
  249. DWORD dwTempNumEntries;
  250. DWORD idx;
  251. LPRASDEVINFO lpNextValidDevice;
  252. dwTempNumEntries = m_dwNumEntries;
  253. lpNextValidDevice = m_lpData;
  254. //
  255. // Walk through the list of devices and copy non-VPN device to the first
  256. // available element of the array.
  257. //
  258. for (idx = 0;idx < dwTempNumEntries; idx++)
  259. {
  260. if (0 != lstrcmpi("VPN",m_lpData[idx].szDeviceType))
  261. {
  262. if (lpNextValidDevice != &m_lpData[idx])
  263. {
  264. MoveMemory(lpNextValidDevice ,&m_lpData[idx],sizeof(RASDEVINFO));
  265. }
  266. lpNextValidDevice++;
  267. }
  268. else
  269. {
  270. m_dwNumEntries--;
  271. }
  272. }
  273. return m_dwError;
  274. }
  275. /*******************************************************************
  276. NAME: ENUM_MODEM::~ENUM_MODEM
  277. SYNOPSIS: Destructor for class
  278. ********************************************************************/
  279. ENUM_MODEM::~ENUM_MODEM()
  280. {
  281. if (m_lpData)
  282. {
  283. delete m_lpData;
  284. m_lpData = NULL;
  285. }
  286. }
  287. /*******************************************************************
  288. NAME: ENUM_MODEM::Next
  289. SYNOPSIS: Enumerates next modem
  290. EXIT: Returns a pointer to device info structure. Returns
  291. NULL if no more modems or error occurred. Call GetError
  292. to determine if error occurred.
  293. ********************************************************************/
  294. CHAR * ENUM_MODEM::Next()
  295. {
  296. if (m_dwIndex < m_dwNumEntries)
  297. {
  298. return m_lpData[m_dwIndex++].szDeviceName;
  299. }
  300. return NULL;
  301. }
  302. /*******************************************************************
  303. NAME: ENUM_MODEM::GetDeviceTypeFromName
  304. SYNOPSIS: Returns type string for specified device.
  305. EXIT: Returns a pointer to device type string for first
  306. device name that matches. Returns
  307. NULL if no device with specified name is found
  308. ********************************************************************/
  309. CHAR * ENUM_MODEM::GetDeviceTypeFromName(LPSTR szDeviceName)
  310. {
  311. DWORD dwIndex = 0;
  312. while (dwIndex < m_dwNumEntries)
  313. {
  314. if (!lstrcmp(m_lpData[dwIndex].szDeviceName, szDeviceName))
  315. {
  316. return m_lpData[dwIndex].szDeviceType;
  317. }
  318. dwIndex++;
  319. }
  320. return NULL;
  321. }
  322. /*******************************************************************
  323. NAME: ENUM_MODEM::GetDeviceNameFromType
  324. SYNOPSIS: Returns type string for specified device.
  325. EXIT: Returns a pointer to device name string for first
  326. device type that matches. Returns
  327. NULL if no device with specified Type is found
  328. ********************************************************************/
  329. CHAR * ENUM_MODEM::GetDeviceNameFromType(LPSTR szDeviceType)
  330. {
  331. DWORD dwIndex = 0;
  332. while (dwIndex < m_dwNumEntries)
  333. {
  334. if (!lstrcmp(m_lpData[dwIndex].szDeviceType, szDeviceType))
  335. {
  336. return m_lpData[dwIndex].szDeviceName;
  337. }
  338. dwIndex++;
  339. }
  340. return NULL;
  341. }
  342. /*******************************************************************
  343. NAME: ENUM_MODEM::VerifyDeviceNameAndType
  344. SYNOPSIS: Determines whether there is a device with the name
  345. and type given.
  346. EXIT: Returns TRUE if the specified device was found,
  347. FALSE otherwise.
  348. ********************************************************************/
  349. BOOL ENUM_MODEM::VerifyDeviceNameAndType(LPSTR szDeviceName, LPSTR szDeviceType)
  350. {
  351. DWORD dwIndex = 0;
  352. while (dwIndex < m_dwNumEntries)
  353. {
  354. if (!lstrcmp(m_lpData[dwIndex].szDeviceType, szDeviceType) &&
  355. !lstrcmp(m_lpData[dwIndex].szDeviceName, szDeviceName))
  356. {
  357. return TRUE;
  358. }
  359. dwIndex++;
  360. }
  361. return FALSE;
  362. }
  363. /*******************************************************************
  364. NAME: GetApiProcAddresses
  365. SYNOPSIS: Gets proc addresses for a table of functions
  366. EXIT: returns TRUE if successful, FALSE if unable to retrieve
  367. any proc address in table
  368. HISTORY:
  369. 96/02/28 markdu If the api is not found in the module passed in,
  370. try the backup (RNAPH.DLL)
  371. ********************************************************************/
  372. BOOL GetApiProcAddresses(HMODULE hModDLL,APIFCN * pApiProcList,UINT nApiProcs)
  373. {
  374. DEBUGMSG("rnacall.c::GetApiProcAddresses()");
  375. UINT nIndex;
  376. // cycle through the API table and get proc addresses for all the APIs we
  377. // need
  378. for (nIndex = 0;nIndex < nApiProcs;nIndex++)
  379. {
  380. if (!(*pApiProcList[nIndex].ppFcnPtr = (PVOID) GetProcAddress(hModDLL,
  381. pApiProcList[nIndex].pszName)))
  382. {
  383. // Try to find the address in RNAPH.DLL. This is useful in the
  384. // case that RASAPI32.DLL did not contain the function that we
  385. // were trying to load.
  386. if (FALSE == IsNT())
  387. {
  388. if (!ghInstRNAPHDll)
  389. {
  390. CHAR szRNAPHDll[SMALL_BUF_LEN];
  391. LoadSz(IDS_RNAPHDLL_FILENAME,szRNAPHDll,sizeof(szRNAPHDll));
  392. ghInstRNAPHDll = LoadLibrary(szRNAPHDll);
  393. }
  394. if ((!ghInstRNAPHDll) || !(*pApiProcList[nIndex].ppFcnPtr =
  395. (PVOID) GetProcAddress(ghInstRNAPHDll,pApiProcList[nIndex].pszName)))
  396. {
  397. DEBUGMSG("Unable to get address of function %s",
  398. pApiProcList[nIndex].pszName);
  399. for (nIndex = 0;nIndex<nApiProcs;nIndex++)
  400. *pApiProcList[nIndex].ppFcnPtr = NULL;
  401. return FALSE;
  402. }
  403. }
  404. }
  405. }
  406. return TRUE;
  407. }
  408. //+----------------------------------------------------------------------------
  409. //
  410. // Function: InitTAPILocation
  411. //
  412. // Synopsis: Ensure that TAPI location information is configured correctly;
  413. // if not, prompt user to fill it in.
  414. //
  415. // Arguments: hwndParent -- parent window for TAPI dialog to use
  416. // (_must_ be a valid window HWND, see note below)
  417. //
  418. // Returns: void
  419. //
  420. // Notes: The docs for lineTranslateDialog lie when they say that the
  421. // fourth parameter (hwndOwner) can be null. In fact, if this
  422. // is null, the call will return with LINEERR_INVALPARAM.
  423. //
  424. //
  425. // History: 7/15/97 jmazner Created for Olympus #6294
  426. //
  427. //-----------------------------------------------------------------------------
  428. void InitTAPILocation(HWND hwndParent)
  429. {
  430. HLINEAPP hLineApp=NULL;
  431. char szTempCountryCode[8];
  432. char szTempCityCode[8];
  433. DWORD dwTapiErr = 0;
  434. DWORD cDevices=0;
  435. DWORD dwCurDevice = 0;
  436. ASSERT( IsWindow(hwndParent) );
  437. //
  438. // see if we can get location info from TAPI
  439. //
  440. dwTapiErr = tapiGetLocationInfo(szTempCountryCode,szTempCityCode);
  441. if( 0 != dwTapiErr )
  442. {
  443. //
  444. // GetLocation failed. let's try calling the TAPI mini dialog. Note
  445. // that when called in this fashion, the dialog has _no_ cancel option,
  446. // the user is forced to enter info and hit OK.
  447. //
  448. DEBUGMSG("InitTAPILocation, tapiGetLocationInfo failed");
  449. dwTapiErr = lineInitialize(&hLineApp,ghInstance,LineCallback," ",&cDevices);
  450. if (dwTapiErr == ERROR_SUCCESS)
  451. {
  452. //
  453. // loop through all TAPI devices and try to call lineTranslateDialog
  454. // The call might fail for VPN devices, thus we want to try every
  455. // device until we get a success.
  456. //
  457. dwTapiErr = LINEERR_INVALPARAM;
  458. while( (dwTapiErr != 0) && (dwCurDevice < cDevices) )
  459. {
  460. dwTapiErr = lineTranslateDialog(hLineApp,dwCurDevice,0x10004,hwndParent,NULL);
  461. if( 0 != dwTapiErr )
  462. {
  463. DEBUGMSG("InitTAPILocation, lineTranslateDialog on device %d failed with err = %d!",
  464. dwCurDevice, dwTapiErr);
  465. }
  466. dwCurDevice++;
  467. }
  468. }
  469. else
  470. {
  471. DEBUGMSG("InitTAPILocation, lineInitialize failed with err = %d", dwTapiErr);
  472. }
  473. dwTapiErr = tapiGetLocationInfo(szTempCountryCode,szTempCityCode);
  474. if( 0 != dwTapiErr )
  475. {
  476. DEBUGMSG("InitTAPILocation still failed on GetLocationInfo, bummer.");
  477. }
  478. else
  479. {
  480. DEBUGMSG("InitTAPILocation, TAPI location is initialized now");
  481. }
  482. }
  483. if( hLineApp )
  484. {
  485. lineShutdown(hLineApp);
  486. hLineApp = NULL;
  487. }
  488. }