Commit | Line | Data |
---|---|---|
4e7b6ff9 CH |
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 | ||
c5b4902d CH |
23 | #include "dns/resolverbase.h" |
24 | #include "dns/dnsmaster.h" | |
4e7b6ff9 CH |
25 | |
26 | #include <boost/bind.hpp> | |
27 | ||
c5b4902d | 28 | |
4e7b6ff9 | 29 | ResolverBase::~ResolverBase() |
c5b4902d | 30 | { } |
4e7b6ff9 CH |
31 | |
32 | /** | |
33 | * callbacks should be of type | |
34 | * void resolve_callback(const bool was_success, | |
35 | * const int cname_count) | |
36 | */ | |
37 | void ResolverBase::async_resolve(const callback_type &callback) | |
38 | { | |
39 | // remember callback | |
40 | CallbackList.push(callback); | |
41 | ||
42 | // let subclass do the resolving | |
43 | do_resolve(); | |
44 | } | |
45 | ||
46 | ResolverBase::ResolverBase(const IoServiceItem &io_serv, | |
47 | const std::string &hostname, | |
48 | const DnsCacheItem &cache ) | |
49 | : IoService( io_serv ) | |
50 | , Hostname( hostname ) | |
51 | , Cache( cache ) | |
52 | , CallbackList() | |
53 | {} | |
54 | ||
dbe986b9 CH |
55 | std::string ResolverBase::get_hostname() const |
56 | { return Hostname; } | |
57 | ||
e18c1337 CH |
58 | void ResolverBase::update_cache( const std::string &hostname, |
59 | const HostAddressVec &new_results ) const | |
60 | { Cache->update( hostname, new_results ); } | |
61 | ||
62 | void ResolverBase::update_cache( const std::string &hostname, | |
dbe986b9 | 63 | const Cname &cname ) const |
e18c1337 CH |
64 | { Cache->update( hostname, cname ); } |
65 | ||
4e7b6ff9 CH |
66 | void ResolverBase::update_cache( const HostAddressVec &new_results ) const |
67 | { Cache->update( Hostname, new_results ); } | |
68 | ||
dbe986b9 | 69 | void ResolverBase::update_cache( const Cname &cname ) const |
ad83004d CH |
70 | { Cache->update( Hostname, cname ); } |
71 | ||
dbe986b9 CH |
72 | void ResolverBase::update_cache( const uint32_t ttl ) const |
73 | { Cache->update( Hostname, ttl ); } | |
ad83004d | 74 | |
dbe986b9 CH |
75 | HostAddressVec ResolverBase::get_cached_ips_recursively(const std::string host, |
76 | bool check_up_to_date) const | |
4e7b6ff9 CH |
77 | { |
78 | if (host.empty()) | |
dbe986b9 | 79 | return Cache->get_ips_recursive(Hostname, check_up_to_date); |
4e7b6ff9 | 80 | else |
dbe986b9 | 81 | return Cache->get_ips_recursive(host, check_up_to_date); |
4e7b6ff9 CH |
82 | } |
83 | ||
84 | void ResolverBase::schedule_callbacks(const bool was_success, | |
85 | const int cname_count) | |
86 | { | |
87 | while ( !CallbackList.empty() ) | |
88 | { | |
89 | callback_type callback = CallbackList.front(); | |
90 | CallbackList.pop(); | |
91 | IoService->post( boost::bind( callback, | |
92 | was_success, cname_count ) ); | |
93 | } | |
94 | } | |
95 | ||
96 | // (created using vim -- the world's best text editor) | |
97 |