remove the footer saying that vim is the best editor -- anyone knows anyway
[pingcheck] / src / dns / ippseudoresolver.h
1 /*
2  The software in this package is distributed under the GNU General
3  Public License version 2 (with a special exception described below).
4
5  A copy of GNU General Public License (GPL) is included in this distribution,
6  in the file COPYING.GPL.
7
8  As a special exception, if other files instantiate templates or use macros
9  or inline functions from this file, or you compile this file and link it
10  with other works to produce a work based on this file, this file
11  does not by itself cause the resulting work to be covered
12  by the GNU General Public License.
13
14  However the source code for this file must still be made available
15  in accordance with section (3) of the GNU General Public License.
16
17  This exception does not invalidate any other reasons why a work based
18  on this file might be covered by the GNU General Public License.
19
20  Christian Herdtweck, Intra2net AG 2015
21  */
22
23 #ifndef IP_PSEUDO_RESOLVER_H
24 #define IP_PSEUDO_RESOLVER_H
25
26 #include <boost/asio/ip/address.hpp>
27 #include "dns/hostaddress.h"
28 #include "dns/resolverbase.h"
29 #include "dns/dnsmaster.h"
30
31 namespace Config
32 {
33     uint32_t DefaultTtl = 60*60*24*356;  // 1 year in seconds (approx)
34 }
35
36 /** @brief Degenerate case of a resolver: hostname is already an IP
37  * 
38  * created by DnsMaster if given an IP address as hostname
39  *
40  * Will do nothing, just remember that IP and return it for every call to
41  * get_next_ip
42  *
43  * Since this is so boring, I did not create an own .cpp for it
44  */
45 class IpPseudoResolver : public ResolverBase
46 {
47 // constructor accessible from friend DnsMaster
48 public:
49     friend ResolverItem& DnsMaster::get_resolver_for(
50                                                  const std::string &hostname,
51                                                  const DnsIpProtocol &protocol);
52 private:
53     IpPseudoResolver(const IoServiceItem io_serv,
54                      const std::string &ip_string,
55                      const DnsCacheItem &cache )
56         : ResolverBase( io_serv, ip_string, cache )
57         , IpAddress( boost::asio::ip::address::from_string(ip_string),
58                      Config::DefaultTtl )
59     {}
60
61 private:
62     HostAddress IpAddress;
63
64 // only real public function
65 public:
66     HostAddress get_next_ip(const bool check_up_to_date=true)
67                                        { return IpAddress; }
68     bool have_up_to_date_ip()          { return true;      }
69     int get_resolved_ip_count(const bool check_up_to_date=true)
70                                        { return 1;         }
71     bool is_resolving() const          { return false;     }
72     bool is_waiting_to_resolve() const { return false;     }
73     void cancel_resolve() {}
74
75 // implementation of ResolverBase::async_resolve
76 protected:
77     void do_resolve(const int recursion_count)
78     {   ResolverBase::schedule_callbacks(true, 0);  }
79 };
80 #endif
81