changed how dns deals with cnames and recursion: remember cnames and implement recurs...
[pingcheck] / src / dns / resolverbase.h
CommitLineData
36ad976b
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
23#ifndef RESOLVER_BASE_H
24#define RESOLVER_BASE_H
25
26#include <boost/shared_ptr.hpp>
4e7b6ff9 27#include <boost/function.hpp>
36ad976b 28
4e7b6ff9
CH
29#include <queue>
30#include "host/pinger.h"
96779587 31#include "dns/hostaddress.h"
c5b4902d 32#include "dns/dnscache.h"
96779587 33
4e7b6ff9
CH
34typedef boost::function<void(const bool, const int)> callback_type;
35typedef std::queue<callback_type> callback_list_type;
96779587 36
36ad976b
CH
37/**
38 * @brief: abstract base class for DnsResolver and IpPseudoResolver
39 */
40class ResolverBase
41{
42public:
4e7b6ff9
CH
43 virtual ~ResolverBase();
44
45 /**
46 * callbacks should be of type
47 * void resolve_callback(const bool was_success,
48 * const int cname_count)
49 */
50 void async_resolve(const callback_type &callback);
36ad976b 51
c5b4902d 52 virtual HostAddress get_next_ip() = 0;
923626c0
CH
53 virtual bool have_up_to_date_ip() = 0;
54 virtual int get_resolved_ip_count() = 0;
55
96779587 56protected:
4e7b6ff9
CH
57 ResolverBase(const IoServiceItem &io_serv,
58 const std::string &hostname,
59 const DnsCacheItem &cache );
96779587
CH
60
61// variables
4e7b6ff9
CH
62protected:
63 IoServiceItem IoService;
96779587
CH
64 std::string Hostname;
65 DnsCacheItem Cache;
4e7b6ff9 66 callback_list_type CallbackList;
96779587
CH
67
68// functions for subclasses
69protected:
4e7b6ff9
CH
70 virtual void do_resolve() = 0;
71
72 void update_cache( const HostAddressVec &new_results ) const;
ad83004d
CH
73 void update_cache( const std::string &cname ) const;
74 void update_cache_ttl( const uint32_t ttl ) const;
4e7b6ff9
CH
75
76 HostAddressVec& get_cached_results(const std::string host="") const;
77
78 void schedule_callbacks(const bool was_success,
79 const int cname_count);
80
96779587 81};
36ad976b 82
4e7b6ff9
CH
83typedef boost::shared_ptr<ResolverBase> ResolverItem;
84
36ad976b
CH
85#endif
86
87// (created using vim -- the world's best text editor)
88