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.

347 lines
11 KiB

  1. //--------------------------------------------------------------------------//
  2. // Application Header Files. //
  3. //--------------------------------------------------------------------------//
  4. #include "precomp.h"
  5. #include "callto.h"
  6. #include "calltoContext.h"
  7. #include "calltoDisambiguator.h"
  8. //--------------------------------------------------------------------------//
  9. // CCalltoDisambiguator::CCalltoDisambiguator. //
  10. //--------------------------------------------------------------------------//
  11. CCalltoDisambiguator::CCalltoDisambiguator(void):
  12. m_registeredDisambiguators( 0 )
  13. {
  14. addDisambiguator( &m_gatekeeperDisambiguator );
  15. addDisambiguator( &m_gatewayDisambiguator );
  16. addDisambiguator( &m_computerDisambiguator );
  17. addDisambiguator( &m_ilsDisambiguator );
  18. addDisambiguator( &m_unrecognizedDisambiguator );
  19. } // End of CCalltoDisambiguator::CCalltoDisambiguator.
  20. //--------------------------------------------------------------------------//
  21. // CCalltoDisambiguator::~CCalltoDisambiguator. //
  22. //--------------------------------------------------------------------------//
  23. CCalltoDisambiguator::~CCalltoDisambiguator()
  24. {
  25. } // End of CCalltoDisambiguator::~CCalltoDisambiguator.
  26. //--------------------------------------------------------------------------//
  27. // CCalltoDisambiguator::disambiguate. //
  28. //--------------------------------------------------------------------------//
  29. HRESULT
  30. CCalltoDisambiguator::disambiguate
  31. (
  32. const ICalltoContext * const calltoContext,
  33. ICalltoCollection * const resolvedCalltoCollection,
  34. CCalltoCollection * const disambiguatedCalltoCollection
  35. ){
  36. HRESULT result;
  37. if( (calltoContext == NULL) || (resolvedCalltoCollection == NULL) || (disambiguatedCalltoCollection == NULL) )
  38. {
  39. result = E_POINTER;
  40. }
  41. else
  42. {
  43. result = S_UNDISAMBIGUATED;
  44. disambiguatedCalltoCollection->reset();
  45. // Run through "smart" disambiguators...
  46. static HRESULT confidenceLevels[] = {S_CONFIDENCE_CERTITUDE, S_CONFIDENCE_HIGH, S_CONFIDENCE_MEDIUM, S_CONFIDENCE_LOW};
  47. const ICallto * resolvedCallto;
  48. HRESULT resolveResult = S_OK;
  49. for( int level = 0; (level < elementsof( confidenceLevels )) && (resolveResult != S_CONFIDENCE_CERTITUDE); level++ )
  50. {
  51. for( resolvedCallto = resolvedCalltoCollection->get_first();
  52. (resolvedCallto != NULL) && (resolveResult != S_CONFIDENCE_CERTITUDE);
  53. resolvedCallto = resolvedCalltoCollection->get_next() )
  54. {
  55. if( resolvedCallto->get_confidence() == confidenceLevels[ level ] )
  56. {
  57. for( int nn = 0; (nn < m_registeredDisambiguators) && (resolveResult != S_CONFIDENCE_CERTITUDE); nn++ )
  58. {
  59. resolveResult = m_disambiguators[ nn ]->disambiguate( calltoContext, disambiguatedCalltoCollection, resolvedCallto );
  60. if( FAILED( resolveResult ) && (!FAILED( result )) )
  61. {
  62. result = resolveResult;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. return( result );
  70. } // End of CCalltoDisambiguator::disambiguate.
  71. //--------------------------------------------------------------------------//
  72. // CCalltoDisambiguator::addDisambiguator. //
  73. //--------------------------------------------------------------------------//
  74. bool
  75. CCalltoDisambiguator::addDisambiguator
  76. (
  77. IDisambiguator * const disambiguator
  78. ){
  79. //assert( disambiguator != NULL, TEXT( "attempted to add NULL disambiguator\r\n" ) );
  80. //assert( m_registeredDisambiguators < elementsof( m_disambiguators ), TEXT( "attempted to add to many disambiguators: %d\r\n" ), m_registeredDisambiguators );
  81. if( (disambiguator != NULL) && (m_registeredDisambiguators < elementsof( m_disambiguators )) )
  82. {
  83. m_disambiguators[ m_registeredDisambiguators++ ] = disambiguator;
  84. }
  85. return( (disambiguator !=NULL ) && (m_registeredDisambiguators <= elementsof( m_disambiguators )) );
  86. } // End of CCalltoDisambiguator::addDisambiguator.
  87. //--------------------------------------------------------------------------//
  88. // CGatekeeperDisambiguator::disambiguate. //
  89. //--------------------------------------------------------------------------//
  90. HRESULT
  91. CGatekeeperDisambiguator::disambiguate
  92. (
  93. const ICalltoContext * const calltoContext,
  94. IMutableCalltoCollection * const calltoCollection,
  95. const ICallto * const resolvedCallto
  96. ){
  97. const IGatekeeperContext * const gatekeeperContext = calltoContext->get_gatekeeperContext();
  98. HRESULT result = S_UNDISAMBIGUATED;
  99. if( gatekeeperContext != NULL )
  100. {
  101. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  102. if( disambiguatedCallto != NULL )
  103. {
  104. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  105. disambiguatedCallto->set_destination( gatekeeperContext->get_ipAddress() );
  106. disambiguatedCallto->set_confidence( S_CONFIDENCE_CERTITUDE );
  107. result = S_CONFIDENCE_CERTITUDE;
  108. }
  109. }
  110. return( result );
  111. } // End of CGatekeeperDisambiguator::disambiguate.
  112. //--------------------------------------------------------------------------//
  113. // CGatewayDisambiguator::disambiguate. //
  114. //--------------------------------------------------------------------------//
  115. HRESULT
  116. CGatewayDisambiguator::disambiguate
  117. (
  118. const ICalltoContext * const calltoContext,
  119. IMutableCalltoCollection * const calltoCollection,
  120. const ICallto * const resolvedCallto
  121. ){
  122. HRESULT result = S_UNDISAMBIGUATED;
  123. if( lstrcmpi( resolvedCallto->get_type(), TEXT( "phone" ) ) == 0 )
  124. {
  125. const TCHAR * const gateway = resolvedCallto->get_gateway();
  126. if( gateway != NULL )
  127. {
  128. TCHAR ipAddress[ MAX_PATH ];
  129. result = CCalltoContext::get_ipAddressFromName( gateway, ipAddress, elementsof( ipAddress ) );
  130. if( result == S_OK )
  131. {
  132. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  133. if( disambiguatedCallto == NULL )
  134. {
  135. result = S_UNDISAMBIGUATED;
  136. }
  137. else
  138. {
  139. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  140. disambiguatedCallto->set_destination( ipAddress );
  141. disambiguatedCallto->set_confidence( S_CONFIDENCE_CERTITUDE );
  142. result = S_CONFIDENCE_CERTITUDE;
  143. }
  144. }
  145. }
  146. else
  147. {
  148. const IGatewayContext * const gatewayContext = calltoContext->get_gatewayContext();
  149. if( gatewayContext != NULL )
  150. {
  151. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  152. if( disambiguatedCallto != NULL )
  153. {
  154. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  155. disambiguatedCallto->set_destination( gatewayContext->get_ipAddress() );
  156. disambiguatedCallto->set_confidence( S_CONFIDENCE_CERTITUDE );
  157. result = S_CONFIDENCE_CERTITUDE;
  158. }
  159. }
  160. }
  161. }
  162. return( result );
  163. } // End of CGatewayDisambiguator::disambiguate.
  164. //--------------------------------------------------------------------------//
  165. // CComputerDisambiguator::disambiguate. //
  166. //--------------------------------------------------------------------------//
  167. HRESULT
  168. CComputerDisambiguator::disambiguate
  169. (
  170. const ICalltoContext * const calltoContext,
  171. IMutableCalltoCollection * const calltoCollection,
  172. const ICallto * const resolvedCallto
  173. ){
  174. bool ip = (lstrcmpi( resolvedCallto->get_type(), TEXT( "ip" ) ) == 0);
  175. bool computer = (lstrcmpi( resolvedCallto->get_type(), TEXT( "computer" ) ) == 0);
  176. HRESULT result = S_UNDISAMBIGUATED;
  177. if( ip || computer )
  178. {
  179. TCHAR ipAddress[ 64 ];
  180. result = CCalltoContext::get_ipAddressFromName( resolvedCallto->get_value(),
  181. ipAddress,
  182. elementsof( ipAddress ) );
  183. if( result != S_OK )
  184. {
  185. result = S_UNDISAMBIGUATED;
  186. }
  187. else
  188. {
  189. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  190. if( disambiguatedCallto == NULL )
  191. {
  192. result = S_UNDISAMBIGUATED;
  193. }
  194. else
  195. {
  196. result = S_CONFIDENCE_CERTITUDE;
  197. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  198. disambiguatedCallto->set_destination( ipAddress );
  199. disambiguatedCallto->set_confidence( result );
  200. }
  201. }
  202. }
  203. return( result );
  204. } // End of CComputerDisambiguator::disambiguate.
  205. //--------------------------------------------------------------------------//
  206. // CILSDisambiguator::disambiguate. //
  207. //--------------------------------------------------------------------------//
  208. HRESULT
  209. CILSDisambiguator::disambiguate
  210. (
  211. const ICalltoContext * const calltoContext,
  212. IMutableCalltoCollection * const calltoCollection,
  213. const ICallto * const resolvedCallto
  214. ){
  215. const IILSContext * const ilsContext = calltoContext->get_ilsContext();
  216. const TCHAR * const type = resolvedCallto->get_type();
  217. const TCHAR * ilsServer = resolvedCallto->get_server();
  218. HRESULT result = S_FALSE;
  219. TCHAR ipAddress[ MAX_PATH ];
  220. if( (ilsServer == NULL) && (ilsContext != NULL) )
  221. {
  222. ilsServer = ilsContext->get_ilsName();
  223. }
  224. if( ilsServer != NULL )
  225. {
  226. bool ils = (lstrcmpi( type, TEXT( "ils" ) ) == 0);
  227. if( ils || (lstrcmpi( type, TEXT( "email" ) ) == 0) )
  228. {
  229. result = CCalltoContext::get_ipAddressFromILSEmail( ilsServer,
  230. resolvedCallto->get_serverPort(),
  231. resolvedCallto->get_value(),
  232. ipAddress,
  233. elementsof( ipAddress ) );
  234. if( result == S_OK )
  235. {
  236. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  237. if( disambiguatedCallto == NULL )
  238. {
  239. result = S_UNDISAMBIGUATED;
  240. }
  241. else
  242. {
  243. result = (ils)? S_CONFIDENCE_HIGH: S_CONFIDENCE_MEDIUM;
  244. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  245. disambiguatedCallto->set_destination( ipAddress );
  246. disambiguatedCallto->set_confidence( result );
  247. }
  248. }
  249. }
  250. }
  251. return( result );
  252. } // End of CILSDisambiguator::disambiguate.
  253. //--------------------------------------------------------------------------//
  254. // CUnrecognizedDisambiguator::disambiguate. //
  255. //--------------------------------------------------------------------------//
  256. HRESULT
  257. CUnrecognizedDisambiguator::disambiguate
  258. (
  259. const ICalltoContext * const calltoContext,
  260. IMutableCalltoCollection * const calltoCollection,
  261. const ICallto * const resolvedCallto
  262. ){
  263. if( calltoCollection->get_count() == 0 )
  264. {
  265. const TCHAR * const type = resolvedCallto->get_type();
  266. bool phone = (lstrcmpi( type, TEXT( "phone" ) ) == 0);
  267. bool email = (lstrcmpi( type, TEXT( "email" ) ) == 0);
  268. bool ip = (lstrcmpi( type, TEXT( "ip" ) ) == 0);
  269. bool computer = (lstrcmpi( type, TEXT( "computer" ) ) == 0);
  270. bool ils = (lstrcmpi( type, TEXT( "ils" ) ) == 0);
  271. bool string = (lstrcmpi( type, TEXT( "string" ) ) == 0);
  272. if( string || ((!phone) && (!email) && (!ip) && (!computer) && (!ils)) )
  273. {
  274. ICallto * disambiguatedCallto = calltoCollection->get_nextUnused();
  275. if( disambiguatedCallto != NULL )
  276. {
  277. disambiguatedCallto->set_qualifiedName( resolvedCallto->get_qualifiedName() );
  278. disambiguatedCallto->set_confidence( S_UNDISAMBIGUATED );
  279. }
  280. }
  281. }
  282. return( S_UNDISAMBIGUATED );
  283. } // End of CUnrecognizedDisambiguator::disambiguate.