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

Contents of /branches/b-identity-0505/AresDns.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: 6084 byte(s)
set svn:eol-style to LF
1 #include "resiprocate/AresDns.hxx"
2
3 #include "resiprocate/os/WinLeakCheck.hxx"
4
5 extern "C"
6 {
7 #include "ares.h"
8 #include "ares_dns.h"
9 }
10
11 #if !defined(USE_ARES)
12 #error Must have ARES
13 #endif
14
15 #if !defined(WIN32)
16 #if !defined(__CYGWIN__)
17 #include <arpa/nameser.h>
18 #endif
19 #endif
20
21 using namespace resip;
22
23 int
24 AresDns::init()
25 {
26 int status;
27 if ((status = ares_init(&mChannel)) != ARES_SUCCESS)
28 {
29 return status;
30 }
31 else
32 {
33 return 0;
34 }
35 }
36
37 AresDns::~AresDns()
38 {
39 ares_destroy(mChannel);
40 }
41
42 void
43 AresDns::lookupARecords(const char* target, ExternalDnsHandler* handler, void* userData)
44 {
45 ares_gethostbyname(mChannel, target, AF_INET, AresDns::aresHostCallback, new Payload(handler, userData));
46 }
47
48 void
49 AresDns::lookupAAAARecords(const char* target, ExternalDnsHandler* handler, void* userData)
50 {
51 ares_query(mChannel, target, C_IN, T_AAAA, AresDns::aresAAAACallback, new Payload(handler, userData));
52 }
53
54 void
55 AresDns::lookupNAPTR(const char* target, ExternalDnsHandler* handler, void* userData)
56 {
57 ares_query(mChannel, target, C_IN, T_NAPTR, AresDns::aresNAPTRCallback, new Payload(handler, userData));
58 }
59
60 void
61 AresDns::lookupSRV(const char* target, ExternalDnsHandler* handler, void* userData)
62 {
63 ares_query(mChannel, target, C_IN, T_SRV, AresDns::aresSRVCallback, new Payload(handler, userData));
64 }
65
66 ExternalDnsHandler*
67 AresDns::getHandler(void* arg)
68 {
69 Payload* p = reinterpret_cast<Payload*>(arg);
70 ExternalDnsHandler *thisp = reinterpret_cast<ExternalDnsHandler*>(p->first);
71 return thisp;
72 }
73
74 ExternalDnsRawResult
75 AresDns::makeRawResult(void *arg, int status, unsigned char *abuf, int alen)
76 {
77 Payload* p = reinterpret_cast<Payload*>(arg);
78 void* userArg = reinterpret_cast<void*>(p->second);
79
80 if (status != ARES_SUCCESS)
81 {
82 return ExternalDnsRawResult(status, userArg);
83 }
84 else
85 {
86 return ExternalDnsRawResult(abuf, alen, userArg);
87 }
88 }
89
90 void
91 AresDns::aresHostCallback(void *arg, int status, struct hostent* result)
92 {
93 Payload* p = reinterpret_cast<Payload*>(arg);
94 ExternalDnsHandler *thisp = reinterpret_cast<ExternalDnsHandler*>(p->first);
95 void* userArg = reinterpret_cast<void*>(p->second);
96
97 if (status != ARES_SUCCESS)
98 {
99 thisp->handle_host(ExternalDnsHostResult(status, userArg));
100 }
101 else
102 {
103 thisp->handle_host(ExternalDnsHostResult(result, userArg));
104 }
105 delete p;
106 }
107
108 void
109 AresDns::aresNAPTRCallback(void *arg, int status, unsigned char *abuf, int alen)
110 {
111 getHandler(arg)->handle_NAPTR(makeRawResult(arg, status, abuf, alen));
112 Payload* p = reinterpret_cast<Payload*>(arg);
113 delete p;
114 }
115
116 void
117 AresDns::aresSRVCallback(void *arg, int status, unsigned char *abuf, int alen)
118 {
119 getHandler(arg)->handle_SRV(makeRawResult(arg, status, abuf, alen));
120 Payload* p = reinterpret_cast<Payload*>(arg);
121 delete p;
122 }
123
124 void
125 AresDns::aresAAAACallback(void *arg, int status, unsigned char *abuf, int alen)
126 {
127 getHandler(arg)->handle_AAAA(makeRawResult(arg, status, abuf, alen));
128 Payload* p = reinterpret_cast<Payload*>(arg);
129 delete p;
130 }
131
132 bool
133 AresDns::requiresProcess()
134 {
135 return true;
136 }
137
138 void
139 AresDns::buildFdSet(fd_set& read, fd_set& write, int& size)
140 {
141 int newsize = ares_fds(mChannel, &read, &write);
142 if ( newsize > size )
143 {
144 size = newsize;
145 }
146 }
147
148 void
149 AresDns::process(fd_set& read, fd_set& write)
150 {
151 ares_process(mChannel, &read, &write);
152 }
153
154 char*
155 AresDns::errorMessage(long errorCode)
156 {
157 const char* aresMsg = ares_strerror(errorCode);
158
159 int len = strlen(aresMsg);
160 char* errorString = new char[len+1];
161
162 strncpy(errorString, aresMsg, len);
163 errorString[len] = '\0';
164 return errorString;
165 }
166
167 /* ====================================================================
168 * The Vovida Software License, Version 1.0
169 *
170 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
171 *
172 * Redistribution and use in source and binary forms, with or without
173 * modification, are permitted provided that the following conditions
174 * are met:
175 *
176 * 1. Redistributions of source code must retain the above copyright
177 * notice, this list of conditions and the following disclaimer.
178 *
179 * 2. Redistributions in binary form must reproduce the above copyright
180 * notice, this list of conditions and the following disclaimer in
181 * the documentation and/or other materials provided with the
182 * distribution.
183 *
184 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
185 * and "Vovida Open Communication Application Library (VOCAL)" must
186 * not be used to endorse or promote products derived from this
187 * software without prior written permission. For written
188 * permission, please contact vocal@vovida.org.
189 *
190 * 4. Products derived from this software may not be called "VOCAL", nor
191 * may "VOCAL" appear in their name, without prior written
192 * permission of Vovida Networks, Inc.
193 *
194 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
195 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
197 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
198 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
199 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
200 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
201 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
202 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
203 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
204 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
205 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
206 * DAMAGE.
207 *
208 * ====================================================================
209 *
210 * This software consists of voluntary contributions made by Vovida
211 * Networks, Inc. and many individuals on behalf of Vovida Networks,
212 * Inc. For more information on Vovida Networks, Inc., please see
213 * <http://www.vovida.org/>.
214 *
215 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27