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.

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