/usr/include/resip/stack/DnsResult.hxx is in libresiprocate-1.9-dev 1.9.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | #if !defined(RESIP_DNSRESULT_HXX)
#define RESIP_DNSRESULT_HXX
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iosfwd>
#include <set>
#include <vector>
#include <deque>
#include <map>
#include <stack>
#include "resip/stack/Tuple.hxx"
#include "resip/stack/Transport.hxx"
#include "resip/stack/Uri.hxx"
#include "rutil/Condition.hxx"
#include "rutil/HeapInstanceCounter.hxx"
#include "rutil/dns/RRVip.hxx"
#include "rutil/dns/DnsStub.hxx"
#ifdef WIN32
#include <Ws2tcpip.h>
#endif
struct hostent;
namespace resip
{
class DnsInterface;
class DnsAAAARecord;
class DnsHandler;
class EnumResultSink
{
public:
virtual void onEnumResult(const DNSResult<DnsNaptrRecord>& result,
int order) = 0;
};
class EnumResult : public DnsResultSink
{
public:
EnumResult(EnumResultSink& resultSink, int order);
~EnumResult();
// DnsResultSink
void onDnsResult(const DNSResult<DnsHostRecord>&);
//#ifdef USE_IPV6
void onDnsResult(const DNSResult<DnsAAAARecord>&);
//#endif
void onDnsResult(const DNSResult<DnsSrvRecord>&);
void onDnsResult(const DNSResult<DnsNaptrRecord>&);
void onDnsResult(const DNSResult<DnsCnameRecord>&);
void onEnumResult(const DNSResult<DnsNaptrRecord>& result);
void onNaptrResult(const DNSResult<DnsNaptrRecord>& result);
private:
EnumResultSink& mResultSink;
int mOrder;
};
class DnsResult : public DnsResultSink, public EnumResultSink
{
public:
RESIP_HeapCount(DnsResult);
DnsResult(DnsInterface& interfaceObj, DnsStub& dns, RRVip& vip, DnsHandler* handler);
virtual ~DnsResult();
typedef enum
{
Available, // A result is available now
Pending, // More results may be pending
Finished, // No more results available and none pending
Destroyed // the associated transaction has been deleted
// (ie, this DnsResult will delete itself as soon as it
// gets a new result)
} Type;
typedef std::vector<Data> DataVector;
/*! Starts a lookup. Has the rules for determining the transport
from a uri as per rfc3263 and then does a NAPTR lookup or an A
lookup depending on the uri.
@param uri The uri to resolve.
@param enumSuffixes If the uri is enum searchable, this is the list of
enum suffixes (for example "e164.arpa") that will be used in
the attempt to resolve this uri.
@param enumDomains The ENUM possibility is only considered if
the URI domain part is one of these domains
*/
void lookup(const Uri& uri, const std::vector<Data> &enumSuffixes,
const std::map<Data,Data> &enumDomains);
/*!
Blacklist the last returned result until the specified time (ms)
@param expiry The absolute expiry, in ms, of this blacklist.
@return true iff the last result could be blacklisted
@note This is a no-op if no results have been returned.
*/
bool blacklistLast(UInt64 expiry);
/*!
Greylist the last returned result until the specified time (ms)
Greylisting a tuple effectively de-prioritizes it, so it will not be
tried if there are any non-grey or blacklisted tuples left to try.
@param expiry The absolute expiry, in ms, of this blacklist.
@return true iff the last result could be greylisted
@note This is a no-op if no results have been returned.
*/
bool greylistLast(UInt64 expiry);
/*!
Tries to load the next tuple. If Available is returned, the tuple may
be accessed using current().
@return Available if there is a result ready, Pending if it needs to
follow an SRV (more results might come in later), or Finished
if there are definitively no more results.
@note ALWAYS call this before calling next()
*/
Type available();
/*!
Return the next tuple available for this query.
@return The next Tuple available for this query.
@note ALWAYS call available() and verify the return is Available
before calling this function.
@note This no longer results in the last result being blacklisted. To
blacklist the last result, use blacklistLast().
*/
Tuple next();
/*!
Whitelist the last tuple returned by next(). This means that the path
to this result (NAPTR->SRV->A/AAAA) will be favored by the resolver
from now on. (ie, this NAPTR will be favored above all others that
match, even if the order/preference changes in the DNS, and this
A/AAAA record will be favored above all others that match, even if new
ones are added.)
@note It can be argued that using this is harmful, since the load-
leveling capabilities of DNS are ignored from here on.
@note This will also re-order SRV records, but the order in which
SRVs arrive is ignored by DnsResult (they are just re-sorted)
*/
void whitelistLast();
// return the target of associated query
Data target() const { return mTarget; }
unsigned int getSRVResultsSize() const {return (unsigned int)mSRVResults.size();}
// Will delete this DnsResult if no pending queries are out there or wait
// until the pending queries get responses and then delete
void destroy();
// Used to store a NAPTR result
class NAPTR
{
public:
NAPTR();
// As defined by RFC3263
bool operator<(const NAPTR& rhs) const;
Data key; // NAPTR record key
int order;
int pref;
Data flags;
Data service;
DnsNaptrRecord::RegExp regex;
Data replacement;
};
class SRV
{
public:
SRV();
// As defined by RFC3263, RFC2782
bool operator<(const SRV& rhs) const;
Data key; // SRV record key
int naptrpref;
TransportType transport;
int priority;
int weight;
int port;
Data target;
};
private:
void lookupInternal(const Uri& uri);
// Given a transport and port from uri, return the default port to use
int getDefaultPort(TransportType transport, int port);
void lookupHost(const Data& target);
// compute the cumulative weights for the SRV entries with the lowest
// priority, then randomly pick according to RFC2782 from the entries with
// the lowest priority based on weights. When all entries at the lowest
// priority are chosen, pick the next lowest priority and repeat. After an
// SRV entry is selected, remove it from mSRVResults
SRV retrieveSRV();
// Will retrieve the next SRV record and compute the prime the mResults
// with the appropriate Tuples.
void primeResults();
private:
DnsInterface& mInterface;
DnsStub& mDns;
RRVip& mVip;
DnsHandler* mHandler;
int mSRVCount;
Uri mInputUri;
int mDoingEnum;
std::map<int,Uri> mEnumDestinations;
resip::Mutex mEnumDestinationsMutex;
bool mSips;
Data mTarget;
Data mSrvKey;
TransportType mTransport; // current
int mPort; // current
/*!
@author bwc
This is set to true when the RFC 3263 logic has chosen the transport
it will be using. Incoming SRVs will be filtered according to
mTransport if mHaveChosenTransport is true. It is VITAL that this
boolean not change during the phase where we are acquiring/processing
SRV records, because the state of this boolean denotes whether we
filtered incoming SRVs or not. (If it changes halfway through, some
of the SRVs will have been filtered, but some won't, and this will
break retrieveSRV() )
*/
bool mHaveChosenTransport;
/*!
@author bwc
DnsResult::transition is the ONLY function that should ever touch this
(This is because we need to notify mInterface when we are done making
queries, and this is when we transition from either Pending or
Available to either Destroyed or Finished.)
*/
Type mType;
//Ugly hack
Data mPassHostFromAAAAtoA;
void transition(Type t);
// This is where the current pending (ordered) results are stored. As they
// are retrieved by calling next(), they are popped from the front of the list
std::deque<Tuple> mResults;
std::vector<Tuple> mGreylistedTuples;
// Map of NAPTR records by replacement (ie. SRV lookup key)
std::map<Data, NAPTR> mTopOrderedNAPTRs;
// used in determining the next SRV record to use as per rfc2782
int mCumulativeWeight; // for current priority
// All SRV records sorted in order of preference
std::vector<SRV> mSRVResults;
friend class DnsInterface;
friend EncodeStream& operator<<(EncodeStream& strm, const DnsResult&);
friend EncodeStream& operator<<(EncodeStream& strm, const DnsResult::SRV&);
friend EncodeStream& operator<<(EncodeStream& strm, const DnsResult::NAPTR&);
// DnsResultSink
void onDnsResult(const DNSResult<DnsHostRecord>&);
//#ifdef USE_IPV6
void onDnsResult(const DNSResult<DnsAAAARecord>&);
//#endif
void onDnsResult(const DNSResult<DnsSrvRecord>&);
void onDnsResult(const DNSResult<DnsNaptrRecord>&);
void onDnsResult(const DNSResult<DnsCnameRecord>&);
void onEnumResult(const DNSResult<DnsNaptrRecord>& result, int order);
void onNaptrResult(const DNSResult<DnsNaptrRecord>& result);
typedef struct
{
Data domain;
int rrType;
Data value; // stores ip for A/AAAA, target host:port for SRV, and replacement for NAPTR.
} Item;
/*!
@author bwc
This is a snapshot of mCurrentPath when it was returned last.
(This will be empty if we haven't returned anything)
This is primarily used for whitelisting the last returned result.
*/
std::vector<Item> mLastReturnedPath;
/*!
@author bwc
The current DNS path we are working on.
(ie NAPTR -> SRV -> A/AAAA) There is at most one of these types
in here at any given time, and they will always be in order.
This exists solely to allow mLastReturnedPath to be defined.
*/
std::vector<Item> mCurrentPath;
bool mHaveReturnedResults;
void clearCurrPath();
Tuple mLastResult;
};
EncodeStream& operator<<(EncodeStream& strm, const DnsResult&);
EncodeStream& operator<<(EncodeStream& strm, const DnsResult::SRV&);
EncodeStream& operator<<(EncodeStream& strm, const DnsResult::NAPTR&);
}
#endif
// Copyright (c) 2003, Jason Fischl
/* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by Vovida
* Networks, Inc. and many individuals on behalf of Vovida Networks,
* Inc. For more information on Vovida Networks, Inc., please see
* <http://www.vovida.org/>.
*
*/
|