IIOP_Endpoint.cpp File Reference

#include "tao/IIOP_Endpoint.h"
#include "tao/IOP_IORC.h"
#include "tao/debug.h"
#include "tao/ORB_Core.h"
#include "ace/Log_Msg.h"
#include "ace/Guard_T.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_stdio.h"
#include "ace/os_include/os_netdb.h"
#include "ace/Vector_T.h"
#include "ace/ACE.h"
#include "ace/INET_Addr.h"
#include "ace/Sock_Connect.h"

Include dependency graph for IIOP_Endpoint.cpp:

Include dependency graph

Go to the source code of this file.

Functions

ACE_CString find_local (const ACE_Vector< ACE_CString > &local_ips, const ACE_CString &pattern)
void get_ip_interfaces (ACE_Vector< ACE_CString > &local_ips)
void find_preferred_interfaces (const ACE_CString &host, const ACE_CString &csvPreferred, ACE_Vector< ACE_CString > &preferred)


Function Documentation

ACE_CString find_local const ACE_Vector< ACE_CString > &  local_ips,
const ACE_CString pattern
[static]
 

Definition at line 399 of file IIOP_Endpoint.cpp.

References ACE_CString, ACE_Vector< T, DEFAULT_SIZE >::size(), and ACE::wild_match().

Referenced by find_preferred_interfaces().

00401 {
00402   for (size_t i = 0; i < local_ips.size(); ++i)
00403   {
00404     ACE_CString ret = local_ips[i];
00405     if (ACE::wild_match(ret.c_str(), pattern.c_str()))
00406       return ret;
00407   }
00408   return "";
00409 }

void find_preferred_interfaces const ACE_CString host,
const ACE_CString csvPreferred,
ACE_Vector< ACE_CString > &  preferred
[static]
 

Definition at line 452 of file IIOP_Endpoint.cpp.

References ACE_ASSERT, ACE_CString, find_local(), get_ip_interfaces(), ACE_Vector< T, DEFAULT_SIZE >::push_back(), ACE_Vector< T, DEFAULT_SIZE >::size(), ssize_t, and ACE::wild_match().

Referenced by TAO_IIOP_Endpoint::preferred_interfaces().

00455 {
00456   ACE_Vector<ACE_CString> local_ips;
00457   get_ip_interfaces(local_ips);
00458   if (local_ips.size() == 0)
00459     return;
00460 
00461   // The outer loop steps through each preferred interface directive
00462   // and chains a new endpoint if the remote interface matches the
00463   // current endpoint.
00464   size_t index = 0;
00465   while (index < csvPreferred.length())
00466   {
00467     ssize_t comma = csvPreferred.find(',', index);
00468     ssize_t assign = csvPreferred.find('=', index);
00469 
00470     if (assign == ACE_CString::npos)
00471     {
00472       assign = csvPreferred.find(':', index);
00473       if (assign == ACE_CString::npos)
00474       {
00475         ACE_ASSERT(assign != ACE_CString::npos);
00476         return;
00477       }
00478     }
00479 
00480     ACE_CString wild_local;
00481     if (comma == ACE_CString::npos)
00482       wild_local = csvPreferred.substr(assign + 1);
00483     else
00484       wild_local = csvPreferred.substr(assign + 1, comma - assign - 1);
00485     ACE_CString wild_remote = csvPreferred.substr(index, assign - index);
00486 
00487     index = static_cast<size_t>(comma) + 1;
00488 
00489     // For now, we just try to match against the host literally. In
00490     // the future it might be worthwhile to resolve some aliases for
00491     // this->host_ using DNS (and possibly reverse DNS) lookups. Then we
00492     // could try matching against those too.
00493     if (ACE::wild_match(host.c_str(), wild_remote.c_str(), false))
00494     {
00495       // If it's a match, then it means we need to use a
00496       // local interface that matches wild_local.
00497       ACE_CString local = find_local(local_ips, wild_local);
00498       if (local.length() > 0)
00499       {
00500         preferred.push_back(local);
00501       }
00502       else
00503       {
00504         // There is no matching local interface, so we can skip
00505         // to the next preferred interface directive.
00506       }
00507     }
00508     else
00509     {
00510       // The preferred interface directive is for a different
00511       // remote endpoint.
00512     }
00513     if (comma == ACE_CString::npos)
00514       break;
00515   }
00516 }

void get_ip_interfaces ACE_Vector< ACE_CString > &  local_ips  )  [static]
 

Definition at line 422 of file IIOP_Endpoint.cpp.

References ACE_ASSERT, ACE_CString, ACE_INET_Addr::get_host_addr(), ACE::get_ip_interfaces(), and ACE_Vector< T, DEFAULT_SIZE >::push_back().

Referenced by find_preferred_interfaces().

00423 {
00424   ACE_INET_Addr* tmp = 0;
00425   size_t cnt = 0;
00426   int err = ACE::get_ip_interfaces (cnt, tmp);
00427   if (err != 0)
00428     return;
00429 #if defined (ACE_HAS_IPV6)
00430   char buf[64];
00431 #else /* ACE_HAS_IPV6 */
00432   char buf[32];
00433 #endif /* !ACE_HAS_IPV6 */
00434   for (size_t i = 0; i < cnt; ++i)
00435   {
00436     const char *s_if = tmp[i].get_host_addr(buf, sizeof (buf));
00437     ACE_ASSERT(s_if != 0);
00438     ACE_CString tmp(s_if);
00439     //ssize_t pos = tmp.find(':');
00440     //if (pos != ACE_CString::npos)
00441     //  tmp = tmp.substr(0, pos);
00442     local_ips.push_back(tmp);
00443   }
00444   delete[] tmp;
00445 }


Generated on Thu Nov 9 12:00:04 2006 for TAO by doxygen 1.3.6