reSIProcate/stack  9694
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
resip::Resolver Class Reference

#include <Resolver.hxx>

Collaboration diagram for resip::Resolver:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Resolver (const Uri &url)
 Resolver (const Data &host, int port, TransportType transport)

Static Public Member Functions

static bool isIpAddress (const Data &data)
static Data getHostName ()

Public Attributes

std::list< TuplemNextHops

Private Member Functions

void lookupARecords ()

Private Attributes

TransportType mTransport
Data mHost
int mPort

Detailed Description

Definition at line 16 of file Resolver.hxx.


Constructor & Destructor Documentation

Resolver::Resolver ( const Uri url)

Definition at line 29 of file Resolver.cxx.

References resip::Data::c_str(), DebugLog, errno, resip::Uri::exists(), isIpAddress(), lookupARecords(), mHost, mNextHops, mPort, mTransport, resip::Uri::scheme(), resip::Symbols::Sip, resip::Symbols::Sips, strerror(), resip::TCP, and resip::UDP.

                                 : 
   mHost(uri.host()),
   mPort(uri.port() ? uri.port() : 5060)
{
   bool isNumeric = isIpAddress(mHost);
   if (!uri.exists(p_transport) )
   {
      if (isNumeric)
      {
         if (uri.scheme() == Symbols::Sip)
         {
            mTransport = UDP;
         }
         else if (uri.scheme() == Symbols::Sips)
         {
            mTransport = TCP;
         }
      }
      else // not numeric
      {
         if (1) // uri.portSpecified()) // !jf!
         {
            if (uri.scheme() == Symbols::Sip)
            {
               mTransport = UDP;
            }
            else if (uri.scheme() == Symbols::Sips)
            {
               mTransport = TCP;
            }
         }
         else // NAPTR query - yuck! 
         {
            // Rohan, step up to the plate buddy.
            mTransport = UDP; // !jf! not done yet
         }
      }
   }

   if (!isNumeric)
   {
      if (1) // !jf! uri.portSpecified())
      {
         lookupARecords();
         // do an A or AAAA DNS lookup
         
      }
      else
      {
         // do SRV lookup on result of NAPTR lookup
         
         // if no NAPTR lookup, do SRV lookup on _sips for sips and _sip for sip
         
         // if no result on SRV lookup, do an A or AAAA lookup
         
      }
   }
   else
   {
      Tuple tuple;
      if (inet_pton(AF_INET, mHost.c_str(), &tuple.ipv4.s_addr) <= 0)
      {
         DebugLog( << "inet_pton failed to parse address: " << mHost << " " << strerror(errno));
         assert(0);
      }
      tuple.port = mPort;
      tuple.transportType = mTransport;
      
      mNextHops.push_back(tuple);
   }
   
}

Here is the call graph for this function:

Resolver::Resolver ( const Data host,
int  port,
TransportType  transport 
)

Definition at line 103 of file Resolver.cxx.

References resip::Data::c_str(), DebugLog, errno, isIpAddress(), lookupARecords(), mHost, mNextHops, mPort, mTransport, and strerror().

   :  mTransport(transport),
      mHost(host),
      mPort(port)
{
   bool isNumeric = isIpAddress(mHost);
   if (!isNumeric)
   {
      if (1) // !jf! uri.portSpecified())
      {
         lookupARecords();
         // do an A or AAAA DNS lookup
         
      }
      else
      {
         // do SRV lookup on result of NAPTR lookup
         
         // if no NAPTR lookup, do SRV lookup on _sips for sips and _sip for sip
         
         // if no result on SRV lookup, do an A or AAAA lookup
         
      }
   }
   else
   {
      Tuple tuple;
      if (inet_pton(AF_INET, mHost.c_str(), &tuple.ipv4.s_addr) <= 0)
      {
         DebugLog( << "inet_pton failed to parse address: " << mHost << " " << strerror(errno));
         assert(0);
      }
      tuple.port = mPort;
      tuple.transportType = mTransport;
      
      mNextHops.push_back(tuple);
   }
}

Here is the call graph for this function:


Member Function Documentation

Data Resolver::getHostName ( ) [static]

Definition at line 229 of file Resolver.cxx.

References errno, InfoLog, and strerror().

{
   char buffer[255];
   if (gethostname(buffer, sizeof(buffer)) < 0)
   {
      InfoLog (<< "Failed gethostname() " << strerror(errno));
      return "localhost";
   }
   else
   {
      return Data(buffer);
   }
}

Here is the call graph for this function:

bool Resolver::isIpAddress ( const Data data) [static]

Definition at line 208 of file Resolver.cxx.

References resip::Data::c_str(), and resip::Data::size().

Referenced by Resolver().

{
   // ok, this is fairly monstrous but it works. 
   unsigned int p1,p2,p3,p4;
   int count=0;
   int result = sscanf( data.c_str(), 
                        "%u.%u.%u.%u%n",
                        &p1, &p2, &p3, &p4, &count );

   if ( (result == 4) && (p1 <= 255) && (p2 <= 255) && (p3 <= 255) && (p4 <= 255) && (count == int(data.size())) )
   {
      return true;
   }
   else
   {
      return false;
   }
}

Here is the call graph for this function:

void Resolver::lookupARecords ( ) [private]

Definition at line 144 of file Resolver.cxx.

References resip::Data::c_str(), DebugLog, InfoLog, mHost, mNextHops, mPort, and mTransport.

Referenced by Resolver().

{
   struct hostent hostbuf; 
   struct hostent* result=0;

   int herrno=0;
   char buffer[8192];
#ifdef __QNX__
   result = gethostbyname_r (mHost.c_str(), &hostbuf, buffer, sizeof(buffer), &herrno);
   if (result == 0)
   {
#else

#if defined( WIN32 ) || defined( __APPLE__ ) || defined (__SUNPRO_CC) || defined(__FreeBSD__)
        assert(0); // !cj! 
        int ret = -1;
#else
        int ret = gethostbyname_r (mHost.c_str(), &hostbuf, buffer, sizeof(buffer), &result, &herrno);
#endif
   assert (ret != ERANGE);

   if (ret != 0)
   {
#endif
      switch (herrno)
      {
         case HOST_NOT_FOUND:
            InfoLog ( << "host not found: " << mHost);
            break;
         case NO_DATA:
            InfoLog ( << "no data found for: " << mHost);
            break;
         case NO_RECOVERY:
            InfoLog ( << "no recovery lookup up: " << mHost);
            break;
         case TRY_AGAIN:
            InfoLog ( << "try again: " << mHost);
            break;
      }
   }
   else
   {
      assert(result);
      assert(result->h_length == 4);
   
      DebugLog (<< "DNS lookup of " << mHost << ": canonical name: " << result->h_name);
      char str[256];
      for (char** pptr = result->h_addr_list; *pptr != 0; pptr++)
      {
         Tuple tuple;
         tuple.ipv4.s_addr = *((u_int32_t*)(*pptr));
         tuple.port = mPort;
         tuple.transportType = mTransport;

         mNextHops.push_back(tuple);
#ifndef WIN32
         DebugLog (<< inet_ntop(AF_INET, &tuple.ipv4.s_addr, str, sizeof(str)));
#endif

      }
   }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 35 of file Resolver.hxx.

Referenced by lookupARecords(), and Resolver().

Definition at line 30 of file Resolver.hxx.

Referenced by lookupARecords(), Resolver(), and Loadgen::Transceiver::send().

int resip::Resolver::mPort [private]

Definition at line 36 of file Resolver.hxx.

Referenced by lookupARecords(), and Resolver().

Definition at line 34 of file Resolver.hxx.

Referenced by lookupARecords(), and Resolver().


The documentation for this class was generated from the following files: