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.

835 lines
20 KiB

  1. /*
  2. File : Phone.CPP
  3. */
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <stdio.h>
  7. #include <tchar.h>
  8. #include <ATK_RAS.H>
  9. #include "cntryinf.h"
  10. #include "resource.h"
  11. #include "phonebk.h"
  12. #include "util.h"
  13. #include "rw_common.h"
  14. #define TYPE_SIGNUP_ANY 0x82
  15. #define MASK_SIGNUP_ANY 0xB2
  16. #define TYPE_REGULAR_USAGE 0x42
  17. #define MASK_REGULAR_USAGE 0x73
  18. #define MAX_BUFFER 1024 * 5
  19. #define RAS_ENTRY_NAME _T("REGWIZ")
  20. //
  21. // This function expands and substitutes Environment variable
  22. // in input string
  23. //
  24. //
  25. static void GetAbsolutePath( LPTSTR input,LPTSTR output)
  26. {
  27. if(_tcschr(input,_T('%')) == NULL) {
  28. _tcscpy(output, input);
  29. return ;
  30. }
  31. if(input[0] == _T('%'))
  32. {
  33. LPTSTR token = _tcstok(input,_T("%"));
  34. if(token != NULL)
  35. {
  36. LPTSTR sztemp;
  37. sztemp = _tgetenv( token );
  38. if(sztemp != NULL)
  39. {
  40. _tcscpy(output ,sztemp);
  41. }
  42. token = _tcstok(NULL,_T("\0"));
  43. if(token != NULL)
  44. {
  45. _tcscat(output ,token);
  46. }
  47. }
  48. }
  49. else
  50. {
  51. LPTSTR token = _tcstok(input,_T("%"));
  52. if(token != NULL)
  53. {
  54. _tcscpy(output ,token);
  55. token = _tcstok(NULL,_T("%"));
  56. if(token != NULL)
  57. {
  58. LPTSTR sztemp;
  59. sztemp = _tgetenv( token );
  60. if(sztemp != NULL)
  61. {
  62. _tcscat(output ,sztemp);
  63. }
  64. token = _tcstok(NULL,_T("\0"));
  65. if(token != NULL)
  66. {
  67. _tcscat(output ,token);
  68. }
  69. }
  70. }
  71. }
  72. GetAbsolutePath(output,output);
  73. }
  74. #define MAX_ALTERNATES 5
  75. #define MAX_DUN_ENTRYNAME 256
  76. class DUNFileProcess {
  77. public :
  78. DUNFileProcess(HINSTANCE hIns, TCHAR *czFile);
  79. //~DUNFileProcess();
  80. DWORD CreateRasEntry( RASENTRY *pRasEntry, // Pointer of the RASENTRY structre to be created
  81. LPTSTR szUserName, // User name of the ISP
  82. LPTSTR szPassword); // Password for the ISP
  83. HINSTANCE m_hInstance;
  84. TCHAR m_szDUNFile[MAX_PATH];
  85. TCHAR m_szDunEntry[MAX_ALTERNATES][MAX_DUN_ENTRYNAME];
  86. TCHAR * GetDunFileRoot();
  87. TCHAR * GetFromResource(int iResId);
  88. };
  89. DUNFileProcess :: DUNFileProcess (HINSTANCE hIns, TCHAR *czFileName)
  90. {
  91. m_hInstance = hIns;
  92. _tcscpy(m_szDUNFile,GetDunFileRoot());
  93. _tcscat(m_szDUNFile, _T("\\"));
  94. _tcscat(m_szDUNFile,czFileName);
  95. }
  96. //
  97. // This gets the directory from where the ICWIP.DUN can be found
  98. // The default is the C:\Progra~1\ICW-IN~1\\
  99. //
  100. TCHAR * DUNFileProcess :: GetDunFileRoot()
  101. {
  102. HKEY hKey;
  103. LONG regStatus;
  104. TCHAR czTemp[256];
  105. //TCHAR uszRegKey[]="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\ICWCONN1.EXE";
  106. //TCHAR uszR[ ]= "Path";
  107. DWORD dwInfoSize;
  108. static TCHAR szDunRoot[256] = _T("c:\\Progra~1\\ICW-IN~1\\");
  109. dwInfoSize = 256;
  110. regStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  111. GetFromResource(IDS_ICW_DIRECTORY_ENTRY),
  112. 0,KEY_READ ,&hKey);
  113. if (regStatus == ERROR_SUCCESS) {
  114. // Get The Path
  115. dwInfoSize = MAX_PATH;
  116. RegQueryValueEx(hKey,
  117. GetFromResource(IDS_ICW_DIRECTORY_ENTRY_VALUE),
  118. NULL,0,
  119. (LPBYTE) czTemp,
  120. &dwInfoSize);
  121. GetAbsolutePath(czTemp,szDunRoot);
  122. size_t sLen = _tcslen(szDunRoot);
  123. szDunRoot[sLen-1] = _T('\0');
  124. }
  125. else {
  126. ;
  127. }
  128. return szDunRoot;
  129. }
  130. TCHAR * DUNFileProcess ::GetFromResource(int iResId)
  131. {
  132. static int iCount=0;
  133. if(iCount == MAX_ALTERNATES ) {
  134. iCount = 0;
  135. }
  136. LoadString(m_hInstance,iResId,m_szDunEntry[iCount],
  137. MAX_DUN_ENTRYNAME);
  138. return m_szDunEntry[iCount++];
  139. }
  140. void FillIpAddress1(_TCHAR *czStr, RASIPADDR * pRE )
  141. {
  142. _TCHAR czTemp[4];
  143. int iCount=0;
  144. int iIndex=0;
  145. int Location =0;
  146. for(int Addr=0; Addr< 4; Addr++) {
  147. iCount = 0;
  148. for( ;czStr[iIndex] !=_T('.') && iCount <3; )
  149. {
  150. czTemp[iCount] = czStr[iIndex];
  151. iCount += _tcslen( czTemp + iCount );
  152. iIndex += _tcslen( czStr + iIndex );
  153. }
  154. iIndex += _tcslen( czStr + iIndex );
  155. czTemp[iCount] = _T('\0');
  156. switch(Addr) {
  157. case 0:
  158. pRE->a = (BYTE) _ttoi(czTemp);
  159. break;
  160. case 1:
  161. pRE->b = (BYTE) _ttoi(czTemp);
  162. break;
  163. case 2:
  164. pRE->c = (BYTE) _ttoi(czTemp);
  165. break;
  166. case 3:
  167. pRE->d = (BYTE) _ttoi(czTemp);
  168. break;
  169. default:
  170. break;
  171. }
  172. }
  173. }
  174. void FillIpAddress(_TCHAR *czStr, RASIPADDR * pRE )
  175. {
  176. _TCHAR czTemp[4];
  177. int iCount=0;
  178. int iIndex=0;
  179. int Location =0;
  180. for(int Addr=0; Addr< 4; Addr++) {
  181. iCount = 0;
  182. for( ;czStr[iIndex] != _T('.') && iCount <3; ) {
  183. czTemp[iCount++] =
  184. czStr[iIndex];
  185. iIndex++;
  186. }
  187. iIndex++;
  188. czTemp[iCount] = _T('\0');
  189. switch(Addr) {
  190. case 0:
  191. pRE->a = (BYTE) _ttoi(czTemp);
  192. break;
  193. case 1:
  194. pRE->b = (BYTE) _ttoi(czTemp);
  195. break;
  196. case 2:
  197. pRE->c = (BYTE) _ttoi(czTemp);
  198. break;
  199. case 3:
  200. pRE->d = (BYTE) _ttoi(czTemp);
  201. break;
  202. default:
  203. break;
  204. }
  205. }
  206. }
  207. //
  208. // Returns 1 if successful
  209. // 0 failure
  210. //
  211. DWORD DUNFileProcess :: CreateRasEntry(
  212. RASENTRY *pRasEntry,
  213. LPTSTR szUserName,
  214. LPTSTR szPassword)
  215. {
  216. TCHAR szSection[MAX_PATH];
  217. TCHAR szValue[MAX_PATH];
  218. TCHAR szScript[MAX_PATH];
  219. TCHAR szWinPath[MAX_PATH];
  220. DWORD dwRead;
  221. BOOL bRet= FALSE;
  222. pRasEntry->dwSize = sizeof(RASENTRY);
  223. pRasEntry->dwfOptions = RASEO_UseCountryAndAreaCodes |
  224. RASEO_ModemLights;
  225. // Framing
  226. //
  227. pRasEntry->dwFrameSize = 0;
  228. _tcscpy(pRasEntry->szScript, _T(""));
  229. // Auto-Dial
  230. //
  231. _tcscpy(pRasEntry->szAutodialDll, _T(""));
  232. _tcscpy(pRasEntry->szAutodialFunc, _T(""));
  233. // Device
  234. //
  235. _tcscpy(pRasEntry->szDeviceType, RASDT_Modem);
  236. // _tcscpy(pRasEntry->szDeviceName, GetModemDeviceInformation(m_hInstance));
  237. // The Modem entry will be created before creating the Phone book entry
  238. // X.25
  239. //
  240. _tcscpy(pRasEntry->szX25PadType, _T(""));
  241. _tcscpy(pRasEntry->szX25Address, _T(""));
  242. _tcscpy(pRasEntry->szX25Facilities, _T(""));
  243. _tcscpy(pRasEntry->szX25UserData, _T(""));
  244. pRasEntry->dwChannels = 0;
  245. // Phone
  246. //
  247. _tcscpy(szSection,GetFromResource(IDS_DUN_PHONE_SECTION));
  248. // Area Code
  249. DWORD dwAreaCode = GetPrivateProfileInt (szSection,
  250. GetFromResource(IDS_DUN_PHONE_AREACODE),
  251. 0,
  252. m_szDUNFile);
  253. _tprintf(pRasEntry->szAreaCode, "%d", dwAreaCode);
  254. // Country Code
  255. pRasEntry->dwCountryCode = GetPrivateProfileInt (szSection,
  256. GetFromResource(IDS_DUN_PHONE_COUNTRY),
  257. 1, m_szDUNFile);
  258. RW_DEBUG <<"\n Country Code " << pRasEntry->dwCountryCode;
  259. pRasEntry->dwCountryID = GetPrivateProfileInt (szSection, _T("Country_ID"), 1, m_szDUNFile);
  260. RW_DEBUG <<"\n Country ID " << pRasEntry->dwCountryID;
  261. //
  262. GetPrivateProfileString (szSection,
  263. GetFromResource(IDS_DUN_PHONE_DIALAS),
  264. GetFromResource(IDS_DUN_VALUE_YES),
  265. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  266. pRasEntry->dwAlternateOffset=0;
  267. // TODO : Set Phone No from Phone Book
  268. _tcscpy(pRasEntry->szLocalPhoneNumber,_T(""));
  269. // Server
  270. //
  271. // Framing Protocol
  272. _tcscpy(szSection,GetFromResource(IDS_DUN_SERVER_SECTION));
  273. GetPrivateProfileString (szSection,
  274. GetFromResource(IDS_DUN_SERVER_TYPE),
  275. GetFromResource(IDS_DUN_SERVER_TYPE_PPP), // PPP
  276. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  277. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_SERVER_TYPE_PPP))) {
  278. pRasEntry->dwFramingProtocol = RASFP_Ppp;
  279. }
  280. // SW Compression
  281. GetPrivateProfileString (szSection,GetFromResource(IDS_DUN_SERVER_SW_COMPRESS),
  282. GetFromResource(IDS_DUN_VALUE_YES),
  283. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  284. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  285. pRasEntry->dwfOptions |=RASEO_SwCompression;
  286. }
  287. // Negociate TCP
  288. GetPrivateProfileString (szSection,
  289. GetFromResource(IDS_DUN_SERVER_TCPIP),
  290. GetFromResource(IDS_DUN_VALUE_YES),
  291. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  292. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  293. pRasEntry->dwfNetProtocols = RASNP_Ip;
  294. }
  295. // Disable LCP
  296. GetPrivateProfileString (szSection,
  297. GetFromResource(IDS_DUN_SERVER_LCP),
  298. GetFromResource(IDS_DUN_VALUE_YES),
  299. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  300. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  301. pRasEntry->dwfOptions |=RASEO_DisableLcpExtensions;
  302. }
  303. // TCP/IP
  304. _tcscpy(szSection, GetFromResource(IDS_DUN_TCP_SECTION));
  305. GetPrivateProfileString (szSection,
  306. GetFromResource(IDS_DUN_TCP_IPADDRESS),
  307. GetFromResource(IDS_DUN_VALUE_NO),
  308. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  309. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  310. pRasEntry->dwfOptions |=RASEO_SpecificIpAddr;
  311. }
  312. GetPrivateProfileString (szSection,
  313. GetFromResource(IDS_DUN_TCP_SERVERADDRESS),
  314. GetFromResource(IDS_DUN_VALUE_NO),
  315. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  316. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  317. pRasEntry->dwfOptions |=RASEO_SpecificNameServers;
  318. }
  319. GetPrivateProfileString (szSection,
  320. GetFromResource(IDS_DUN_TCP_HEADERCOMPRESSION),
  321. GetFromResource(IDS_DUN_VALUE_NO),
  322. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  323. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  324. pRasEntry->dwfOptions |=RASEO_IpHeaderCompression;
  325. }
  326. GetPrivateProfileString (szSection,
  327. GetFromResource(IDS_DUN_TCP_GATEWAY),
  328. GetFromResource(IDS_DUN_VALUE_NO),
  329. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  330. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  331. pRasEntry->dwfOptions |=RASEO_RemoteDefaultGateway;
  332. }
  333. GetPrivateProfileString (szSection,
  334. GetFromResource(IDS_DUN_TCP_SERVERADDRESS),
  335. GetFromResource(IDS_DUN_VALUE_NO),
  336. szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  337. if(!_tcsicmp(szValue,GetFromResource(IDS_DUN_VALUE_YES))) {
  338. dwRead = GetPrivateProfileString (szSection,
  339. GetFromResource(IDS_DUN_TCP_DNS),
  340. _T("0"), szValue,
  341. sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  342. if( dwRead >2) {
  343. FillIpAddress(szValue,&pRasEntry->ipaddrDns);
  344. }
  345. //
  346. // Get The Secondary Address
  347. dwRead = GetPrivateProfileString (szSection,
  348. GetFromResource(IDS_DUN_TCP_DNS_ALT),
  349. _T("0"), szValue,
  350. sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  351. if(dwRead > 2) {
  352. FillIpAddress(szValue,&pRasEntry->ipaddrDnsAlt);
  353. }
  354. }
  355. // User Section
  356. _tcscpy(szSection,
  357. GetFromResource(IDS_DUN_USER_SECTION));
  358. GetPrivateProfileString (szSection,
  359. GetFromResource(IDS_DUN_USER_NAME),
  360. _T(""), szUserName, MAX_PATH, m_szDUNFile);
  361. GetPrivateProfileString (szSection,
  362. GetFromResource(IDS_DUN_USER_PASSWORD),
  363. _T(""), szPassword, MAX_PATH, m_szDUNFile);
  364. // Scripting
  365. _tcscpy(szSection, _T("Scripting"));
  366. GetPrivateProfileString (szSection, _T("Name"), _T(""), szScript, MAX_PATH, m_szDUNFile);
  367. if ( lstrcmpi(szScript, _T("") ) != 0 ) {
  368. if (!GetWindowsDirectory(szWinPath, MAX_PATH) )
  369. {
  370. #ifdef _LOG_IN_FILE
  371. RW_DEBUG << "\n CreateRasEntry : Error 1- Fail to Get Windows Directory" << flush;
  372. #endif
  373. return TRUE;
  374. }
  375. //APPCOMPAT:Needs specail procesing for win9x
  376. if ( _T('\\') != szWinPath[_tcslen(szWinPath)-1])
  377. {
  378. lstrcat(szWinPath,_T("\\"));
  379. }
  380. lstrcat(szWinPath,szScript);
  381. lstrcpy(szScript,szWinPath);
  382. if (_tcslen(szScript) >=MAX_PATH)
  383. {
  384. #ifdef _LOG_IN_FILE
  385. RW_DEBUG << "\n CreateRasEntry : Error 1- Script File Path too long" << flush;
  386. #endif
  387. return TRUE;
  388. }
  389. }
  390. lstrcpy(pRasEntry->szScript,szScript);
  391. // Script_File
  392. TCHAR szScriptBuffer[MAX_BUFFER];
  393. _tcscpy(szSection, _T("Script_File"));
  394. GetPrivateProfileString (szSection, NULL, _T(""), szScriptBuffer, MAX_BUFFER, m_szDUNFile);
  395. // Create the .SCP File and Dump the script data
  396. PTSTR pKey=szScriptBuffer;
  397. HANDLE fileHandle = CreateFile(pRasEntry->szScript, GENERIC_WRITE,0, 0, CREATE_ALWAYS, 0, 0);
  398. if (fileHandle == INVALID_HANDLE_VALUE)
  399. {
  400. #ifdef _LOG_IN_FILE
  401. RW_DEBUG << "\n Load DUN Strings : Error 1- Fail to create Script File " << flush;
  402. #endif
  403. return TRUE;
  404. }
  405. BOOL bWrite = TRUE;
  406. DWORD numWrite;
  407. while (*pKey && bWrite)
  408. {
  409. GetPrivateProfileString (szSection, pKey , _T(""), szValue, sizeof(szValue)/sizeof(TCHAR), m_szDUNFile);
  410. _tcscat(szValue, _T("\x0d\x0a"));
  411. #ifdef _UNICODE
  412. char *czP;
  413. czP = ConvertToANSIString(szValue);
  414. bWrite = WriteFile(fileHandle, czP, strlen(czP)*sizeof(char), &numWrite, 0);
  415. #else
  416. bWrite = WriteFile(fileHandle, szValue, _tcslen(szValue)*sizeof(_TCHAR), &numWrite, 0);
  417. #endif
  418. while (*pKey)
  419. {
  420. pKey = _tcsinc(pKey);
  421. }
  422. pKey = _tcsinc(pKey);
  423. }
  424. CloseHandle(fileHandle);
  425. return TRUE;
  426. }
  427. int GetDeaultCfgAreaCode(HINSTANCE hInstance, DWORD *CountryCode, DWORD *AreaCode)
  428. {
  429. HKEY hKey;
  430. TCHAR szTel[256] = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations");
  431. TCHAR szCI [48] = _T("CurrentID");
  432. TCHAR szNE [48] = _T("NumEntries");
  433. TCHAR szID [48] = _T("ID");
  434. TCHAR szCountryReg[48] = _T("Country");
  435. _TCHAR szAreaCodeReg[48];
  436. _TCHAR czLastStr[48];
  437. _TCHAR czNewKey[256];
  438. _TCHAR szAreaCode[48];
  439. DWORD dwCurrentId;
  440. DWORD dwNumEntries;
  441. DWORD dwId;
  442. LONG lStatus;
  443. DWORD dwInfoSize = 48;
  444. DWORD dwAreaCode = 0;
  445. int iRetValue;
  446. iRetValue =0;
  447. *CountryCode=1; // Default USA
  448. *AreaCode = 1; // Default Area Code
  449. LoadString(hInstance,IDS_TELEPHONE_LOC,szTel,256);
  450. LoadString(hInstance,IDS_TELEPHONE_CID,szCI,48);
  451. LoadString(hInstance,IDS_TELEPHONE_NENT,szNE,48);
  452. LoadString(hInstance,IDS_TELEPHONE_ID,szID,48);
  453. LoadString(hInstance,IDS_TELEPHONE_COUNTRY,szCountryReg,48);
  454. lStatus= RegOpenKeyEx(HKEY_LOCAL_MACHINE,szTel,0,KEY_READ,&hKey);
  455. if (lStatus == ERROR_SUCCESS)
  456. {
  457. // Get Index
  458. //
  459. dwInfoSize = sizeof(dwCurrentId);
  460. lStatus = RegQueryValueEx(hKey,szCI,NULL,0,( LPBYTE )&dwCurrentId,&dwInfoSize);
  461. if( lStatus != ERROR_SUCCESS)
  462. {
  463. RegCloseKey(hKey);
  464. return iRetValue;
  465. }
  466. //
  467. /*dwInfoSize = sizeof(dwNumEntries);
  468. lStatus = RegQueryValueEx(hKey,szNE,NULL,0,( LPBYTE )&dwNumEntries,&dwInfoSize);
  469. if( lStatus != ERROR_SUCCESS)
  470. {
  471. RegCloseKey(hKey);
  472. return iRetValue;
  473. }*/
  474. RegCloseKey(hKey);
  475. }
  476. //
  477. // Now Contine to scan
  478. //for (int iCount =0; iCount < dwNumEntries; iCount ++ )
  479. _stprintf(czLastStr,_T("\\Location%d"),dwCurrentId);
  480. _tcscpy(czNewKey,szTel);
  481. _tcscat(czNewKey,czLastStr);
  482. #ifdef _LOG_IN_FILE
  483. RW_DEBUG << "\n RegKey Location:"<< czNewKey << flush;
  484. #endif
  485. lStatus= RegOpenKeyEx(HKEY_LOCAL_MACHINE,czNewKey,0,KEY_READ,&hKey);
  486. if (lStatus == ERROR_SUCCESS)
  487. {
  488. dwInfoSize = sizeof(dwCurrentId);
  489. /* lStatus = RegQueryValueEx(hKey,szID,NULL,0,( LPBYTE )&dwId,&dwInfoSize);
  490. if( lStatus == ERROR_SUCCESS)
  491. if(dwId == dwCurrentId)
  492. dwInfoSize = sizeof(dwCurrentId);; */
  493. lStatus = RegQueryValueEx(hKey,szCountryReg,NULL,0,( LPBYTE )CountryCode,&dwInfoSize);
  494. LoadString(hInstance,IDS_TAPI_AREA_CODE,szAreaCodeReg,48);
  495. dwInfoSize = 48;
  496. lStatus = RegQueryValueEx(hKey,szAreaCodeReg,NULL,0,( LPBYTE )szAreaCode,&dwInfoSize);
  497. if( lStatus == ERROR_SUCCESS)
  498. {
  499. *AreaCode = _ttol(szAreaCode);
  500. }
  501. RegCloseKey(hKey);
  502. return dwAreaCode;
  503. }
  504. return iRetValue;
  505. }
  506. //
  507. // returns 0 if Error
  508. // 1 if Succesful
  509. //
  510. //
  511. DWORD GetRASEntries(HINSTANCE hInstance,
  512. RASENTRY *pRasEntry,
  513. LPTSTR szUserName,
  514. LPTSTR szPassword)
  515. {
  516. HKEY hKey;
  517. DWORD_PTR dwPhoneID;
  518. DWORD dwCountry;
  519. DWORD dwCountryCode;
  520. DWORD dwAreaCode = 0;
  521. TCHAR szResEntry[256];
  522. dwPhoneID = 0;
  523. //LoadString(hInstance,IDS_PHONEBOOK_ENTRY,szResEntry,255);
  524. //
  525. // Presently this string is not passed as the Phone bokk is
  526. // still not a UNICODE version CXG 6-0497
  527. //
  528. HRESULT hr = PhoneBookLoad("MSICW", &dwPhoneID);
  529. if (!dwPhoneID)
  530. {
  531. #ifdef _LOG_IN_FILE
  532. RW_DEBUG << "\n Fn: GetRasEntries : Error-1 Unable to locate MSN.ISP " << flush;
  533. #endif
  534. return FALSE;
  535. }
  536. //if (!GetTapiCurrentCountry(m_hInst, &dwCountry)) { on6/4/97
  537. if (!GetTapiCurrentCountry(hInstance, &dwCountry))
  538. {
  539. #ifdef _LOG_IN_FILE
  540. RW_DEBUG << "\n Fn: GetRasEntries : Error-2 Unable To Get Country Code " << flush;
  541. #endif
  542. return FALSE ;
  543. }
  544. #ifdef _LOG_IN_FILE
  545. RW_DEBUG << "\n Fn: GetRasEntries : Get Current Country " << dwCountry << flush;
  546. #endif
  547. GetDeaultCfgAreaCode(hInstance,&dwCountryCode,&dwAreaCode);
  548. #ifdef _LOG_IN_FILE
  549. RW_DEBUG << "\n Fn: GetRasEntries : GetDeaultCfgAreaCode Country " << dwCountryCode << "Area " << dwAreaCode << flush;
  550. RW_DEBUG << "\n Country ID: " << dwCountry << flush;
  551. #endif
  552. SUGGESTINFO SuggestInfo;
  553. SuggestInfo.dwCountryID = dwCountry;
  554. SuggestInfo.bMask = MASK_SIGNUP_ANY;
  555. SuggestInfo.fType = TYPE_SIGNUP_ANY;
  556. SuggestInfo.wAreaCode = dwAreaCode;
  557. SuggestInfo.wNumber = 1;
  558. int nIndex = PhoneBookSuggestNumbers(dwPhoneID, &SuggestInfo);
  559. if (nIndex != 0)
  560. {
  561. #ifdef _LOG_IN_FILE
  562. RW_DEBUG << "\n Fn: GetRasEntries : Error-3 In Phone Suggest Number" << flush;
  563. #endif
  564. return FALSE;
  565. }
  566. PACCESSENTRY m_rgAccessEntry = *(SuggestInfo.rgpAccessEntry);
  567. #ifdef _LOG_IN_FILE
  568. RW_DEBUG << "\n Fn: GetRasEntries : Phone Book Suggestions " << flush;
  569. RW_DEBUG << "\n\t Index " << m_rgAccessEntry->dwIndex ;
  570. RW_DEBUG << "\n\t Phone Number Type " << m_rgAccessEntry->fType;
  571. RW_DEBUG << "\n\t StateId " << m_rgAccessEntry->wStateID;
  572. RW_DEBUG << "\n\t CountryId " << m_rgAccessEntry->dwCountryID;
  573. RW_DEBUG << "\n\t AreaCode " << m_rgAccessEntry->dwAreaCode ;
  574. RW_DEBUG << "\n\t CityName " << m_rgAccessEntry-> szCity;
  575. RW_DEBUG << "\n\t Access Number " << m_rgAccessEntry->szAccessNumber;
  576. RW_DEBUG << "\n\t Actual Area Code " << m_rgAccessEntry->szAreaCode << flush;
  577. #endif
  578. //BOOL FillRASEntries(RASENTRY *pRasEntry);
  579. DUNFileProcess dfp(hInstance,
  580. ConvertToUnicode(m_rgAccessEntry->szDataCenter));
  581. if(!dfp.CreateRasEntry(pRasEntry,szUserName,szPassword))
  582. {
  583. #ifdef _LOG_IN_FILE
  584. RW_DEBUG << "\n GetRas Entries -Error 4 : Processinfg DUN File " << flush;
  585. #endif
  586. return FALSE;
  587. }
  588. pRasEntry->dwCountryID = dwCountry;
  589. GetCountryCodeUsingTapiId(dwCountryCode,&dwCountryCode) ;
  590. pRasEntry->dwCountryCode =dwCountryCode;
  591. _tcscpy(pRasEntry->szLocalPhoneNumber, ConvertToUnicode(m_rgAccessEntry->szAccessNumber));
  592. _tcscpy(pRasEntry->szAreaCode,ConvertToUnicode(m_rgAccessEntry->szAreaCode));
  593. RW_DEBUG << "\n Counntry ID " <<pRasEntry->dwCountryID << " Country Code " << pRasEntry->dwCountryCode << flush;
  594. RW_DEBUG << "\n AreaCode: " << ConvertToANSIString(pRasEntry->szAreaCode);
  595. RW_DEBUG << "Local No Real: " << m_rgAccessEntry->szAccessNumber << flush;
  596. RW_DEBUG << "Local No: " << ConvertToANSIString(pRasEntry->szLocalPhoneNumber) << flush;
  597. return TRUE;
  598. }
  599. DWORD ConfigureDUN ( HWND hWnd, HINSTANCE hInstance,
  600. RASENTRY *pRasEntry,
  601. TCHAR *szUserName,
  602. TCHAR *szPassword,
  603. int iModemIndex)
  604. {
  605. DWORD dwEntrySize;
  606. DWORD dwRet;
  607. // Prepare RASENTRY for Dial-up
  608. //
  609. if(!GetRASEntries(hInstance,
  610. pRasEntry,
  611. szUserName,
  612. szPassword) )
  613. {
  614. #ifdef _LOG_IN_FILE
  615. RW_DEBUG << "\n Fn : ConfigureDUN : Error3 Error Getting Ras Entries " << flush;
  616. #endif
  617. return FALSE;
  618. }
  619. _tcscpy(pRasEntry->szDeviceName, GetModemDeviceInformation(hInstance, iModemIndex));
  620. #ifdef _WIN95
  621. //
  622. // remove Old entry
  623. // Verify if name exists in Registry
  624. // if so remove the name from Registry
  625. //
  626. //
  627. //
  628. HANDLE hRegKey ;
  629. LONG regStatus;
  630. DWORD dwInfoSize;
  631. char szParam[512];
  632. regStatus = RegOpenKeyEx(HKEY_CURRENT_USER,
  633. "RemoteAccess\\Addresses",0,
  634. KEY_READ,&hRegKey);
  635. if (regStatus == ERROR_SUCCESS) {
  636. // Key Exists so search if REG WIZ exists
  637. dwInfoSize = 512;
  638. regStatus = RegQueryValueEx(hRegKey,RAS_ENTRY_NAME,NULL,0,
  639. (unsigned char*) szParam,&dwInfoSize);
  640. if (regStatus == ERROR_SUCCESS)
  641. {
  642. // The Key Exits So delete the Entry
  643. RegDeleteValue(hRegKey,RAS_ENTRY_NAME);
  644. #ifdef _LOG_IN_FILE
  645. RW_DEBUG << "\nRegistry Entry found " << RAS_ENTRY_NAME <<
  646. " and Deleting the Entry " << flush;
  647. #endif
  648. }
  649. RegCloseKey(hRegKey);
  650. }
  651. #else
  652. ATK_RasDeleteEntry(NULL,RAS_ENTRY_NAME);
  653. #endif
  654. dwEntrySize = sizeof(RASENTRY);
  655. #ifdef _LOG_IN_FILE
  656. RW_DEBUG << "\nAfter Ras Get Properties :";
  657. RW_DEBUG << "\n\t Device Name " << ConvertToANSIString(pRasEntry->szDeviceName) << flush;
  658. #endif
  659. dwRet = ATK_RasSetEntryProperties( NULL,
  660. RAS_ENTRY_NAME,
  661. pRasEntry,
  662. dwEntrySize ,
  663. NULL,
  664. 0);
  665. if(dwRet == ERROR_CANNOT_OPEN_PHONEBOOK )
  666. {
  667. #ifdef _LOG_IN_FILE
  668. RW_DEBUG << "\nFun ConfigureDUN : ERROR_CANNOT_OPEN_PHONEBOOK " << dwRet << flush;
  669. #endif
  670. return FALSE;
  671. }
  672. else
  673. if(dwRet == ERROR_BUFFER_INVALID )
  674. {
  675. #ifdef _LOG_IN_FILE
  676. RW_DEBUG << "\nFun ConfigureDUN : ERROR_BUFFER_INVALID " << dwRet << flush;
  677. #endif
  678. return FALSE;
  679. }
  680. else
  681. if(dwRet)
  682. {
  683. #ifdef _LOG_IN_FILE
  684. RW_DEBUG << "\n ConfigureDUN : Unknown/Undocumented Error " << dwRet << flush;
  685. #endif
  686. return FALSE;
  687. }
  688. return TRUE;
  689. }