/[resiprocate]/branches/b-identity-0505/DnsInterface.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/DnsInterface.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 6887 byte(s)
set svn:eol-style to LF
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #if defined(USE_ARES)
6 extern "C"
7 {
8 #include "ares.h"
9 #include "ares_dns.h"
10 }
11 #endif
12
13 #include "resiprocate/os/compat.hxx"
14 #include "resiprocate/os/Logger.hxx"
15
16 #include "resiprocate/DnsInterface.hxx"
17 #include "resiprocate/DnsHandler.hxx"
18 #include "resiprocate/DnsResult.hxx"
19
20 #include "resiprocate/ExternalDnsFactory.hxx"
21 #include "resiprocate/os/WinLeakCheck.hxx"
22
23
24 using namespace resip;
25
26 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS
27
28 DnsInterface::DnsInterface() :
29 mDnsProvider(ExternalDnsFactory::createExternalDns()),
30 mActiveQueryCount(0)
31 {
32 int retCode = mDnsProvider->init();
33 if (retCode != 0)
34 {
35 ErrLog (<< "Failed to initialize async dns library");
36 char* errmem = mDnsProvider->errorMessage(retCode);
37 ErrLog (<< errmem);
38 delete errmem;
39 throw Exception("failed to initialize async dns library", __FILE__,__LINE__);
40 }
41 }
42
43 DnsInterface::~DnsInterface()
44 {
45 delete mDnsProvider;
46 }
47
48 void
49 DnsInterface::lookupARecords(const Data& target, DnsResult* dres)
50 {
51 mDnsProvider->lookupARecords(target.c_str(), this, dres);
52 }
53
54 void
55 DnsInterface::lookupAAAARecords(const Data& target, DnsResult* dres)
56 {
57 mDnsProvider->lookupAAAARecords(target.c_str(), this, dres);
58 }
59
60 void
61 DnsInterface::lookupNAPTR(const Data& target, DnsResult* dres)
62 {
63 mDnsProvider->lookupNAPTR(target.c_str(), this, dres);
64 }
65
66 void
67 DnsInterface::lookupSRV(const Data& target, DnsResult* dres)
68 {
69 mDnsProvider->lookupSRV(target.c_str(), this, dres);
70 }
71
72 Data
73 DnsInterface::errorMessage(int status)
74 {
75 return Data(Data::Take, mDnsProvider->errorMessage(status));
76 }
77
78 void
79 DnsInterface::addTransportType(TransportType type, IpVersion version)
80 {
81 static Data Udp("SIP+D2U");
82 static Data Tcp("SIP+D2T");
83 static Data Tls("SIPS+D2T");
84 static Data Dtls("SIPS+D2U");
85
86 mSupportedTransports.push_back(std::make_pair(type, version));
87 switch (type)
88 {
89 case UDP:
90 mSupportedNaptrs.insert(Udp);
91 break;
92 case TCP:
93 mSupportedNaptrs.insert(Tcp);
94 break;
95 case TLS:
96 mSupportedNaptrs.insert(Tls);
97 break;
98 case DTLS:
99 mSupportedNaptrs.insert(Dtls);
100 break;
101 default:
102 assert(0);
103 break;
104 }
105 }
106
107 bool
108 DnsInterface::isSupported(const Data& service)
109 {
110 return mSupportedNaptrs.count(service) != 0;
111 }
112
113 bool
114 DnsInterface::isSupported(TransportType t, IpVersion version)
115 {
116 return std::find(mSupportedTransports.begin(), mSupportedTransports.end(), std::make_pair(t, version)) != mSupportedTransports.end();
117 }
118
119 bool
120 DnsInterface::isSupportedProtocol(TransportType t)
121 {
122 for (TransportMap::const_iterator i=mSupportedTransports.begin(); i != mSupportedTransports.end(); ++i)
123 {
124 if (i->first == t)
125 {
126 return true;
127 }
128 }
129 return false;
130 }
131
132 bool
133 DnsInterface::requiresProcess()
134 {
135 return mDnsProvider->requiresProcess() && mActiveQueryCount;
136 }
137
138 void
139 DnsInterface::buildFdSet(FdSet& fdset)
140 {
141 mDnsProvider->buildFdSet(fdset.read, fdset.write, fdset.size);
142 }
143
144 void
145 DnsInterface::process(FdSet& fdset)
146 {
147 mDnsProvider->process(fdset.read, fdset.write);
148 }
149
150
151 DnsResult*
152 DnsInterface::createDnsResult(DnsHandler* handler)
153 {
154 DnsResult* result = new DnsResult(*this, handler);
155 mActiveQueryCount++;
156 return result;
157 }
158
159 void
160 DnsInterface::lookup(DnsResult* res, const Uri& uri)
161 {
162 res->lookup(uri);
163 }
164
165
166
167 // DnsResult*
168 // DnsInterface::lookup(const Via& via, DnsHandler* handler)
169 // {
170 // assert(0);
171 // //DnsResult* result = new DnsResult(*this);
172 // return NULL;
173 // }
174
175 void
176 DnsInterface::handle_NAPTR(ExternalDnsRawResult res)
177 {
178 reinterpret_cast<DnsResult*>(res.userData)->processNAPTR(res.errorCode(), res.abuf, res.alen);
179 mDnsProvider->freeResult(res);
180 }
181
182 void
183 DnsInterface::handle_SRV(ExternalDnsRawResult res)
184 {
185 reinterpret_cast<DnsResult*>(res.userData)->processSRV(res.errorCode(), res.abuf, res.alen);
186 mDnsProvider->freeResult(res);
187 }
188
189 void
190 DnsInterface::handle_AAAA(ExternalDnsRawResult res)
191 {
192 reinterpret_cast<DnsResult*>(res.userData)->processAAAA(res.errorCode(), res.abuf, res.alen);
193 mDnsProvider->freeResult(res);
194 }
195
196 void
197 DnsInterface::handle_host(ExternalDnsHostResult res)
198 {
199 reinterpret_cast<DnsResult*>(res.userData)->processHost(res.errorCode(), res.host);
200 mDnsProvider->freeResult(res);
201 }
202
203 //?dcm? -- why is this here?
204 DnsHandler::~DnsHandler()
205 {
206 }
207
208 // Copyright (c) 2003, Jason Fischl
209 /* ====================================================================
210 * The Vovida Software License, Version 1.0
211 *
212 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
213 *
214 * Redistribution and use in source and binary forms, with or without
215 * modification, are permitted provided that the following conditions
216 * are met:
217 *
218 * 1. Redistributions of source code must retain the above copyright
219 * notice, this list of conditions and the following disclaimer.
220 *
221 * 2. Redistributions in binary form must reproduce the above copyright
222 * notice, this list of conditions and the following disclaimer in
223 * the documentation and/or other materials provided with the
224 * distribution.
225 *
226 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
227 * and "Vovida Open Communication Application Library (VOCAL)" must
228 * not be used to endorse or promote products derived from this
229 * software without prior written permission. For written
230 * permission, please contact vocal@vovida.org.
231 *
232 * 4. Products derived from this software may not be called "VOCAL", nor
233 * may "VOCAL" appear in their name, without prior written
234 * permission of Vovida Networks, Inc.
235 *
236 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
237 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
238 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
239 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
240 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
241 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
242 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
243 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
244 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
245 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
247 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
248 * DAMAGE.
249 *
250 * ====================================================================
251 *
252 * This software consists of voluntary contributions made by Vovida
253 * Networks, Inc. and many individuals on behalf of Vovida Networks,
254 * Inc. For more information on Vovida Networks, Inc., please see
255 * <http://www.vovida.org/>.
256 *
257 */
258

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27