/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. Christian Herdtweck, Intra2net AG 2015 */ #ifndef RESOLVER_BASE_H #define RESOLVER_BASE_H #include #include #include #include "host/pinger.h" #include "dns/dnsipprotocol.h" #include "dns/hostaddress.h" #include "dns/dnscache.h" typedef boost::function callback_type; typedef std::queue callback_list_type; class ResolverBase; typedef boost::shared_ptr ResolverItem; /** * @brief: abstract base class for DnsResolver and IpPseudoResolver */ class ResolverBase { public: virtual ~ResolverBase(); /** * callbacks should be of type * void resolve_callback(const bool was_success, * const int recursion_count) */ void async_resolve(const callback_type &callback, const int recursion_count=0); virtual void cancel_resolve() = 0; virtual bool is_resolving() const = 0; virtual bool is_waiting_to_resolve() const = 0; virtual HostAddress get_next_ip(const bool check_up_to_date=true) = 0; virtual bool have_up_to_date_ip() = 0; virtual int get_resolved_ip_count(const bool check_up_to_date=true) = 0; std::string get_hostname() const; std::string get_skip_cname() const; protected: ResolverBase(const IoServiceItem &io_serv, const std::string &hostname, const DnsIpProtocol &protocol, const DnsCacheItem &cache ); // variables protected: IoServiceItem IoService; const std::string Hostname; const DnsIpProtocol Protocol; DnsCacheItem Cache; callback_list_type CallbackList; // functions for subclasses protected: // recursion_count is guaranteed to be below // DnsMaster::get_max_recursion_count virtual void do_resolve(const int recursion_count) = 0; // convenient forwards to DnsCache that just insert Hostname void update_cache( const HostAddressVec &new_ips ) const; void update_cache( const Cname &cname ) const; void update_cache( const std::string &hostname, const HostAddressVec &new_ips ) const; void update_cache( const std::string &hostname, const Cname &cname ) const; HostAddressVec get_cached_ips_recursively(const std::string host="", const bool check_up_to_date=false) const; void schedule_callbacks(const bool was_success, const int recursion_count); }; #endif