reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
AresDns.hxx
Go to the documentation of this file.
1#if !defined(RESIP_ARES_DNS_HXX)
2#define RESIP_ARES_DNS_HXX
3
4#include "rutil/HashMap.hxx"
7
8extern "C"
9{
10struct ares_channeldata;
11}
12
13//struct fd_set;
14
15extern "C" {
16 void resip_AresDns_aresCallback(void *arg, int status, unsigned char* abuf, int alen);
17 void resip_AresDns_caresCallback(void *arg, int status, int timeouts, unsigned char* abuf, int alen);
18}
19
20namespace resip
21{
22class AresDnsPollItem;
23class FdPollGrp;
24
25class AresDns : public ExternalDns
26{
27 friend class AresDnsPollItem;
28 public:
29 AresDns() : mChannel(0), mSocketFunc(0), mFeatures(0), mPollGrp(NULL), mDestroying(false) { }
30 virtual ~AresDns();
31
32 virtual int init(const std::vector<GenericIPAddress>& additionalNameservers,
33 AfterSocketCreationFuncPtr socketfunc, int timeout=0, int tries=0, unsigned int features=0);
34 // reinitializes with the same additionalNameservers and AfterSocketCreationFuncPtr as last call to init
35 virtual int init(int dnsTimeout = 0, int dnsTries = 0, unsigned int features = 0);
36
37 int internalInit(const std::vector<GenericIPAddress>& additionalNameservers,
39 ares_channeldata** channel = 0, int timeout=0, int tries=0, bool useStateFunc=false);
40
41 virtual void changeNameServers(const std::vector<GenericIPAddress>& additional);
42 virtual bool checkDnsChange();
43
44 virtual unsigned int getTimeTillNextProcessMS();
45 virtual void process(FdSet& fdset);
46 virtual void buildFdSet(FdSet& fdset);
47
48 virtual void buildFdSet(fd_set& read, fd_set& write, int& size);
49 virtual void process(fd_set& read, fd_set& write);
50
51 virtual void setPollGrp(FdPollGrp *pollGrp);
52 virtual void processTimers();
53
54 //?dcm? I believe these need to do nothing in the ARES case.
55 virtual void freeResult(ExternalDnsRawResult /* res */) {}
56 virtual void freeResult(ExternalDnsHostResult /* res */) {}
57
58 virtual char* errorMessage(long errorCode);
59
60 void lookup(const char* target, unsigned short type, ExternalDnsHandler* handler, void* userData);
61
62 virtual bool hostFileLookup(const char* target, in_addr &addr);
63 virtual bool hostFileLookupLookupOnlyMode() { return mHostFileLookupOnlyMode; }
64 static void enableHostFileLookupOnlyMode(bool enable) { mHostFileLookupOnlyMode = enable; }
65
66 friend void ::resip_AresDns_aresCallback(void *arg, int status, unsigned char* abuf, int alen);
67 friend void ::resip_AresDns_caresCallback(void *arg, int status, int timeouts, unsigned char* abuf, int alen);
68
69 static const char* dnsRRTypeToString(int rrtype);
70
71 // used for epoll() interface to ares lib
72 // time_t mNow;
73
74 private:
75 void clearPollItems();
76
77 // c-ares socket callbacks, before and after the socket connects;
78 // both call mSocketFunc
79 static int caresSocketConfigure(Socket s, int type, void* data);
80 static int caresSocketConnected(Socket s, int type, void* data);
81
82 // What each query's callback is given: its handler and the handler's
83 // data, and the AresDns that made the query
84 struct Payload
85 {
86 Payload(ExternalDnsHandler* h, void* d, AresDns* o) : handler(h), userData(d), owner(o) {}
87 ExternalDnsHandler* handler;
88 void* userData;
89 AresDns* owner;
90 };
91 static ExternalDnsRawResult makeRawResult(void *arg, int status, unsigned char *abuf, int alen);
92 static ExternalDnsHandler* getHandler(void* arg);
93 struct ares_channeldata* mChannel;
94 std::vector<GenericIPAddress> mAdditionalNameservers;
96 unsigned int mFeatures;
97 volatile static bool mHostFileLookupOnlyMode;
98
99 FdPollGrp* mPollGrp;
100 typedef HashMap<Socket, AresDnsPollItem*> PollItemsMap;
101 PollItemsMap mPollItems;
102
103 // set by ~AresDns, so that the queries its channel fails with
104 // ARES_EDESTRUCTION are not reported
105 bool mDestroying;
106};
107
108}
109
110
111#endif
112
113/* ====================================================================
114 * The Vovida Software License, Version 1.0
115 *
116 * Copyright (c) 2026 SIP Spectrum, Inc. http://www.sipspectrum.com
117 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 *
123 * 1. Redistributions of source code must retain the above copyright
124 * notice, this list of conditions and the following disclaimer.
125 *
126 * 2. Redistributions in binary form must reproduce the above copyright
127 * notice, this list of conditions and the following disclaimer in
128 * the documentation and/or other materials provided with the
129 * distribution.
130 *
131 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
132 * and "Vovida Open Communication Application Library (VOCAL)" must
133 * not be used to endorse or promote products derived from this
134 * software without prior written permission. For written
135 * permission, please contact vocal@vovida.org.
136 *
137 * 4. Products derived from this software may not be called "VOCAL", nor
138 * may "VOCAL" appear in their name, without prior written
139 * permission of Vovida Networks, Inc.
140 *
141 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
142 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
143 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
144 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
145 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
146 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
147 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
148 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
149 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
150 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
151 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
152 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
153 * DAMAGE.
154 *
155 * ====================================================================
156 *
157 * This software consists of voluntary contributions made by Vovida
158 * Networks, Inc. and many individuals on behalf of Vovida Networks,
159 * Inc. For more information on Vovida Networks, Inc., please see
160 * <http://www.vovida.org/>.
161 *
162 * vi: set shiftwidth=3 expandtab:
163 */
void resip_AresDns_caresCallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen)
Definition AresDns.cxx:1052
void resip_AresDns_aresCallback(void *arg, int status, unsigned char *abuf, int alen)
Definition AresDns.cxx:1032
Wraps your platform's implementation of hash_map, hash_multimap, and hash_set.
virtual void freeResult(ExternalDnsRawResult)
Definition AresDns.hxx:55
virtual void setPollGrp(FdPollGrp *pollGrp)
Definition AresDns.cxx:435
virtual void processTimers()
Definition AresDns.cxx:916
friend class AresDnsPollItem
Definition AresDns.hxx:27
virtual bool checkDnsChange()
Definition AresDns.cxx:730
virtual void freeResult(ExternalDnsHostResult)
Definition AresDns.hxx:56
static const char * dnsRRTypeToString(int rrtype)
Definition AresDns.cxx:1060
int internalInit(const std::vector< GenericIPAddress > &additionalNameservers, AfterSocketCreationFuncPtr socketfunc, unsigned int features=0, ares_channeldata **channel=0, int timeout=0, int tries=0, bool useStateFunc=false)
Definition AresDns.cxx:511
virtual char * errorMessage(long errorCode)
Definition AresDns.cxx:978
virtual ~AresDns()
Definition AresDns.cxx:807
virtual int init(const std::vector< GenericIPAddress > &additionalNameservers, AfterSocketCreationFuncPtr socketfunc, int timeout=0, int tries=0, unsigned int features=0)
Definition AresDns.cxx:458
virtual unsigned int getTimeTillNextProcessMS()
Definition AresDns.cxx:873
void lookup(const char *target, unsigned short type, ExternalDnsHandler *handler, void *userData)
Definition AresDns.cxx:1014
virtual bool hostFileLookup(const char *target, in_addr &addr)
Definition AresDns.cxx:817
static void enableHostFileLookupOnlyMode(bool enable)
Definition AresDns.hxx:64
virtual bool hostFileLookupLookupOnlyMode()
Definition AresDns.hxx:63
virtual void process(FdSet &fdset)
Definition AresDns.cxx:930
virtual void changeNameServers(const std::vector< GenericIPAddress > &additional)
Definition AresDns.cxx:725
virtual void buildFdSet(FdSet &fdset)
Definition AresDns.cxx:936
Object-oriented wrapper for your platform's file-descriptor set.
Definition Socket.hxx:162
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
Definition Socket.hxx:107
int Socket
Definition Socket.hxx:94
void list()
Definition userAdmin.cxx:66