reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DnsInterface.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#ifndef WIN32
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <arpa/inet.h>
9#ifndef __CYGWIN__
10# include <netinet/in.h>
11# include <arpa/nameser.h>
12# include <resolv.h>
13#endif
14#endif
15
16#include "rutil/compat.hxx"
17#include "rutil/Logger.hxx"
19#include "rutil/Socket.hxx"
20
21#include "rutil/dns/DnsStub.hxx"
22#include "rutil/dns/RRVip.hxx"
26
27//#include "rutil/dns/ExternalDnsFactory.hxx"
29
30
31using namespace resip;
32
33#define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS
34
35DnsInterface::DnsInterface(DnsStub& dnsStub, bool useDnsVip) :
36 mUdpOnlyOnNumeric(false),
37 mDnsStub(dnsStub)
38{
39 if (useDnsVip)
40 {
42 }
43}
44
48
49void
51{
52 const Data* pNaptrType = getSupportedNaptrType(type);
53 auto ts = std::make_pair(type, version);
55 mSupportedTransports[std::move(ts)]++;
56 if (pNaptrType)
57 {
58 mSupportedNaptrs[*pNaptrType]++;
59 }
60
61 //logSupportedTransports();
62}
63
64void
66{
67 const Data* pNaptrType = getSupportedNaptrType(type);
68
70 TransportMap::iterator itTrans = mSupportedTransports.find(std::make_pair(type, version));
71 if(itTrans != mSupportedTransports.end())
72 {
73 // Remove from map if ref count hits zero
74 if(--itTrans->second == 0)
75 {
76 mSupportedTransports.erase(itTrans);
77 }
78 }
79
80 if(pNaptrType)
81 {
82 SupportedNaptrMap::iterator itNT = mSupportedNaptrs.find(*pNaptrType);
83 if(itNT != mSupportedNaptrs.end())
84 {
85 // Remove from map if ref count hits zero
86 if(--itNT->second == 0)
87 {
88 mSupportedNaptrs.erase(itNT);
89 }
90 }
91 }
92 //logSupportedTransports();
93}
94
95static Data UdpNAPTRType("SIP+D2U");
96static Data TcpNAPTRType("SIP+D2T");
97static Data TlsNAPTRType("SIPS+D2T");
98static Data DtlsNAPTRType("SIPS+D2U");
99static Data WsNAPTRType("SIP+D2W");
100static Data WssNAPTRType("SIPS+D2W");
101const Data*
103{
104 Data* pNaptrType = 0;
105 switch (type)
106 {
107 case UDP:
108 pNaptrType = &UdpNAPTRType;
109 break;
110 case TCP:
111 pNaptrType = &TcpNAPTRType;
112 break;
113 case TLS:
114 pNaptrType = &TlsNAPTRType;
115 break;
116 case DTLS:
117 pNaptrType = &DtlsNAPTRType;
118 break;
119 case WS:
120 pNaptrType = &WsNAPTRType;
121 break;
122 case WSS:
123 pNaptrType = &WssNAPTRType;
124 break;
125 default:
126 resip_assert(0);
127 break;
128 }
129 return pNaptrType;
130}
131
132void
134{
135 TransportMap::iterator itTrans = mSupportedTransports.begin();
136 for(; itTrans != mSupportedTransports.end(); itTrans++)
137 {
138 InfoLog(<< "logSupportedTransports: mSupportedTransports[" << toData(itTrans->first.first) << "," << (itTrans->first.second == V4 ? "V4" : "V6") << "] = " << itTrans->second);
139 }
140
141 SupportedNaptrMap::iterator itNT = mSupportedNaptrs.begin();
142 for(; itNT != mSupportedNaptrs.end(); itNT++)
143 {
144 InfoLog(<< "logSupportedTransports: mSupportedNaptrs[" << itNT->first << "] = " << itNT->second);
145 }
146}
147
148bool
150{
151 Lock lock(mSupportedMutex);
152 return mSupportedNaptrs.find(service) != mSupportedNaptrs.end();
153}
154
155bool
157{
158 auto ts = std::make_pair(t, version);
159
160 Lock lock(mSupportedMutex);
161 return mSupportedTransports.find(ts) != mSupportedTransports.end();
162}
163
164bool
166{
167 Lock lock(mSupportedMutex);
168 for (TransportMap::const_iterator i=mSupportedTransports.begin(); i != mSupportedTransports.end(); ++i)
169 {
170 if (i->first.first == t)
171 {
172 return true;
173 }
174 }
175 return false;
176}
177
179{
180 Lock lock(mSupportedMutex);
181 return (int)mSupportedTransports.size();
182}
183
186{
187 DnsResult* result = new DnsResult(*this, mDnsStub, mVip, handler);
188 return result;
189}
190
191void
193{
194 res->lookup(uri);
195}
196
197//?dcm? -- why is this here?
201
202
203// Copyright (c) 2003, Jason Fischl
204/* ====================================================================
205 * The Vovida Software License, Version 1.0
206 *
207 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
208 *
209 * Redistribution and use in source and binary forms, with or without
210 * modification, are permitted provided that the following conditions
211 * are met:
212 *
213 * 1. Redistributions of source code must retain the above copyright
214 * notice, this list of conditions and the following disclaimer.
215 *
216 * 2. Redistributions in binary form must reproduce the above copyright
217 * notice, this list of conditions and the following disclaimer in
218 * the documentation and/or other materials provided with the
219 * distribution.
220 *
221 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
222 * and "Vovida Open Communication Application Library (VOCAL)" must
223 * not be used to endorse or promote products derived from this
224 * software without prior written permission. For written
225 * permission, please contact vocal@vovida.org.
226 *
227 * 4. Products derived from this software may not be called "VOCAL", nor
228 * may "VOCAL" appear in their name, without prior written
229 * permission of Vovida Networks, Inc.
230 *
231 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
232 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
233 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
234 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
235 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
236 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
237 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
238 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
239 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
240 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
242 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
243 * DAMAGE.
244 *
245 * ====================================================================
246 *
247 * This software consists of voluntary contributions made by Vovida
248 * Networks, Inc. and many individuals on behalf of Vovida Networks,
249 * Inc. For more information on Vovida Networks, Inc., please see
250 * <http://www.vovida.org/>.
251 *
252 */
253
static Data DtlsNAPTRType("SIPS+D2U")
static Data TlsNAPTRType("SIPS+D2T")
static Data UdpNAPTRType("SIP+D2U")
static Data WsNAPTRType("SIP+D2W")
static Data WssNAPTRType("SIPS+D2W")
static Data TcpNAPTRType("SIP+D2T")
#define InfoLog(args_)
Definition Logger.hxx:131
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * begin() const noexcept
Returns a pointer to the beginning of the buffer used by the Data.
Definition Data.hxx:642
virtual ~DnsHandler()=0
const Data * getSupportedNaptrType(TransportType type)
void addTransportType(TransportType type, IpVersion version)
void lookup(DnsResult *res, const Uri &uri)
TransportMap mSupportedTransports
friend class DnsResult
bool isSupportedProtocol(TransportType t)
SupportedNaptrMap mSupportedNaptrs
DnsInterface(DnsStub &dnsStub, bool useDnsVip=false)
void removeTransportType(TransportType type, IpVersion version)
bool isSupported(const Data &service)
DnsResult * createDnsResult(DnsHandler *handler=0)
void lookup(const Uri &uri)
void setResultTransform(ResultTransform *)
Definition DnsStub.cxx:397
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
dcm! – add UnusedChecking(_enum) below;
const resip::Data & toData(const TransportType typeEnum)
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28
TransportType
An enumeration of transport protocols.
IpVersion
An enumeration of IP versions.