37#ifndef ASYNC_DNS_LOOKUP_INCLUDED
38#define ASYNC_DNS_LOOKUP_INCLUDED
47#include <sigc++/sigc++.h>
126 template <
class RR>
using RRList = std::vector<std::unique_ptr<RR>>;
127 template <
class RR>
using SharedRRList = std::vector<std::shared_ptr<RR>>;
214 const std::string &
label(
void)
const {
return m_label; }
252 bool empty(
void)
const {
return resourceRecordsP().empty(); }
309 cloneResourceRecords(rrs,
type);
329 cloneResourceRecords(rrs, RR::staticType());
336 cloneResourceRecords(rrs, RR::staticType());
346 typedef std::vector<DnsResourceRecord*> RRListP;
349 Type m_type = Type::A;
350 DnsLookupWorker* m_worker = 0;
352 std::default_random_engine m_rng;
354 void onResultsReady(
void);
355 const RRListP& resourceRecordsP(
void)
const;
360 for (
const auto& rr : resourceRecordsP())
362 if ((
type == RR::Type::ANY) || (rr->type() ==
type))
364 rrs.push_back(std::unique_ptr<RR>(
static_cast<RR*
>(rr->clone())));
372 for (
const auto& rr : resourceRecordsP())
374 if ((
type == RR::Type::ANY) || (rr->type() ==
type))
376 rrs.push_back(std::shared_ptr<RR>(
static_cast<RR*
>(rr->clone())));
A collection of classes representing DNS resource records.
Platform independent representation of an IP address.
A class for performing asynchronous DNS lookups.
std::vector< std::unique_ptr< RR > > RRList
~DnsLookup(void)
Destructor.
void resourceRecords(SharedRRList< RR > &rrs) const
void resourceRecords(RRList< RR > &rrs) const
Return resource records of a specific type.
std::vector< std::shared_ptr< RR > > SharedRRList
bool recordsValid(void) const
Check if the cached records are valid.
DnsResourceRecord::List resourceRecords(Type type=Type::ANY) const
Return all matching resource records.
DnsLookup & operator=(DnsLookup &&other)
Move assignment operator.
const RRList< DnsResourceRecord > & staticResourceRecords(void) const
Get all previously added static resource records.
bool empty(void) const
Check if the query returned any answers.
const std::string & label(void) const
Return the associated label.
std::string typeStr(void) const
Return the type of lookup as a string.
void abort(void)
Abort a pending lookup.
bool lookupFailed(void) const
Check if the lookup failed.
bool lookup(const std::string &label, Type type=Type::A)
Start a DNS lookup.
void addStaticResourceRecord(DnsResourceRecord *rr)
Add a static resource record to the lookup result.
DnsLookup(void)
Default Constructor.
bool resultsAreReady(void) const
Check if the DNS lookup is done or not.
std::vector< IpAddress > addresses(void)
Return the addresses for the host in the query.
DnsResourceRecord::Type Type
sigc::signal< void, DnsLookup & > resultsReady
A signal to indicate that the query has been completed.
bool lookup(void)
Start a DNS lookup using previously configured parameters.
DnsLookup(const std::string &label, Type type=Type::A)
Constructor.
Type type(void) const
Return the type of lookup.
bool isPending(void) const
Check if a DNS lookup is pending.
void clear(void)
Remove any cached DNS resource records.
void setLookupParams(const std::string &label, Type type=Type::A)
Prepare a lookup by setting up query parameters.
The base class for representing a DNS resource record.
std::vector< std::unique_ptr< DnsResourceRecord > > List
The type for a list of resource records.
static const std::string & typeToString(Type type)
The type for this specific class represented as a string.
Namespace for the asynchronous programming classes.