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.

1035 lines
25 KiB

  1. //--------------------------------------------------------------------------//
  2. // Application Header Files. //
  3. //--------------------------------------------------------------------------//
  4. #include "precomp.h"
  5. #include "call.h"
  6. #include "confPolicies.h"
  7. #include "nmldap.h"
  8. #include "confroom.h"
  9. #include "regentry.h"
  10. //#include "debug.hpp"
  11. #include "callto.h"
  12. #include "calltoContext.h"
  13. #include "dlgAcd.h"
  14. #include "richAddr.h"
  15. //--------------------------------------------------------------------------//
  16. // CUIContext::CUIContext. //
  17. //--------------------------------------------------------------------------//
  18. CUIContext::CUIContext(void):
  19. m_parent( NULL ),
  20. m_callFlags( 0 )
  21. {
  22. } // End of CUIContext::CUIContext.
  23. //--------------------------------------------------------------------------//
  24. // CUIContext::~CUIContext. //
  25. //--------------------------------------------------------------------------//
  26. CUIContext::~CUIContext(void)
  27. {
  28. } // End of CUIContext::~CUIContext.
  29. //--------------------------------------------------------------------------//
  30. // CUIContext::disambiguate. //
  31. //--------------------------------------------------------------------------//
  32. HRESULT
  33. CUIContext::disambiguate
  34. (
  35. ICalltoCollection * const calltoCollection,
  36. ICallto * const ,//emptyCallto,
  37. const ICallto ** const selectedCallto
  38. ){
  39. //trace( TEXT( "CUIContext::disambiguate()\r\n" ) );
  40. HRESULT result = S_FALSE;
  41. if( calltoCollection->get_count() > 1 )
  42. {
  43. static HRESULT confidenceLevels[] = {S_CONFIDENCE_CERTITUDE, S_CONFIDENCE_HIGH, S_CONFIDENCE_MEDIUM, S_CONFIDENCE_LOW};
  44. // Just take the first highest confidence one until we have time to do something superior...
  45. for( int level = 0; (level < elementsof( confidenceLevels )) && (result == S_FALSE); level++ )
  46. {
  47. for( *selectedCallto = calltoCollection->get_first();
  48. *selectedCallto != NULL;
  49. *selectedCallto = calltoCollection->get_next() )
  50. {
  51. if( (*selectedCallto)->get_confidence() == confidenceLevels[ level ] )
  52. {
  53. result = S_OK;
  54. break;
  55. }
  56. }
  57. }
  58. }
  59. if( result != S_OK )
  60. {
  61. ::MessageBox( m_parent, RES2T( IDS_UNRESOLVED_MESSAGE ), RES2T( IDS_UNRESOLVED_CAPTION ), MB_OK );
  62. *selectedCallto = NULL;
  63. }
  64. return( result );
  65. }; // End of class CUIContext::disambiguate.
  66. //--------------------------------------------------------------------------//
  67. // CUIContext::set_parentWindow. //
  68. //--------------------------------------------------------------------------//
  69. void
  70. CUIContext::set_parentWindow
  71. (
  72. const HWND window
  73. ){
  74. //trace( TEXT( "CUIContext::set_parentWindow()\r\n" ) );
  75. m_parent = window;
  76. }; // End of class CUIContext::set_parentWindow.
  77. //--------------------------------------------------------------------------//
  78. // CUIContext::set_callFlags. //
  79. //--------------------------------------------------------------------------//
  80. void
  81. CUIContext::set_callFlags
  82. (
  83. const DWORD callFlags
  84. ){
  85. //trace( TEXT( "CUIContext::set_callFlags()\r\n" ) );
  86. m_callFlags = callFlags;
  87. }; // End of class CUIContext::set_callFlags.
  88. //--------------------------------------------------------------------------//
  89. // CGatekeeperContext::CGatekeeperContext. //
  90. //--------------------------------------------------------------------------//
  91. CGatekeeperContext::CGatekeeperContext(void):
  92. m_enabled( false ),
  93. m_ipAddress( NULL )
  94. {
  95. } // End of CGatekeeperContext::CGatekeeperContext.
  96. //--------------------------------------------------------------------------//
  97. // CGatekeeperContext::~CGatekeeperContext. //
  98. //--------------------------------------------------------------------------//
  99. CGatekeeperContext::~CGatekeeperContext(void)
  100. {
  101. delete [] m_ipAddress;
  102. } // End of CGatekeeperContext::~CGatekeeperContext.
  103. //--------------------------------------------------------------------------//
  104. // CGatekeeperContext::isEnabled. //
  105. //--------------------------------------------------------------------------//
  106. bool
  107. CGatekeeperContext::isEnabled(void) const
  108. {
  109. return( m_enabled && (get_ipAddress() != NULL) );
  110. } // End of CGatekeeperContext::isEnabled.
  111. //--------------------------------------------------------------------------//
  112. // CGatekeeperContext::get_ipAddress. //
  113. //--------------------------------------------------------------------------//
  114. const TCHAR *
  115. CGatekeeperContext::get_ipAddress(void) const
  116. {
  117. return( m_ipAddress );
  118. } // End of CGatekeeperContext::get_ipAddress.
  119. //--------------------------------------------------------------------------//
  120. // CGatekeeperContext::set_enabled. //
  121. //--------------------------------------------------------------------------//
  122. void
  123. CGatekeeperContext::set_enabled
  124. (
  125. const bool enabled
  126. ){
  127. m_enabled = enabled;
  128. } // End of CGatekeeperContext::set_enabled.
  129. //--------------------------------------------------------------------------//
  130. // CGatekeeperContext::set_gatekeeperName. //
  131. //--------------------------------------------------------------------------//
  132. HRESULT
  133. CGatekeeperContext::set_gatekeeperName
  134. (
  135. const TCHAR * const gatekeeperName
  136. ){
  137. TCHAR ipAddress[ MAX_PATH ];
  138. HRESULT result = CCalltoContext::get_ipAddressFromName( gatekeeperName, ipAddress, elementsof( ipAddress ) );
  139. if( result == S_OK )
  140. {
  141. result = set_ipAddress( ipAddress );
  142. }
  143. return( result );
  144. } // End of CGatekeeperContext::set_gatekeeperName.
  145. //--------------------------------------------------------------------------//
  146. // CGatekeeperContext::set_ipAddress. //
  147. //--------------------------------------------------------------------------//
  148. HRESULT
  149. CGatekeeperContext::set_ipAddress
  150. (
  151. const TCHAR * const ipAddress
  152. ){
  153. HRESULT result = S_FALSE;
  154. if( m_ipAddress != NULL )
  155. {
  156. delete [] m_ipAddress;
  157. m_ipAddress = NULL;
  158. }
  159. if( ipAddress != NULL )
  160. {
  161. if( (m_ipAddress = new TCHAR [ lstrlen( ipAddress ) + 1 ]) == NULL )
  162. {
  163. result = E_OUTOFMEMORY;
  164. }
  165. else
  166. {
  167. lstrcpy( m_ipAddress, ipAddress );
  168. result = S_OK;
  169. }
  170. }
  171. return( result );
  172. } // End of CGatekeeperContext::set_ipAddress.
  173. //--------------------------------------------------------------------------//
  174. // CGatewayContext::CGatewayContext. //
  175. //--------------------------------------------------------------------------//
  176. CGatewayContext::CGatewayContext(void):
  177. m_enabled( false ),
  178. m_ipAddress( NULL )
  179. {
  180. } // End of CGatewayContext::CGatewayContext.
  181. //--------------------------------------------------------------------------//
  182. // CGatewayContext::~CGatewayContext. //
  183. //--------------------------------------------------------------------------//
  184. CGatewayContext::~CGatewayContext(void)
  185. {
  186. delete [] m_ipAddress;
  187. } // End of CGatewayContext::~CGatewayContext.
  188. //--------------------------------------------------------------------------//
  189. // CGatewayContext::isEnabled. //
  190. //--------------------------------------------------------------------------//
  191. bool
  192. CGatewayContext::isEnabled(void) const
  193. {
  194. return( m_enabled && (get_ipAddress() != NULL) );
  195. } // End of CGatewayContext::isEnabled.
  196. //--------------------------------------------------------------------------//
  197. // CGatewayContext::get_ipAddress. //
  198. //--------------------------------------------------------------------------//
  199. const TCHAR *
  200. CGatewayContext::get_ipAddress(void) const
  201. {
  202. return( m_ipAddress );
  203. } // End of CGatewayContext::get_ipAddress.
  204. //--------------------------------------------------------------------------//
  205. // CGatewayContext::set_enabled. //
  206. //--------------------------------------------------------------------------//
  207. void
  208. CGatewayContext::set_enabled
  209. (
  210. const bool enabled
  211. ){
  212. m_enabled = enabled;
  213. } // End of CGatewayContext::set_enabled.
  214. //--------------------------------------------------------------------------//
  215. // CGatewayContext::set_gatewayName. //
  216. //--------------------------------------------------------------------------//
  217. HRESULT
  218. CGatewayContext::set_gatewayName
  219. (
  220. const TCHAR * const gatewayName
  221. ){
  222. TCHAR ipAddress[ MAX_PATH ];
  223. HRESULT result = CCalltoContext::get_ipAddressFromName( gatewayName, ipAddress, elementsof( ipAddress ) );
  224. if( result == S_OK )
  225. {
  226. result = set_ipAddress( ipAddress );
  227. }
  228. return( result );
  229. } // End of CGatewayContext::set_gatewayName.
  230. //--------------------------------------------------------------------------//
  231. // CGatewayContext::set_ipAddress. //
  232. //--------------------------------------------------------------------------//
  233. HRESULT
  234. CGatewayContext::set_ipAddress
  235. (
  236. const TCHAR * const ipAddress
  237. ){
  238. HRESULT result = S_FALSE;
  239. if( m_ipAddress != NULL )
  240. {
  241. delete [] m_ipAddress;
  242. m_ipAddress = NULL;
  243. }
  244. if( ipAddress != NULL )
  245. {
  246. if( (m_ipAddress = new TCHAR [ lstrlen( ipAddress ) + 1 ]) == NULL )
  247. {
  248. result = E_OUTOFMEMORY;
  249. }
  250. else
  251. {
  252. lstrcpy( m_ipAddress, ipAddress );
  253. result = S_OK;
  254. }
  255. }
  256. return( result );
  257. } // End of CGatewayContext::set_ipAddress.
  258. //--------------------------------------------------------------------------//
  259. // CILSContext::CILSContext. //
  260. //--------------------------------------------------------------------------//
  261. CILSContext::CILSContext
  262. (
  263. const TCHAR * const ilsServer
  264. ):
  265. m_enabled( false ),
  266. m_ipAddress( NULL ),
  267. m_ilsName( NULL )
  268. {
  269. } // End of CILSContext::CILSContext.
  270. //--------------------------------------------------------------------------//
  271. // CILSContext::~CILSContext. //
  272. //--------------------------------------------------------------------------//
  273. CILSContext::~CILSContext(void)
  274. {
  275. delete [] m_ipAddress;
  276. delete [] m_ilsName;
  277. } // End of CILSContext::~CILSContext.
  278. //--------------------------------------------------------------------------//
  279. // CILSContext::isEnabled. //
  280. //--------------------------------------------------------------------------//
  281. bool
  282. CILSContext::isEnabled(void) const
  283. {
  284. return( (g_pLDAP != NULL) && (ConfPolicies::GetCallingMode() == ConfPolicies::CallingMode_Direct) );
  285. } // End of CILSContext::isEnabled.
  286. //--------------------------------------------------------------------------//
  287. // CILSContext::get_ipAddress. //
  288. //--------------------------------------------------------------------------//
  289. const TCHAR *
  290. CILSContext::get_ipAddress(void) const
  291. {
  292. return( m_ipAddress );
  293. } // End of CILSContext::get_ipAddress.
  294. //--------------------------------------------------------------------------//
  295. // CILSContext::get_ilsName. //
  296. //--------------------------------------------------------------------------//
  297. const TCHAR * const
  298. CILSContext::get_ilsName(void) const
  299. {
  300. return( m_ilsName );
  301. } // End of CILSContext::get_ilsName.
  302. //--------------------------------------------------------------------------//
  303. // CILSContext::set_enabled. //
  304. //--------------------------------------------------------------------------//
  305. void
  306. CILSContext::set_enabled
  307. (
  308. const bool enabled
  309. ){
  310. m_enabled = enabled;
  311. } // End of CILSContext::set_enabled.
  312. //--------------------------------------------------------------------------//
  313. // CILSContext::set_ilsName. //
  314. //--------------------------------------------------------------------------//
  315. HRESULT
  316. CILSContext::set_ilsName
  317. (
  318. const TCHAR * const ilsName
  319. ){
  320. HRESULT result;
  321. if( m_ilsName && lstrcmpi( ilsName, m_ilsName ) == 0 )
  322. {
  323. result = S_OK;
  324. }
  325. else
  326. {
  327. result = E_FAIL;
  328. if( m_ilsName != NULL )
  329. {
  330. delete [] m_ilsName;
  331. m_ilsName = NULL;
  332. }
  333. if( ilsName != NULL )
  334. {
  335. if( (m_ilsName = new TCHAR [ lstrlen( ilsName ) + 1 ]) == NULL )
  336. {
  337. result = E_OUTOFMEMORY;
  338. }
  339. else
  340. {
  341. TCHAR ipAddress[ MAX_PATH ];
  342. if( (result = CCalltoContext::get_ipAddressFromName( ilsName, ipAddress, elementsof( ipAddress ) )) == S_OK )
  343. {
  344. if( (result = set_ipAddress( ipAddress )) == S_OK )
  345. {
  346. lstrcpy( m_ilsName, ilsName );
  347. }
  348. }
  349. }
  350. }
  351. }
  352. return( result );
  353. } // End of CILSContext::set_ilsName.
  354. //--------------------------------------------------------------------------//
  355. // CILSContext::set_ipAddress. //
  356. //--------------------------------------------------------------------------//
  357. HRESULT
  358. CILSContext::set_ipAddress
  359. (
  360. const TCHAR * const ipAddress
  361. ){
  362. HRESULT result = S_FALSE;
  363. if( m_ipAddress != NULL )
  364. {
  365. delete [] m_ipAddress;
  366. m_ipAddress = NULL;
  367. }
  368. if( ipAddress != NULL )
  369. {
  370. if( (m_ipAddress = new TCHAR [ lstrlen( ipAddress ) + 1 ]) == NULL )
  371. {
  372. result = E_OUTOFMEMORY;
  373. }
  374. else
  375. {
  376. lstrcpy( m_ipAddress, ipAddress );
  377. result = S_OK;
  378. }
  379. }
  380. return( result );
  381. } // End of CILSContext::set_ipAddress.
  382. //--------------------------------------------------------------------------//
  383. // CCalltoContext::CCalltoContext. //
  384. //--------------------------------------------------------------------------//
  385. CCalltoContext::CCalltoContext()
  386. {
  387. } // End of CCalltoContext::CCalltoContext.
  388. //--------------------------------------------------------------------------//
  389. // CCalltoContext::~CCalltoContext. //
  390. //--------------------------------------------------------------------------//
  391. CCalltoContext::~CCalltoContext()
  392. {
  393. } // End of CCalltoContext::~CCalltoContext.
  394. //--------------------------------------------------------------------------//
  395. // CCalltoContext::callto. //
  396. //--------------------------------------------------------------------------//
  397. HRESULT
  398. CCalltoContext::callto
  399. (
  400. const ICalltoProperties * const calltoProperties,
  401. INmCall** ppInternalCall
  402. ){
  403. HRESULT result = CRPlaceCall( calltoProperties, this, ppInternalCall );
  404. if( FAILED( result ) )
  405. {
  406. DisplayCallError( result, calltoProperties->get_displayName() );
  407. }
  408. return( result );
  409. } // End of CCalltoContext::callto.
  410. //--------------------------------------------------------------------------//
  411. // CCalltoContext::get_gatekeeperContext. //
  412. //--------------------------------------------------------------------------//
  413. const IGatekeeperContext * const
  414. CCalltoContext::get_gatekeeperContext(void) const
  415. {
  416. return( (CGatekeeperContext::isEnabled())? this: NULL );
  417. } // End of CCalltoContext::get_gatekeeperContext.
  418. //--------------------------------------------------------------------------//
  419. // CCalltoContext::get_gatewayContext. //
  420. //--------------------------------------------------------------------------//
  421. const IGatewayContext * const
  422. CCalltoContext::get_gatewayContext(void) const
  423. {
  424. return( (CGatewayContext::isEnabled())? this: NULL );
  425. } // End of CCalltoContext::get_gatewayContext.
  426. //--------------------------------------------------------------------------//
  427. // CCalltoContext::get_ilsContext. //
  428. //--------------------------------------------------------------------------//
  429. const IILSContext * const
  430. CCalltoContext::get_ilsContext(void) const
  431. {
  432. return( (CILSContext::isEnabled())? this: NULL );
  433. } // End of CCalltoContext::get_ilsContext.
  434. //--------------------------------------------------------------------------//
  435. // CCalltoContext::get_mutableUIContext. //
  436. //--------------------------------------------------------------------------//
  437. IMutableUIContext * const
  438. CCalltoContext::get_mutableUIContext(void) const
  439. {
  440. return( (IMutableUIContext * const) this );
  441. } // End of CCalltoContext::get_mutableUIContext.
  442. //--------------------------------------------------------------------------//
  443. // CCalltoContext::get_mutableGatekeeperContext. //
  444. //--------------------------------------------------------------------------//
  445. IMutableGatekeeperContext * const
  446. CCalltoContext::get_mutableGatekeeperContext(void) const
  447. {
  448. return( (IMutableGatekeeperContext * const) this );
  449. } // End of CCalltoContext::get_mutableGatekeeperContext.
  450. //--------------------------------------------------------------------------//
  451. // CCalltoContext::get_mutableGatewayContext. //
  452. //--------------------------------------------------------------------------//
  453. IMutableGatewayContext * const
  454. CCalltoContext::get_mutableGatewayContext(void) const
  455. {
  456. return( (IMutableGatewayContext * const) this );
  457. } // End of CCalltoContext::get_mutableGatewayContext.
  458. //--------------------------------------------------------------------------//
  459. // CCalltoContext::get_mutableIlsContext. //
  460. //--------------------------------------------------------------------------//
  461. IMutableILSContext * const
  462. CCalltoContext::get_mutableIlsContext(void) const
  463. {
  464. return( (IMutableILSContext * const) this );
  465. } // End of CCalltoContext::get_mutableIlsContext.
  466. //--------------------------------------------------------------------------//
  467. // CCalltoContext::isPhoneNumber. //
  468. //--------------------------------------------------------------------------//
  469. bool
  470. CCalltoContext::isPhoneNumber
  471. (
  472. const TCHAR * phone
  473. ){
  474. bool result = ((phone != NULL) && (phone[ 0 ] != '\0'));
  475. while( (phone != NULL) && (phone[ 0 ] != '\0') )
  476. {
  477. switch( phone[ 0 ] )
  478. {
  479. default:
  480. result = false; // fall through...
  481. case '0':
  482. case '1':
  483. case '2':
  484. case '3':
  485. case '4':
  486. case '5':
  487. case '6':
  488. case '7':
  489. case '8':
  490. case '9':
  491. case '(':
  492. case ')':
  493. case '#':
  494. case '*':
  495. case '-':
  496. case ',':
  497. case '+':
  498. case ' ':
  499. break;
  500. }
  501. phone++;
  502. }
  503. return( result );
  504. } // End of CCalltoContext::isPhoneNumber.
  505. //--------------------------------------------------------------------------//
  506. // CCalltoContext::toE164. //
  507. //--------------------------------------------------------------------------//
  508. bool
  509. CCalltoContext::toE164
  510. (
  511. const TCHAR * phone,
  512. TCHAR * base10,
  513. int size
  514. ){
  515. static TCHAR base10map[] =
  516. {
  517. 0, -1, -1, '#', -1, -1, -1, -1, // !"#$%&'
  518. 0, 0, '*', -1, ',', 0, 0, -1, // ()*+,-./
  519. '0', '1', '2', '3', '4', '5', '6', '7', // 01234567
  520. '8', '9', -1, -1, -1, -1, -1, -1, // 89:;<=>?
  521. -1, '2', '2', '2', '3', '3', '3', '4', // @ABCDEFG
  522. '4', '4', '5', '5', '5', '6', '6', '6', // HIJKLMNO
  523. '7', '7', '7', '7', '8', '8', '8', '9', // PQRSTUVW
  524. '9', '9', '9', -1, -1, -1, -1, -1, // XYZ[\]^_
  525. -1, '2', '2', '2', '3', '3', '3', '4', // `abcdefg
  526. '4', '4', '5', '5', '5', '6', '6', '6', // hijklmno
  527. '7', '7', '7', '7', '8', '8', '8', '9', // pqrstuvw
  528. '9', '9', '9' // xyz
  529. };
  530. bool result = true;
  531. for( ; (*phone != NULL) && ((size > 0) || (base10 == NULL)) && result; phone++ )
  532. {
  533. if( (*phone >= ' ') && (*phone < (TCHAR) (' ' + elementsof( base10map ))) )
  534. {
  535. TCHAR mapValue = base10map[ *phone - ' ' ];
  536. if( mapValue == (TCHAR) -1 )
  537. {
  538. result = false;
  539. }
  540. else if( mapValue != (TCHAR) 0 )
  541. {
  542. if( base10 != NULL )
  543. {
  544. *base10++ = mapValue;
  545. size--;
  546. }
  547. }
  548. }
  549. else
  550. {
  551. result = false;
  552. }
  553. }
  554. if( (size <= 0) && (base10 != NULL) )
  555. {
  556. result = false;
  557. }
  558. else if( result )
  559. {
  560. if( base10 != NULL )
  561. {
  562. *base10 = NULL;
  563. }
  564. }
  565. return( result );
  566. } // End of CCalltoContext::toE164.
  567. //--------------------------------------------------------------------------//
  568. // CCalltoContext::isIPAddress. //
  569. //--------------------------------------------------------------------------//
  570. bool
  571. CCalltoContext::isIPAddress
  572. (
  573. const TCHAR * const ipAddress
  574. ){
  575. int parts = 0;
  576. bool result;
  577. if( (result = (ipAddress != NULL)) != false )
  578. {
  579. const TCHAR * ptr = ipAddress;
  580. bool newPart = true;
  581. int ipByte = 0;
  582. int base = 10;
  583. while( result && (*ptr != NULL) && (parts <= 16) )
  584. {
  585. if( (*ptr >= '0') && (*ptr <= '9') )
  586. {
  587. if( newPart )
  588. {
  589. parts++;
  590. newPart = false;
  591. }
  592. if( (*ptr == '0') && (ipByte == 0) && (base == 10) )
  593. {
  594. base = 8;
  595. }
  596. else if( (base == 8) && ((*ptr == '8') || (*ptr == '9')) )
  597. {
  598. result = false;
  599. }
  600. else
  601. {
  602. ipByte = (ipByte * base) + (*ptr - '0');
  603. if( ipByte > 255 )
  604. {
  605. result = false;
  606. }
  607. }
  608. }
  609. else if( (*ptr >= 'A') && (*ptr <= 'F') )
  610. {
  611. if( base != 16 )
  612. {
  613. result = false;
  614. }
  615. else
  616. {
  617. if( newPart )
  618. {
  619. parts++;
  620. newPart = false;
  621. }
  622. ipByte = (ipByte * 16) + (*ptr - 'A' + 10);
  623. if( ipByte > 255 )
  624. {
  625. result = false;
  626. }
  627. }
  628. }
  629. else if( (*ptr >= 'a') && (*ptr <= 'f') )
  630. {
  631. if( base != 16 )
  632. {
  633. result = false;
  634. }
  635. else
  636. {
  637. if( newPart )
  638. {
  639. parts++;
  640. newPart = false;
  641. }
  642. ipByte = (ipByte * 16) + (*ptr - 'a' + 10);
  643. if( ipByte > 255 )
  644. {
  645. result = false;
  646. }
  647. }
  648. }
  649. else if( *ptr == '.' )
  650. {
  651. newPart = true;
  652. ipByte = 0;
  653. base = 10;
  654. }
  655. else if( (*ptr == 'x') || (*ptr == 'X') )
  656. {
  657. base = 16;
  658. result = (ipByte == 0);
  659. }
  660. else
  661. {
  662. result = false;
  663. }
  664. ptr++;
  665. }
  666. if( result )
  667. {
  668. if( (parts != 4) && (parts != 16) ) // 4 for IPv4, 16 for IPv6 (IPng)...
  669. {
  670. if( (result = (parts < 4)) != false )
  671. {
  672. #if !defined( UNICODE )
  673. result = (inet_addr( ipAddress ) != INADDR_NONE); // Check for valid 1, 2, or 3 part IPv4 address...
  674. #else
  675. result = false;
  676. char * ansiIPAddress;
  677. int size;
  678. size = WideCharToMultiByte( CP_ACP, // code page
  679. 0, // performance and mapping flags
  680. ipAddress, // address of wide-character string
  681. -1, // number of characters in string
  682. NULL, // address of buffer for new string
  683. 0, // size of buffer
  684. NULL, // address of default for unmappable characters
  685. NULL ); // address of flag set when default char. used
  686. if( (ansiIPAddress = new char [ size ]) != NULL )
  687. {
  688. size = WideCharToMultiByte( CP_ACP, // code page
  689. 0, // performance and mapping flags
  690. ipAddress, // address of wide-character string
  691. -1, // number of characters in string
  692. ansiIPAddress, // address of buffer for new string
  693. size, // size of buffer
  694. NULL, // address of default for unmappable characters
  695. NULL ); // address of flag set when default char. used
  696. if( size != 0 )
  697. {
  698. result = (inet_addr( ansiIPAddress ) != INADDR_NONE); // Check for valid 1-4 part IPv4 address...
  699. }
  700. delete [] ansiIPAddress;
  701. }
  702. #endif // !defined( UNICODE )
  703. }
  704. }
  705. }
  706. }
  707. return( result );
  708. } // End of CCalltoContext::isIPAddress.
  709. //--------------------------------------------------------------------------//
  710. // CCalltoContext::get_ipAddressFromName. //
  711. //--------------------------------------------------------------------------//
  712. HRESULT
  713. CCalltoContext::get_ipAddressFromName
  714. (
  715. const TCHAR * const name,
  716. TCHAR * buffer,
  717. int length
  718. ){
  719. HRESULT result = S_FALSE;
  720. if( (name != NULL) && (buffer != NULL) )
  721. {
  722. if( isIPAddress( name ) )
  723. {
  724. if( lstrlen( name ) < length )
  725. {
  726. lstrcpy( buffer, name );
  727. result = S_OK;
  728. }
  729. }
  730. else
  731. {
  732. HOSTENT * hostEntry;
  733. #if !defined( UNICODE )
  734. if( (hostEntry = gethostbyname( name )) != NULL )
  735. {
  736. if( hostEntry->h_addr_list[ 0 ] != NULL )
  737. {
  738. const char * const ipAddress = inet_ntoa( *((in_addr *) hostEntry->h_addr_list[ 0 ]) );
  739. if( lstrlen( ipAddress ) < length )
  740. {
  741. lstrcpy( buffer, ipAddress );
  742. result = S_OK;
  743. }
  744. }
  745. }
  746. #else
  747. char * ansiHost;
  748. int size;
  749. size = WideCharToMultiByte( CP_ACP, // code page
  750. 0, // performance and mapping flags
  751. name, // address of wide-character string
  752. -1, // number of characters in string
  753. NULL, // address of buffer for new string
  754. 0, // size of buffer
  755. NULL, // address of default for unmappable characters
  756. NULL ); // address of flag set when default char. used
  757. if( (ansiHost = new char [ size ]) == NULL )
  758. {
  759. result = E_OUTOFMEMORY;
  760. }
  761. else
  762. {
  763. size = WideCharToMultiByte( CP_ACP, // code page
  764. 0, // performance and mapping flags
  765. name, // address of wide-character string
  766. -1, // number of characters in string
  767. ansiHost, // address of buffer for new string
  768. size, // size of buffer
  769. NULL, // address of default for unmappable characters
  770. NULL ); // address of flag set when default char. used
  771. if( size != 0 )
  772. {
  773. if( (hostEntry = gethostbyname( ansiHost )) != NULL )
  774. {
  775. if( hostEntry->h_addr_list[ 0 ] != NULL )
  776. {
  777. const char * const ipAddress = inet_ntoa( *((in_addr *) hostEntry->h_addr_list[ 0 ]) );
  778. if( lstrlen( ipAddress ) < length )
  779. {
  780. MultiByteToWideChar( CP_ACP, // code page
  781. MB_PRECOMPOSED, // character-type options
  782. ipAddress, // string to convert
  783. -1, // length of string to convert
  784. buffer, // address of wide character buffer
  785. length ); // size of buffer
  786. result = S_OK;
  787. }
  788. }
  789. }
  790. }
  791. delete [] ansiHost;
  792. }
  793. #endif // !defined( UNICODE )
  794. }
  795. }
  796. return( result );
  797. } // End of CCalltoContext::get_ipAddressFromName.
  798. //--------------------------------------------------------------------------//
  799. // CCalltoContext::get_ipAddressFromILSEmail. //
  800. //--------------------------------------------------------------------------//
  801. HRESULT
  802. CCalltoContext::get_ipAddressFromILSEmail
  803. (
  804. const TCHAR * const ilsServer,
  805. const TCHAR * const ilsPort,
  806. const TCHAR * const email,
  807. TCHAR * const ipAddress,
  808. const int size
  809. ){
  810. HRESULT result;
  811. if( g_pLDAP == NULL )
  812. {
  813. g_pLDAP = new CNmLDAP;
  814. }
  815. if( g_pLDAP == NULL )
  816. {
  817. result = E_FAIL;
  818. }
  819. else
  820. {
  821. int port = (ilsPort != NULL)? (int) DecimalStringToUINT( ilsPort ): LDAP_PORT;
  822. result = g_pLDAP->ResolveUser( email, ilsServer, ipAddress, size, port );
  823. }
  824. return( result );
  825. } // End of CCalltoContext::get_ipAddressFromILSEmail.