reSIProcate/stack  9694
DnsInterface.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #ifndef WIN32
00006 #include <sys/types.h>
00007 #include <sys/socket.h>
00008 #include <arpa/inet.h>
00009 #ifndef __CYGWIN__
00010 #  include <netinet/in.h>
00011 #  include <arpa/nameser.h>
00012 #  include <resolv.h>
00013 #endif
00014 #endif
00015 
00016 #include "rutil/compat.hxx"
00017 #include "rutil/Logger.hxx"
00018 #include "rutil/BaseException.hxx"
00019 #include "rutil/Socket.hxx"
00020 
00021 #include "rutil/dns/DnsStub.hxx"
00022 #include "rutil/dns/RRVip.hxx"
00023 #include "resip/stack/DnsInterface.hxx"
00024 #include "rutil/dns/DnsHandler.hxx"
00025 #include "resip/stack/DnsResult.hxx"
00026 
00027 //#include "rutil/dns/ExternalDnsFactory.hxx"
00028 #include "rutil/WinLeakCheck.hxx"
00029 
00030 
00031 using namespace resip;
00032 
00033 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS
00034 
00035 DnsInterface::DnsInterface(DnsStub& dnsStub) : 
00036    mDnsStub(dnsStub)
00037 {
00038 
00039 #ifdef USE_DNS_VIP
00040    mDnsStub.setResultTransform(&mVip);
00041 #endif
00042 }
00043 
00044 DnsInterface::~DnsInterface()
00045 {
00046 }
00047 
00048 static Data UdpNAPTRType("SIP+D2U");
00049 static Data TcpNAPTRType("SIP+D2T");
00050 static Data TlsNAPTRType("SIPS+D2T");
00051 static Data DtlsNAPTRType("SIPS+D2U");
00052 void 
00053 DnsInterface::addTransportType(TransportType type, IpVersion version)
00054 {
00055    mSupportedTransports.push_back(std::make_pair(type, version));
00056    switch (type)
00057    {
00058       case UDP:
00059          mSupportedNaptrs.insert(UdpNAPTRType);
00060          break;
00061       case TCP:
00062          mSupportedNaptrs.insert(TcpNAPTRType);
00063          break;
00064       case TLS:
00065          mSupportedNaptrs.insert(TlsNAPTRType);
00066          break;
00067       case DTLS:
00068          mSupportedNaptrs.insert(DtlsNAPTRType);
00069          break;         
00070       default:
00071          assert(0);
00072          break;
00073    }
00074 }
00075 
00076 bool
00077 DnsInterface::isSupported(const Data& service)
00078 {
00079    return mSupportedNaptrs.count(service) != 0;
00080 }
00081 
00082 bool
00083 DnsInterface::isSupported(TransportType t, IpVersion version)
00084 {
00085    return std::find(mSupportedTransports.begin(), mSupportedTransports.end(), std::make_pair(t, version)) != mSupportedTransports.end();
00086 }
00087 
00088 bool
00089 DnsInterface::isSupportedProtocol(TransportType t)
00090 {
00091    for (TransportMap::const_iterator i=mSupportedTransports.begin(); i != mSupportedTransports.end(); ++i)
00092    {
00093       if (i->first == t)
00094       {
00095          return true;
00096       }
00097    }
00098    return false;
00099 }
00100 
00101 int DnsInterface::supportedProtocols()
00102 {
00103    return (int)mSupportedTransports.size();
00104 }
00105 
00106 
00107 DnsResult*
00108 DnsInterface::createDnsResult(DnsHandler* handler)
00109 {
00110    DnsResult* result = new DnsResult(*this, mDnsStub, mVip, handler);
00111    return result;
00112 }
00113 
00114 void 
00115 DnsInterface::lookup(DnsResult* res, const Uri& uri)
00116 {
00117    res->lookup(uri, mDnsStub.getEnumSuffixes());   
00118 }
00119 
00120 // DnsResult* 
00121 // DnsInterface::lookup(const Via& via, DnsHandler* handler)
00122 // {
00123 //    assert(0);
00124 
00125 //    //DnsResult* result = new DnsResult(*this);
00126 //    return NULL;
00127 // }
00128 
00129 //?dcm? -- why is this here?
00130 DnsHandler::~DnsHandler()
00131 {
00132 }
00133 
00134 /* moved to DnsStub.
00135 void 
00136 DnsInterface::lookupRecords(const Data& target, unsigned short type, DnsRawSink* sink)
00137 {
00138    mDnsProvider->lookup(target.c_str(), type, this, sink);
00139 }
00140 
00141 void 
00142 DnsInterface::handleDnsRaw(ExternalDnsRawResult res)
00143 {
00144    reinterpret_cast<DnsRawSink*>(res.userData)->onDnsRaw(res.errorCode(), res.abuf, res.alen);
00145    mDnsProvider->freeResult(res);
00146 }
00147 */
00148 
00149 //  Copyright (c) 2003, Jason Fischl 
00150 /* ====================================================================
00151  * The Vovida Software License, Version 1.0 
00152  * 
00153  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00154  * 
00155  * Redistribution and use in source and binary forms, with or without
00156  * modification, are permitted provided that the following conditions
00157  * are met:
00158  * 
00159  * 1. Redistributions of source code must retain the above copyright
00160  *    notice, this list of conditions and the following disclaimer.
00161  * 
00162  * 2. Redistributions in binary form must reproduce the above copyright
00163  *    notice, this list of conditions and the following disclaimer in
00164  *    the documentation and/or other materials provided with the
00165  *    distribution.
00166  * 
00167  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00168  *    and "Vovida Open Communication Application Library (VOCAL)" must
00169  *    not be used to endorse or promote products derived from this
00170  *    software without prior written permission. For written
00171  *    permission, please contact vocal@vovida.org.
00172  *
00173  * 4. Products derived from this software may not be called "VOCAL", nor
00174  *    may "VOCAL" appear in their name, without prior written
00175  *    permission of Vovida Networks, Inc.
00176  * 
00177  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00178  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00179  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00180  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00181  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00182  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00183  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00184  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00185  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00186  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00187  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00188  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00189  * DAMAGE.
00190  * 
00191  * ====================================================================
00192  * 
00193  * This software consists of voluntary contributions made by Vovida
00194  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00195  * Inc.  For more information on Vovida Networks, Inc., please see
00196  * <http://www.vovida.org/>.
00197  *
00198  */
00199