reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RRList.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include <vector>
6#include <list>
7
8#include "ares.h"
9#ifdef WIN32
10#undef write // Note: ares.h defines write to be _write for WIN32 - we don't want that here, since we use fdset.write and stream write
11#endif
12
13#include "AresCompat.hxx"
14
15#ifndef WIN32
16#ifndef __CYGWIN__
17#include <arpa/nameser.h>
18#endif
19#endif
20
21#include "rutil/Logger.hxx"
22#include "rutil/compat.hxx"
24#include "rutil/Timer.hxx"
25#include "rutil/DnsUtil.hxx"
26#include "rutil/dns/AresDns.hxx"
30#include "rutil/dns/RRList.hxx"
36
37using namespace resip;
38using namespace std;
39
40#define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS
41
42RRList::RRList() : mRRType(0), mStatus(0), mAbsoluteExpiry(ULONG_MAX) {}
43
44RRList::RRList(const Data& key,
45 const int rrtype,
46 int ttl,
47 int status)
48 : mKey(key), mRRType(rrtype), mStatus(status)
49{
50 mAbsoluteExpiry = ttl + Timer::getTimeSecs();
51}
52
53RRList::RRList(const DnsHostRecord &record, int ttl)
54 : mKey(record.name()), mRRType(T_A), mStatus(0), mAbsoluteExpiry(ULONG_MAX)
55{
56 update(record, ttl);
57}
58
59void RRList::update(const DnsHostRecord &record, int ttl)
60{
61 this->clear();
62
63 RecordItem item;
64 item.record = new DnsHostRecord(record);
65 mRecords.push_back(item);
66 mAbsoluteExpiry = Timer::getTimeSecs() + ttl;
67}
68
69RRList::RRList(const Data& key, int rrtype)
70 : mKey(key), mRRType(rrtype), mStatus(0), mAbsoluteExpiry(ULONG_MAX)
71{}
72
74{
75 this->clear();
76}
77
79 const Data& key,
80 const int rrType,
81 Itr begin,
82 Itr end,
83 int ttl)
84 : mKey(key), mRRType(rrType), mStatus(0)
85{
86 update(factory, begin, end, ttl);
87}
88
89void RRList::update(const RRFactoryBase* factory, Itr begin, Itr end, int ttl)
90{
91 this->clear();
92 mAbsoluteExpiry = ULONG_MAX;
93
94 // Add each record and track the lowest ttl of all the records
95 for (Itr it = begin; it != end; it++)
96 {
97 try
98 {
99 RecordItem item;
100 item.record = factory->create(*it);
101 mRecords.push_back(item);
102 if ((uint64_t)it->ttl() < mAbsoluteExpiry)
103 {
104 mAbsoluteExpiry = it->ttl();
105 }
106 }
107 catch (BaseException& e)
108 {
109 ErrLog(<< e.getMessage() << endl);
110 }
111 }
112
113 if (mAbsoluteExpiry == ULONG_MAX || mAbsoluteExpiry < (uint64_t)ttl)
114 {
115 mAbsoluteExpiry = ttl;
116 }
117
118 mAbsoluteExpiry += Timer::getTimeSecs();
119}
120
122{
124 if (mRecords.empty()) return records;
125
126 for (std::vector<RecordItem>::iterator it = mRecords.begin(); it != mRecords.end(); ++it)
127 {
128 records.push_back((*it).record);
129 }
130 return records;
131}
132
133RRList::RecordItr RRList::find(const Data& value)
134{
135 for (RecordItr it = mRecords.begin(); it != mRecords.end(); ++it)
136 {
137 if ((*it).record->isSameValue(value))
138 {
139 return it;
140 }
141 }
142 return mRecords.end();
143}
144
145void RRList::clear()
146{
147 for (RecordArr::iterator it = mRecords.begin(); it != mRecords.end(); ++it)
148 {
149 delete (*it).record;
150 }
151 mRecords.clear();
152}
153
155RRList::encodeRRList(EncodeStream& strm)
156{
157 strm << "Key=" << mKey << ", Type=" << AresDns::dnsRRTypeToString(mRRType) << ", secsToExpirey=" << (mAbsoluteExpiry - Timer::getTimeSecs()) << ", status=" << mStatus << ", numRecords=" << mRecords.size();
158 int recNum = 0;
159 for (RecordArr::iterator it = mRecords.begin(); it != mRecords.end(); ++it)
160 {
161 recNum++;
162 strm << endl << " Record " << recNum << ": ";
163 it->record->dump(strm);
164 }
165 return strm;
166}
167
168
169/* ====================================================================
170 * The Vovida Software License, Version 1.0
171 *
172 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
173 * Copyright (c) 2010 SIP Spectrum, Inc. All rights reserved.
174 *
175 * Redistribution and use in source and binary forms, with or without
176 * modification, are permitted provided that the following conditions
177 * are met:
178 *
179 * 1. Redistributions of source code must retain the above copyright
180 * notice, this list of conditions and the following disclaimer.
181 *
182 * 2. Redistributions in binary form must reproduce the above copyright
183 * notice, this list of conditions and the following disclaimer in
184 * the documentation and/or other materials provided with the
185 * distribution.
186 *
187 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
188 * and "Vovida Open Communication Application Library (VOCAL)" must
189 * not be used to endorse or promote products derived from this
190 * software without prior written permission. For written
191 * permission, please contact vocal@vovida.org.
192 *
193 * 4. Products derived from this software may not be called "VOCAL", nor
194 * may "VOCAL" appear in their name, without prior written
195 * permission of Vovida Networks, Inc.
196 *
197 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
198 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
200 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
201 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
202 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
203 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
204 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
206 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
207 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
208 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
209 * DAMAGE.
210 *
211 * ====================================================================
212 *
213 * This software consists of voluntary contributions made by Vovida
214 * Networks, Inc. and many individuals on behalf of Vovida Networks,
215 * Inc. For more information on Vovida Networks, Inc., please see
216 * <http://www.vovida.org/>.
217 *
218 */
#define ErrLog(args_)
Definition Logger.hxx:137
static const char * dnsRRTypeToString(int rrtype)
Definition AresDns.cxx:1060
The abstract base-class for all exceptions thrown by resip code.
const Data & getMessage() const noexcept
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
virtual DnsResourceRecord * create(const RROverlay &) const =0
std::vector< RROverlay >::const_iterator Itr
Definition RRList.hxx:30
Records records(const int protocol)
Definition RRList.cxx:121
EncodeStream & encodeRRList(EncodeStream &strm)
Definition RRList.cxx:155
std::vector< DnsResourceRecord * > Records
Definition RRList.hxx:28
void update(const DnsHostRecord &record, int ttl)
Definition RRList.cxx:59
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Timer.hxx:78
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
#define T_A
Definition compat.hxx:152
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39
#define EncodeStream