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.

1198 lines
33 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // RAS API wrappers for wide/ansi
  4. //
  5. // Works on all 9x and NT platforms correctly, maintaining unicode
  6. // whenever possible.
  7. //
  8. /////////////////////////////////////////////////////////////////////////////
  9. #include "wininetp.h"
  10. #include "rashelp.h"
  11. #include "autodial.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. /////////////////////////////////////////////////////////////////////////////
  14. ENUM_TYPE GetOSVersion::_EnumType = ENUM_NONE;
  15. GetOSVersion::GetOSVersion()
  16. {
  17. if(_EnumType == ENUM_NONE)
  18. {
  19. if(0 == GlobalPlatformType)
  20. GlobalPlatformType = PlatformType(&GlobalPlatformVersion5);
  21. // figure out which kind of enumeration we're doing - start with multibyte
  22. _EnumType = ENUM_MULTIBYTE;
  23. if(PLATFORM_TYPE_WINNT == GlobalPlatformType)
  24. {
  25. if(TRUE == GlobalPlatformVersion5)
  26. _EnumType = ENUM_WIN2K;
  27. else
  28. _EnumType = ENUM_UNICODE;
  29. }
  30. }
  31. }
  32. GetOSVersion::~GetOSVersion()
  33. {
  34. }
  35. /////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////
  37. RasEnumHelp::RasEnumHelp()
  38. {
  39. DWORD dwBufSize, dwStructSize;
  40. // init
  41. _dwEntries = 0;
  42. _dwLastError = 0;
  43. switch(_EnumType)
  44. {
  45. case ENUM_MULTIBYTE:
  46. dwStructSize = sizeof(RASENTRYNAMEA);
  47. break;
  48. case ENUM_UNICODE:
  49. dwStructSize = sizeof(RASENTRYNAMEW);
  50. break;
  51. case ENUM_WIN2K:
  52. dwStructSize = sizeof(W2KRASENTRYNAMEW);
  53. break;
  54. }
  55. // allocate space for 16 entries
  56. dwBufSize = 16 * dwStructSize;
  57. _preList = (LPRASENTRYNAMEA)LocalAlloc(LPTR, dwBufSize);
  58. if(_preList)
  59. {
  60. do
  61. {
  62. // set up list
  63. _preList[0].dwSize = dwStructSize;
  64. // call ras to enumerate
  65. _dwLastError = ERROR_UNKNOWN;
  66. if(ENUM_MULTIBYTE == _EnumType)
  67. {
  68. _dwLastError = _RasEnumEntriesA(
  69. NULL,
  70. NULL,
  71. (LPRASENTRYNAMEA)_preList,
  72. &dwBufSize,
  73. &_dwEntries
  74. );
  75. }
  76. else
  77. {
  78. _dwLastError = _RasEnumEntriesW(
  79. NULL,
  80. NULL,
  81. (LPRASENTRYNAMEW)_preList,
  82. &dwBufSize,
  83. &_dwEntries
  84. );
  85. }
  86. // reallocate buffer if necessary
  87. if(ERROR_BUFFER_TOO_SMALL == _dwLastError)
  88. {
  89. LocalFree(_preList);
  90. _preList = (LPRASENTRYNAMEA)LocalAlloc(LPTR, dwBufSize);
  91. if(NULL == _preList)
  92. {
  93. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  94. break;
  95. }
  96. }
  97. else
  98. {
  99. break;
  100. }
  101. } while(TRUE);
  102. }
  103. else
  104. {
  105. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  106. }
  107. if(_preList && (ERROR_SUCCESS != _dwLastError))
  108. {
  109. LocalFree(_preList);
  110. _preList = NULL;
  111. _dwEntries = 0;
  112. }
  113. return;
  114. }
  115. RasEnumHelp::~RasEnumHelp()
  116. {
  117. if(_preList)
  118. {
  119. LocalFree(_preList);
  120. }
  121. }
  122. DWORD
  123. RasEnumHelp::GetError()
  124. {
  125. return _dwLastError;
  126. }
  127. DWORD
  128. RasEnumHelp::GetEntryCount()
  129. {
  130. return _dwEntries;
  131. }
  132. LPWSTR
  133. RasEnumHelp::GetEntryW(DWORD dwConnectionNum)
  134. {
  135. LPWSTR pwszName = NULL;
  136. if(dwConnectionNum >= _dwEntries)
  137. {
  138. return NULL;
  139. }
  140. switch(_EnumType)
  141. {
  142. case ENUM_MULTIBYTE:
  143. if(*_preList[dwConnectionNum].szEntryName)
  144. {
  145. MultiByteToWideChar(CP_ACP, 0, _preList[dwConnectionNum].szEntryName,
  146. -1, _szCurrentEntryW, RAS_MaxEntryName + 1);
  147. pwszName = _szCurrentEntryW;
  148. }
  149. break;
  150. case ENUM_UNICODE:
  151. {
  152. LPRASENTRYNAMEW lpTemp = (LPRASENTRYNAMEW)_preList;
  153. if(*lpTemp[dwConnectionNum].szEntryName)
  154. pwszName = lpTemp[dwConnectionNum].szEntryName;
  155. break;
  156. }
  157. case ENUM_WIN2K:
  158. {
  159. LPW2KRASENTRYNAMEW lpTemp = (LPW2KRASENTRYNAMEW)_preList;
  160. if(*lpTemp[dwConnectionNum].szEntryName)
  161. pwszName = lpTemp[dwConnectionNum].szEntryName;
  162. break;
  163. }
  164. }
  165. return pwszName;
  166. }
  167. LPSTR
  168. RasEnumHelp::GetEntryA(DWORD dwConnectionNum)
  169. {
  170. LPSTR pszName = NULL;
  171. if(dwConnectionNum >= _dwEntries)
  172. {
  173. return NULL;
  174. }
  175. switch(_EnumType)
  176. {
  177. case ENUM_MULTIBYTE:
  178. if(*_preList[dwConnectionNum].szEntryName)
  179. pszName = _preList[dwConnectionNum].szEntryName;
  180. break;
  181. case ENUM_UNICODE:
  182. {
  183. LPRASENTRYNAMEW lpTemp = (LPRASENTRYNAMEW)_preList;
  184. if(*lpTemp[dwConnectionNum].szEntryName)
  185. {
  186. WideCharToMultiByte(CP_ACP, 0, lpTemp[dwConnectionNum].szEntryName, -1,
  187. _szCurrentEntryA, RAS_MaxEntryName + 1, NULL, NULL);
  188. pszName = _szCurrentEntryA;
  189. }
  190. break;
  191. }
  192. case ENUM_WIN2K:
  193. {
  194. LPW2KRASENTRYNAMEW lpTemp = (LPW2KRASENTRYNAMEW)_preList;
  195. if(*lpTemp[dwConnectionNum].szEntryName)
  196. {
  197. WideCharToMultiByte(CP_ACP, 0, lpTemp[dwConnectionNum].szEntryName, -1,
  198. _szCurrentEntryA, RAS_MaxEntryName + 1, NULL, NULL);
  199. pszName = _szCurrentEntryA;
  200. }
  201. break;
  202. }
  203. }
  204. return pszName;
  205. }
  206. /////////////////////////////////////////////////////////////////////////////
  207. //
  208. // RasEnumConnHelp
  209. //
  210. /////////////////////////////////////////////////////////////////////////////
  211. RasEnumConnHelp::RasEnumConnHelp()
  212. {
  213. DWORD dwBufSize;
  214. // init
  215. _dwConnections = 0;
  216. _dwLastError = 0;
  217. switch(_EnumType)
  218. {
  219. case ENUM_MULTIBYTE:
  220. _dwStructSize = sizeof(RASCONNA);
  221. break;
  222. case ENUM_UNICODE:
  223. _dwStructSize = sizeof(RASCONNW);
  224. break;
  225. case ENUM_WIN2K:
  226. _dwStructSize = sizeof(W2KRASCONNW);
  227. break;
  228. }
  229. // allocate space for MAX_CONNECTION entries
  230. dwBufSize = MAX_CONNECTION * _dwStructSize;
  231. _pRasCon = (LPRASCONNA)LocalAlloc(LPTR, dwBufSize);
  232. if(_pRasCon == NULL)
  233. {
  234. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  235. }
  236. return;
  237. }
  238. RasEnumConnHelp::~RasEnumConnHelp()
  239. {
  240. if(_pRasCon)
  241. {
  242. LocalFree(_pRasCon);
  243. _pRasCon = NULL;
  244. }
  245. }
  246. DWORD RasEnumConnHelp::Enum()
  247. {
  248. DWORD dwBufSize;
  249. _dwLastError = 0;
  250. if(_pRasCon)
  251. {
  252. dwBufSize = MAX_CONNECTION * _dwStructSize;
  253. do
  254. {
  255. // set up list
  256. _pRasCon[0].dwSize = _dwStructSize;
  257. // call ras to enumerate
  258. _dwLastError = ERROR_UNKNOWN;
  259. switch(_EnumType)
  260. {
  261. case ENUM_MULTIBYTE:
  262. _dwLastError = _RasEnumConnectionsA((LPRASCONNA)_pRasCon, &dwBufSize, &_dwConnections);
  263. break;
  264. case ENUM_UNICODE:
  265. case ENUM_WIN2K:
  266. _dwLastError = _RasEnumConnectionsW((LPRASCONNW)_pRasCon, &dwBufSize, &_dwConnections);
  267. break;
  268. }
  269. // reallocate buffer if necessary
  270. if(ERROR_BUFFER_TOO_SMALL == _dwLastError)
  271. {
  272. LocalFree(_pRasCon);
  273. _pRasCon = (LPRASCONNA)LocalAlloc(LPTR, dwBufSize);
  274. if(NULL == _pRasCon)
  275. {
  276. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  277. break;
  278. }
  279. }
  280. else
  281. {
  282. break;
  283. }
  284. } while(TRUE);
  285. }
  286. else
  287. {
  288. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  289. }
  290. return _dwLastError;
  291. }
  292. DWORD
  293. RasEnumConnHelp::GetError()
  294. {
  295. return _dwLastError;
  296. }
  297. DWORD
  298. RasEnumConnHelp::GetConnectionsCount()
  299. {
  300. return _dwConnections;
  301. }
  302. LPWSTR
  303. RasEnumConnHelp::GetEntryW(DWORD dwConnectionNum)
  304. {
  305. LPWSTR pwszName = NULL;
  306. if((_pRasCon == NULL) || (dwConnectionNum >= _dwConnections))
  307. {
  308. return NULL;
  309. }
  310. switch(_EnumType)
  311. {
  312. case ENUM_MULTIBYTE:
  313. if(*_pRasCon[dwConnectionNum].szEntryName)
  314. {
  315. MultiByteToWideChar(CP_ACP, 0, _pRasCon[dwConnectionNum].szEntryName, -1, _szEntryNameW, RAS_MaxEntryName + 1);
  316. pwszName = _szEntryNameW;
  317. }
  318. break;
  319. case ENUM_UNICODE:
  320. {
  321. LPRASCONNW lpTemp = (LPRASCONNW)_pRasCon;
  322. if(*lpTemp[dwConnectionNum].szEntryName)
  323. pwszName = lpTemp[dwConnectionNum].szEntryName;
  324. break;
  325. }
  326. case ENUM_WIN2K:
  327. {
  328. LPW2KRASCONNW lpTemp = (LPW2KRASCONNW)_pRasCon;
  329. if(*lpTemp[dwConnectionNum].szEntryName)
  330. pwszName = lpTemp[dwConnectionNum].szEntryName;
  331. break;
  332. }
  333. }
  334. return pwszName;
  335. }
  336. LPSTR
  337. RasEnumConnHelp::GetEntryA(DWORD dwConnectionNum)
  338. {
  339. LPSTR pszName = NULL;
  340. if((_pRasCon == NULL) || (dwConnectionNum >= _dwConnections))
  341. {
  342. return NULL;
  343. }
  344. switch(_EnumType)
  345. {
  346. case ENUM_MULTIBYTE:
  347. if(*_pRasCon[dwConnectionNum].szEntryName)
  348. pszName = _pRasCon[dwConnectionNum].szEntryName;
  349. break;
  350. case ENUM_UNICODE:
  351. {
  352. LPRASCONNW lpTemp = (LPRASCONNW)_pRasCon;
  353. if(*lpTemp[dwConnectionNum].szEntryName)
  354. {
  355. WideCharToMultiByte(CP_ACP, 0, lpTemp[dwConnectionNum].szEntryName, -1, _szEntryNameA, RAS_MaxEntryName + 1, NULL, NULL);
  356. pszName = _szEntryNameA;
  357. }
  358. break;
  359. }
  360. case ENUM_WIN2K:
  361. {
  362. LPW2KRASCONNW lpTemp = (LPW2KRASCONNW )_pRasCon;
  363. if(*lpTemp[dwConnectionNum].szEntryName)
  364. {
  365. WideCharToMultiByte(CP_ACP, 0, lpTemp[dwConnectionNum].szEntryName, -1, _szEntryNameA, RAS_MaxEntryName + 1, NULL, NULL);
  366. pszName = _szEntryNameA;
  367. }
  368. break;
  369. }
  370. }
  371. return pszName;
  372. }
  373. LPWSTR
  374. RasEnumConnHelp::GetLastEntryW(DWORD dwConnectionNum)
  375. {
  376. if(_pRasCon == NULL)
  377. return NULL;
  378. return _szEntryNameW;
  379. }
  380. LPSTR
  381. RasEnumConnHelp::GetLastEntryA(DWORD dwConnectionNum)
  382. {
  383. if(_pRasCon == NULL)
  384. return NULL;
  385. return _szEntryNameA;
  386. }
  387. HRASCONN
  388. RasEnumConnHelp::GetHandle(DWORD dwConnectionNum)
  389. {
  390. HRASCONN hTemp;
  391. if((_pRasCon == NULL) || (dwConnectionNum >= _dwConnections))
  392. {
  393. return NULL;
  394. }
  395. switch(_EnumType)
  396. {
  397. case ENUM_MULTIBYTE:
  398. hTemp = _pRasCon[dwConnectionNum].hrasconn;
  399. break;
  400. case ENUM_UNICODE:
  401. {
  402. LPRASCONNW lpTemp = (LPRASCONNW)_pRasCon;
  403. hTemp = lpTemp[dwConnectionNum].hrasconn;
  404. break;
  405. }
  406. case ENUM_WIN2K:
  407. {
  408. LPW2KRASCONNW lpTemp = (LPW2KRASCONNW)_pRasCon;
  409. hTemp = lpTemp[dwConnectionNum].hrasconn;
  410. break;
  411. }
  412. }
  413. return hTemp;
  414. }
  415. /////////////////////////////////////////////////////////////////////////////
  416. //
  417. // RasEntryPropHelp
  418. //
  419. /////////////////////////////////////////////////////////////////////////////
  420. RasEntryPropHelp::RasEntryPropHelp()
  421. {
  422. // init
  423. _dwLastError = 0;
  424. switch(_EnumType)
  425. {
  426. case ENUM_MULTIBYTE:
  427. _dwStructSize = sizeof(RASENTRYA);
  428. break;
  429. case ENUM_UNICODE:
  430. _dwStructSize = sizeof(RASENTRYW);
  431. break;
  432. case ENUM_WIN2K:
  433. _dwStructSize = sizeof(W2KRASENTRYW);
  434. break;
  435. }
  436. _pRasEntry = (LPRASENTRYA)LocalAlloc(LPTR, _dwStructSize * 2);
  437. if(_pRasEntry)
  438. {
  439. _pRasEntry->dwSize = _dwStructSize;
  440. }
  441. else
  442. {
  443. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  444. }
  445. if(_pRasEntry && (ERROR_SUCCESS != _dwLastError))
  446. {
  447. LocalFree(_pRasEntry);
  448. _pRasEntry = NULL;
  449. }
  450. return;
  451. }
  452. RasEntryPropHelp::~RasEntryPropHelp()
  453. {
  454. if(_pRasEntry)
  455. {
  456. LocalFree(_pRasEntry);
  457. _pRasEntry = NULL;
  458. }
  459. }
  460. DWORD RasEntryPropHelp::GetError()
  461. {
  462. return _dwLastError;
  463. }
  464. DWORD RasEntryPropHelp::GetA(LPSTR lpszEntryName)
  465. {
  466. DWORD dwSize = _dwStructSize * 2;
  467. switch(_EnumType)
  468. {
  469. case ENUM_MULTIBYTE:
  470. _dwLastError = _RasGetEntryPropertiesA(NULL, lpszEntryName, (LPRASENTRYA)_pRasEntry, &dwSize, NULL, NULL);
  471. break;
  472. case ENUM_UNICODE:
  473. {
  474. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  475. MultiByteToWideChar(CP_ACP, 0, lpszEntryName, -1, _szEntryNameW, RAS_MaxEntryName + 1 );
  476. _dwLastError = _RasGetEntryPropertiesW(NULL, _szEntryNameW, (LPRASENTRYW)lpTemp, &dwSize, NULL, NULL);
  477. break;
  478. }
  479. case ENUM_WIN2K:
  480. {
  481. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  482. MultiByteToWideChar(CP_ACP, 0, lpszEntryName, -1, _szEntryNameW, RAS_MaxEntryName + 1);
  483. _dwLastError = _RasGetEntryPropertiesW(NULL, _szEntryNameW, (LPRASENTRYW)lpTemp, &dwSize, NULL, NULL);
  484. break;
  485. }
  486. }
  487. return(_dwLastError);
  488. }
  489. DWORD RasEntryPropHelp::GetW(LPWSTR lpszEntryName)
  490. {
  491. DWORD dwSize = _dwStructSize * 2;
  492. switch(_EnumType)
  493. {
  494. case ENUM_MULTIBYTE:
  495. WideCharToMultiByte(CP_ACP, 0, lpszEntryName, -1, _szEntryNameA, RAS_MaxEntryName + 1, NULL, NULL);
  496. _dwLastError = _RasGetEntryPropertiesA(NULL, _szEntryNameA, (LPRASENTRYA)_pRasEntry, &dwSize, NULL, NULL);
  497. break;
  498. case ENUM_UNICODE:
  499. {
  500. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  501. _dwLastError = _RasGetEntryPropertiesW(NULL, lpszEntryName, (LPRASENTRYW)lpTemp, &dwSize, NULL, NULL);
  502. break;
  503. }
  504. case ENUM_WIN2K:
  505. {
  506. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  507. _dwLastError = _RasGetEntryPropertiesW(NULL, lpszEntryName, (LPRASENTRYW)lpTemp, &dwSize, NULL, NULL);
  508. break;
  509. }
  510. }
  511. return(_dwLastError);
  512. }
  513. LPWSTR RasEntryPropHelp::GetDeviceTypeW(VOID)
  514. {
  515. LPWSTR lpwstr = NULL;
  516. if(_pRasEntry)
  517. {
  518. switch(_EnumType)
  519. {
  520. case ENUM_MULTIBYTE:
  521. if(*_pRasEntry->szDeviceType)
  522. {
  523. MultiByteToWideChar(CP_ACP, 0, _pRasEntry->szDeviceType, -1, _szDeviceTypeW, RAS_MaxDeviceType + 1);
  524. lpwstr = _szDeviceTypeW;
  525. }
  526. break;
  527. case ENUM_UNICODE:
  528. {
  529. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  530. if(*lpTemp->szDeviceType)
  531. lpwstr = lpTemp->szDeviceType;
  532. break;
  533. }
  534. case ENUM_WIN2K:
  535. {
  536. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  537. if(*lpTemp->szDeviceType)
  538. lpwstr = lpTemp->szDeviceType;
  539. break;
  540. }
  541. }
  542. }
  543. return lpwstr;
  544. }
  545. LPSTR RasEntryPropHelp::GetDeviceTypeA(VOID)
  546. {
  547. LPSTR lpstr = NULL;
  548. if(_pRasEntry)
  549. {
  550. switch(_EnumType)
  551. {
  552. case ENUM_MULTIBYTE:
  553. if(*_pRasEntry->szDeviceType)
  554. lpstr = _pRasEntry->szDeviceType;
  555. break;
  556. case ENUM_UNICODE:
  557. {
  558. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  559. if(*lpTemp->szDeviceType)
  560. {
  561. WideCharToMultiByte(CP_ACP, 0, lpTemp->szDeviceType, -1, _szDeviceTypeA, RAS_MaxDeviceType + 1, NULL, NULL);
  562. lpstr = _szDeviceTypeA;
  563. }
  564. break;
  565. }
  566. case ENUM_WIN2K:
  567. {
  568. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  569. if(*lpTemp->szDeviceType)
  570. {
  571. WideCharToMultiByte(CP_ACP, 0, lpTemp->szDeviceType, -1, _szDeviceTypeA, RAS_MaxDeviceType + 1, NULL, NULL);
  572. lpstr = _szDeviceTypeA;
  573. }
  574. break;
  575. }
  576. }
  577. }
  578. return lpstr;
  579. }
  580. LPWSTR RasEntryPropHelp::GetAutodiallDllW()
  581. {
  582. LPWSTR lpwstr = NULL;
  583. if(_pRasEntry)
  584. {
  585. switch(_EnumType)
  586. {
  587. case ENUM_MULTIBYTE:
  588. if(*_pRasEntry->szAutodialDll)
  589. {
  590. MultiByteToWideChar(CP_ACP, 0, _pRasEntry->szAutodialDll, -1, _szAutodialDllW, MAX_PATH);
  591. lpwstr = _szAutodialDllW;
  592. }
  593. break;
  594. case ENUM_UNICODE:
  595. {
  596. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  597. if(*lpTemp->szAutodialDll)
  598. lpwstr = lpTemp->szAutodialDll;
  599. break;
  600. }
  601. case ENUM_WIN2K:
  602. {
  603. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  604. if(*lpTemp->szAutodialDll)
  605. lpwstr = lpTemp->szAutodialDll;
  606. break;
  607. }
  608. }
  609. }
  610. return lpwstr;
  611. }
  612. LPSTR RasEntryPropHelp::GetAutodiallDllA()
  613. {
  614. LPSTR lpstr = NULL;
  615. if(_pRasEntry)
  616. {
  617. switch(_EnumType)
  618. {
  619. case ENUM_MULTIBYTE:
  620. if(*_pRasEntry->szAutodialDll)
  621. lpstr = _pRasEntry->szAutodialDll;
  622. break;
  623. case ENUM_UNICODE:
  624. {
  625. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  626. if(*lpTemp->szAutodialDll)
  627. {
  628. WideCharToMultiByte(CP_ACP, 0, lpTemp->szAutodialDll, -1, _szAutodialDllA, MAX_PATH, NULL, NULL);
  629. lpstr = _szAutodialDllA;
  630. }
  631. break;
  632. }
  633. case ENUM_WIN2K:
  634. {
  635. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  636. if(*lpTemp->szAutodialDll)
  637. {
  638. WideCharToMultiByte(CP_ACP, 0, lpTemp->szAutodialDll, -1, _szAutodialDllA, MAX_PATH, NULL, NULL);
  639. lpstr = _szAutodialDllA;
  640. }
  641. break;
  642. }
  643. }
  644. }
  645. return lpstr;
  646. }
  647. LPWSTR RasEntryPropHelp::GetAutodialFuncW()
  648. {
  649. LPWSTR lpwstr = NULL;
  650. if(_pRasEntry)
  651. {
  652. switch(_EnumType)
  653. {
  654. case ENUM_MULTIBYTE:
  655. if(*_pRasEntry->szAutodialFunc)
  656. {
  657. MultiByteToWideChar(CP_ACP, 0, _pRasEntry->szAutodialFunc, -1, _szAutodialFuncW, RAS_MaxDeviceType + 1);
  658. lpwstr = _szAutodialFuncW;
  659. }
  660. break;
  661. case ENUM_UNICODE:
  662. {
  663. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  664. if(*lpTemp->szAutodialFunc)
  665. lpwstr = lpTemp->szAutodialFunc;
  666. break;
  667. }
  668. case ENUM_WIN2K:
  669. {
  670. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  671. if(*lpTemp->szAutodialFunc)
  672. lpwstr = lpTemp->szAutodialFunc;
  673. break;
  674. }
  675. }
  676. }
  677. return lpwstr;
  678. }
  679. LPSTR RasEntryPropHelp::GetAutodialFuncA()
  680. {
  681. LPSTR lpstr = NULL;
  682. if(_pRasEntry)
  683. {
  684. switch(_EnumType)
  685. {
  686. case ENUM_MULTIBYTE:
  687. if(*_pRasEntry->szAutodialFunc)
  688. lpstr = _pRasEntry->szAutodialFunc;
  689. break;
  690. case ENUM_UNICODE:
  691. {
  692. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  693. if(*lpTemp->szAutodialFunc)
  694. {
  695. WideCharToMultiByte(CP_ACP, 0, lpTemp->szAutodialFunc, -1, _szAutodialFuncA, RAS_MaxDeviceType + 1, NULL, NULL);
  696. lpstr = _szAutodialFuncA;
  697. }
  698. break;
  699. }
  700. case ENUM_WIN2K:
  701. {
  702. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  703. if(*lpTemp->szAutodialFunc)
  704. {
  705. WideCharToMultiByte(CP_ACP, 0, lpTemp->szAutodialFunc, -1, _szAutodialFuncA, RAS_MaxDeviceType + 1, NULL, NULL);
  706. lpstr = _szAutodialFuncA;
  707. }
  708. break;
  709. }
  710. }
  711. }
  712. return lpstr;
  713. }
  714. LPWSTR RasEntryPropHelp::GetCustomDialDllW()
  715. {
  716. LPWSTR lpwstr = NULL;
  717. if(_pRasEntry)
  718. {
  719. switch(_EnumType)
  720. {
  721. case ENUM_MULTIBYTE: // Not in Win9x
  722. break;
  723. case ENUM_UNICODE: // Not is NT4
  724. break;
  725. case ENUM_WIN2K:
  726. {
  727. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry ;
  728. if(*lpTemp->szCustomDialDll)
  729. lpwstr = lpTemp->szCustomDialDll;
  730. break;
  731. }
  732. }
  733. }
  734. return lpwstr;
  735. }
  736. LPWSTR RasEntryPropHelp::GetPhoneNumberW()
  737. {
  738. LPWSTR lpwstr = NULL;
  739. if(_pRasEntry)
  740. {
  741. switch(_EnumType)
  742. {
  743. case ENUM_MULTIBYTE:
  744. if(*_pRasEntry->szLocalPhoneNumber)
  745. {
  746. MultiByteToWideChar(CP_ACP, 0, _pRasEntry->szLocalPhoneNumber, -1, _szPhoneNumberW, RAS_MaxPhoneNumber);
  747. lpwstr = _szPhoneNumberW;
  748. }
  749. break;
  750. case ENUM_UNICODE:
  751. {
  752. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  753. if(*lpTemp->szLocalPhoneNumber)
  754. lpwstr = lpTemp->szLocalPhoneNumber;
  755. break;
  756. }
  757. case ENUM_WIN2K:
  758. {
  759. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  760. if(*lpTemp->szLocalPhoneNumber)
  761. lpwstr = lpTemp->szLocalPhoneNumber;
  762. break;
  763. }
  764. }
  765. }
  766. return lpwstr;
  767. }
  768. DWORD RasEntryPropHelp::GetCountryCode()
  769. {
  770. DWORD dwCode = 0;
  771. if(_pRasEntry)
  772. {
  773. // country code is at the same place for all versions of the struct,
  774. // so take the shortcut
  775. dwCode = _pRasEntry->dwCountryCode;
  776. }
  777. return dwCode;
  778. }
  779. DWORD RasEntryPropHelp::GetOptions()
  780. {
  781. DWORD dwOptions = 0;
  782. if(_pRasEntry)
  783. {
  784. // dwfOptions is at the same place for all versions of the struct,
  785. // so take the shortcut
  786. dwOptions = _pRasEntry->dwfOptions;
  787. }
  788. return dwOptions;
  789. }
  790. LPWSTR RasEntryPropHelp::GetAreaCodeW()
  791. {
  792. LPWSTR lpwstr = NULL;
  793. if(_pRasEntry)
  794. {
  795. switch(_EnumType)
  796. {
  797. case ENUM_MULTIBYTE:
  798. if(*_pRasEntry->szAreaCode)
  799. {
  800. MultiByteToWideChar(CP_ACP, 0, _pRasEntry->szAreaCode, -1, _szAreaCodeW, RAS_MaxAreaCode);
  801. lpwstr = _szAreaCodeW;
  802. }
  803. break;
  804. case ENUM_UNICODE:
  805. {
  806. LPRASENTRYW lpTemp = (LPRASENTRYW)_pRasEntry;
  807. if(*lpTemp->szAreaCode)
  808. lpwstr = lpTemp->szAreaCode;
  809. break;
  810. }
  811. case ENUM_WIN2K:
  812. {
  813. LPW2KRASENTRYW lpTemp = (LPW2KRASENTRYW)_pRasEntry;
  814. if(*lpTemp->szAreaCode)
  815. lpwstr = lpTemp->szAreaCode;
  816. break;
  817. }
  818. }
  819. }
  820. return lpwstr;
  821. }
  822. /////////////////////////////////////////////////////////////////////////////
  823. /////////////////////////////////////////////////////////////////////////////
  824. RasEntryDialParamsHelp::RasEntryDialParamsHelp()
  825. {
  826. // init
  827. _dwLastError = 0;
  828. _pRasDialParamsA = NULL;
  829. if(_EnumType == ENUM_MULTIBYTE)
  830. {
  831. _pRasDialParamsA = (LPRASDIALPARAMSA)LocalAlloc(LPTR, sizeof(RASDIALPARAMSA));
  832. if(_pRasDialParamsA == NULL)
  833. {
  834. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  835. }
  836. else
  837. {
  838. _pRasDialParamsA->dwSize = sizeof(RASDIALPARAMSA);
  839. }
  840. }
  841. return;
  842. }
  843. RasEntryDialParamsHelp::~RasEntryDialParamsHelp()
  844. {
  845. _dwLastError = 0;
  846. if(_pRasDialParamsA)
  847. {
  848. LocalFree(_pRasDialParamsA);
  849. _pRasDialParamsA= NULL;
  850. }
  851. }
  852. DWORD RasEntryDialParamsHelp::GetError()
  853. {
  854. return _dwLastError;
  855. }
  856. DWORD RasEntryDialParamsHelp::SetW(LPCWSTR lpszPhonebook, LPRASDIALPARAMSW lprasdialparams, BOOL fRemovePassword)
  857. {
  858. _dwLastError = 1;
  859. if(lprasdialparams)
  860. {
  861. switch(_EnumType)
  862. {
  863. case ENUM_MULTIBYTE:
  864. if(_pRasDialParamsA)
  865. {
  866. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szEntryName, -1, _pRasDialParamsA->szEntryName, RAS_MaxEntryName , NULL, NULL);
  867. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szPhoneNumber, -1, _pRasDialParamsA->szPhoneNumber, RAS_MaxPhoneNumber , NULL, NULL);
  868. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szCallbackNumber, -1, _pRasDialParamsA->szCallbackNumber, RAS_MaxCallbackNumber , NULL, NULL);
  869. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szUserName, -1, _pRasDialParamsA->szUserName, UNLEN , NULL, NULL);
  870. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szPassword, -1, _pRasDialParamsA->szPassword, PWLEN , NULL, NULL);
  871. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szDomain, -1, _pRasDialParamsA->szDomain, DNLEN , NULL, NULL);
  872. _dwLastError = _RasSetEntryDialParamsA(NULL, _pRasDialParamsA, fRemovePassword);
  873. }
  874. break;
  875. case ENUM_UNICODE:
  876. case ENUM_WIN2K:
  877. _dwLastError = _RasSetEntryDialParamsW(NULL, lprasdialparams, fRemovePassword);
  878. break;
  879. }
  880. }
  881. return _dwLastError;
  882. }
  883. DWORD RasEntryDialParamsHelp::GetW(LPCWSTR lpszPhonebook, LPRASDIALPARAMSW lprasdialparams, LPBOOL pfRemovePassword)
  884. {
  885. _dwLastError = 1;
  886. if(lprasdialparams)
  887. {
  888. switch(_EnumType)
  889. {
  890. case ENUM_MULTIBYTE:
  891. WideCharToMultiByte(CP_ACP, 0, lprasdialparams->szEntryName, -1, _pRasDialParamsA->szEntryName, RAS_MaxEntryName, NULL, NULL);
  892. _dwLastError = _RasGetEntryDialParamsA(NULL, _pRasDialParamsA, pfRemovePassword);
  893. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szEntryName, -1, lprasdialparams->szEntryName, RAS_MaxEntryName);
  894. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szPhoneNumber, -1, lprasdialparams->szPhoneNumber, RAS_MaxPhoneNumber);
  895. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szCallbackNumber, -1, lprasdialparams->szCallbackNumber, RAS_MaxCallbackNumber);
  896. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szUserName, -1, lprasdialparams->szUserName, UNLEN);
  897. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szPassword, -1, lprasdialparams->szPassword, PWLEN);
  898. MultiByteToWideChar(CP_ACP, 0, _pRasDialParamsA->szDomain, -1, lprasdialparams->szDomain, DNLEN);
  899. break;
  900. case ENUM_UNICODE:
  901. case ENUM_WIN2K:
  902. _dwLastError = _RasGetEntryDialParamsW(NULL, lprasdialparams, pfRemovePassword);
  903. break;
  904. }
  905. }
  906. return _dwLastError;
  907. }
  908. /////////////////////////////////////////////////////////////////////////////
  909. /////////////////////////////////////////////////////////////////////////////
  910. RasGetConnectStatusHelp::RasGetConnectStatusHelp(HRASCONN hrasconn)
  911. {
  912. // init
  913. _dwLastError = 0;
  914. switch(_EnumType)
  915. {
  916. case ENUM_MULTIBYTE:
  917. _dwStructSize = sizeof(RASCONNSTATUSA);
  918. break;
  919. case ENUM_UNICODE:
  920. case ENUM_WIN2K:
  921. _dwStructSize = sizeof(RASCONNSTATUSW);
  922. break;
  923. }
  924. _pRasConnStatus = (LPRASCONNSTATUSA)LocalAlloc(LPTR, _dwStructSize);
  925. if(_pRasConnStatus)
  926. {
  927. _pRasConnStatus->dwSize = _dwStructSize;
  928. if(_EnumType == ENUM_MULTIBYTE)
  929. {
  930. _dwLastError = _RasGetConnectStatusA(hrasconn, (LPRASCONNSTATUSA)_pRasConnStatus);
  931. }
  932. else
  933. {
  934. _dwLastError = _RasGetConnectStatusW(hrasconn, (LPRASCONNSTATUSW)_pRasConnStatus);
  935. }
  936. if(_pRasConnStatus && (ERROR_SUCCESS != _dwLastError))
  937. {
  938. LocalFree(_pRasConnStatus);
  939. _pRasConnStatus = NULL;
  940. }
  941. }
  942. else
  943. {
  944. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  945. }
  946. return;
  947. }
  948. RasGetConnectStatusHelp::~RasGetConnectStatusHelp()
  949. {
  950. _dwLastError = 0;
  951. if(_pRasConnStatus)
  952. {
  953. LocalFree(_pRasConnStatus);
  954. _pRasConnStatus = NULL;
  955. }
  956. }
  957. DWORD RasGetConnectStatusHelp::GetError()
  958. {
  959. return _dwLastError;
  960. }
  961. RASCONNSTATE RasGetConnectStatusHelp::ConnState()
  962. {
  963. RASCONNSTATE hConnState = (RASCONNSTATE)NULL;
  964. if(_pRasConnStatus)
  965. {
  966. if(_EnumType == ENUM_MULTIBYTE)
  967. {
  968. hConnState = _pRasConnStatus->rasconnstate;
  969. }
  970. else
  971. {
  972. LPRASCONNSTATUSW lpTemp = (LPRASCONNSTATUSW)_pRasConnStatus;
  973. hConnState = lpTemp->rasconnstate;
  974. }
  975. }
  976. return hConnState;
  977. }
  978. /////////////////////////////////////////////////////////////////////////////
  979. /////////////////////////////////////////////////////////////////////////////
  980. RasDialHelp::RasDialHelp(LPRASDIALEXTENSIONS lpRDE, LPWSTR lpszPB, LPRASDIALPARAMSW lpRDPW, DWORD dwType, LPVOID lpvNot, LPHRASCONN lphRasCon)
  981. {
  982. // init
  983. _dwLastError = 1;
  984. _pRasDialParams = NULL;
  985. _lpszPhonebookA = NULL;
  986. if(lpRDPW)
  987. {
  988. switch(_EnumType)
  989. {
  990. case ENUM_MULTIBYTE:
  991. _pRasDialParams = (LPRASDIALPARAMSA)LocalAlloc(LPTR, sizeof(RASDIALPARAMSA));
  992. if(_pRasDialParams)
  993. {
  994. if(lpszPB)
  995. _lpszPhonebookA = (LPSTR)LocalAlloc(LPTR, (lstrlenW(lpszPB)+1) * sizeof(CHAR));
  996. _pRasDialParams->dwSize = sizeof(RASDIALPARAMSA);
  997. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szEntryName, -1, _pRasDialParams->szEntryName, RAS_MaxEntryName, NULL, NULL);
  998. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szPhoneNumber, -1, _pRasDialParams->szPhoneNumber, RAS_MaxPhoneNumber, NULL, NULL);
  999. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szCallbackNumber, -1, _pRasDialParams->szCallbackNumber, RAS_MaxCallbackNumber, NULL, NULL);
  1000. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szUserName, -1, _pRasDialParams->szUserName, UNLEN, NULL, NULL);
  1001. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szPassword, -1, _pRasDialParams->szPassword, PWLEN, NULL, NULL);
  1002. WideCharToMultiByte(CP_ACP, 0, lpRDPW->szDomain, -1, _pRasDialParams->szDomain, DNLEN, NULL, NULL);
  1003. _dwLastError = _RasDialA(lpRDE, _lpszPhonebookA, _pRasDialParams, dwType, lpvNot, lphRasCon);
  1004. }
  1005. else
  1006. {
  1007. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  1008. }
  1009. break;
  1010. case ENUM_WIN2K:
  1011. case ENUM_UNICODE:
  1012. _pRasDialParams = (LPRASDIALPARAMSA)LocalAlloc(LPTR, sizeof(NT4RASDIALPARAMSW));
  1013. if(_pRasDialParams)
  1014. {
  1015. LPNT4RASDIALPARAMSW pRDPW = (LPNT4RASDIALPARAMSW)_pRasDialParams;
  1016. pRDPW->dwSize = sizeof(NT4RASDIALPARAMSW);
  1017. StrCpyNW(pRDPW->szEntryName, lpRDPW->szEntryName, RAS_MaxEntryName);
  1018. StrCpyNW(pRDPW->szPhoneNumber, lpRDPW->szPhoneNumber, RAS_MaxPhoneNumber);
  1019. StrCpyNW(pRDPW->szCallbackNumber, lpRDPW->szCallbackNumber, RAS_MaxCallbackNumber);
  1020. StrCpyNW(pRDPW->szUserName, lpRDPW->szUserName, UNLEN);
  1021. StrCpyNW(pRDPW->szPassword, lpRDPW->szPassword, PWLEN);
  1022. StrCpyNW(pRDPW->szDomain, lpRDPW->szDomain, DNLEN);
  1023. _dwLastError = _RasDialW(lpRDE, lpszPB, (LPRASDIALPARAMSW)pRDPW, dwType, lpvNot, lphRasCon);
  1024. }
  1025. else
  1026. {
  1027. _dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  1028. }
  1029. break;
  1030. }
  1031. if(_pRasDialParams && (ERROR_SUCCESS != _dwLastError))
  1032. {
  1033. LocalFree(_pRasDialParams);
  1034. _pRasDialParams = NULL;
  1035. }
  1036. if(_lpszPhonebookA && (ERROR_SUCCESS != _dwLastError))
  1037. {
  1038. LocalFree(_lpszPhonebookA);
  1039. _lpszPhonebookA = NULL;
  1040. }
  1041. }
  1042. return;
  1043. }
  1044. RasDialHelp::~RasDialHelp()
  1045. {
  1046. _dwLastError = 0;
  1047. if(_pRasDialParams)
  1048. {
  1049. LocalFree(_pRasDialParams);
  1050. _pRasDialParams = NULL;
  1051. }
  1052. if(_lpszPhonebookA)
  1053. {
  1054. LocalFree(_lpszPhonebookA);
  1055. _lpszPhonebookA = NULL;
  1056. }
  1057. }
  1058. DWORD RasDialHelp::GetError()
  1059. {
  1060. return _dwLastError;
  1061. }
  1062. /////////////////////////////////////////////////////////////////////////////
  1063. /////////////////////////////////////////////////////////////////////////////