From: Christian Herdtweck Date: Fri, 10 Apr 2015 10:35:50 +0000 (+0200) Subject: added dns cache file option X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=a901aed6b17d8cb1caed73a2c39764eea0911cd9;p=pingcheck added dns cache file option --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1645316..b7e366d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,6 +61,7 @@ set(SOURCES config/option/pingreplytimeoutoption.cpp config/option/maxaddressresolutionattemptsoption.cpp config/option/resolvedipttlthresholdoption.cpp + config/option/dnscachefileoption.cpp dns_neww/dnscache.cpp dns_neww/resolverbase.cpp dns_neww/dnsresolver.cpp diff --git a/src/config/configuration.cpp b/src/config/configuration.cpp index 0a17909..5843563 100644 --- a/src/config/configuration.cpp +++ b/src/config/configuration.cpp @@ -61,6 +61,7 @@ Configuration::Configuration() : PingReplyTimeout( 30 ), MaxAddressResolutionAttempts( 10 ), ResolvedIpTtlThreshold( 10 ), + DnsCacheFile(""), Hosts(), RatioRandomHosts( 1.0f ), PrintVersion( false ), @@ -234,6 +235,17 @@ void Configuration::set_resolved_ip_ttl_threshold( const int resolved_ip_ttl_thr ResolvedIpTtlThreshold = resolved_ip_ttl_threshold; } +void Configuration::set_dns_cache_file( const std::string &dns_cache_file) +{ + BOOST_ASSERT( !dns_cache_file.empty() ); + DnsCacheFile = dns_cache_file; +} + +std::string Configuration::get_dns_cache_file() const +{ + return DnsCacheFile; +} + float Configuration::get_ratio_random_hosts() const { return RatioRandomHosts; diff --git a/src/config/configuration.h b/src/config/configuration.h index bf8e396..45752ff 100644 --- a/src/config/configuration.h +++ b/src/config/configuration.h @@ -106,6 +106,9 @@ public: void set_print_version( const bool do_print ); bool get_print_version(); + std::string get_dns_cache_file() const; + void set_dns_cache_file(const std::string &dns_cache_file); + bool randomize_hosts(); private: @@ -132,6 +135,7 @@ private: HostList Hosts; float RatioRandomHosts; bool PrintVersion; + std::string DnsCacheFile; rand_gen_type RandomNumberGenerator; }; diff --git a/src/config/configurationoptions.cpp b/src/config/configurationoptions.cpp index 45981f1..5010921 100644 --- a/src/config/configurationoptions.cpp +++ b/src/config/configurationoptions.cpp @@ -48,6 +48,7 @@ #include "config/option/pingreplytimeoutoption.h" #include "config/option/maxaddressresolutionattemptsoption.h" #include "config/option/resolvedipttlthresholdoption.h" +#include "config/option/dnscachefileoption.h" using namespace std; using boost::program_options::option_description; @@ -119,6 +120,9 @@ ConfigurationOptions::ConfigurationOptions() : ConfigurationOptionItem ratio_random_hosts( new RatioRandomHostsOption ); ConfigOptions.push_back( ratio_random_hosts ); + ConfigurationOptionItem dns_cache_file( new DnsCacheFileOption ); + ConfigOptions.push_back( dns_cache_file ); + HostConfigurationOptionItem host_name( new HostNameOption ); HostOptions.push_back( host_name ); diff --git a/src/config/option/dnscachefileoption.cpp b/src/config/option/dnscachefileoption.cpp new file mode 100644 index 0000000..3dd97d3 --- /dev/null +++ b/src/config/option/dnscachefileoption.cpp @@ -0,0 +1,72 @@ +/* + 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. + */ + +#include "config/option/dnscachefileoption.h" + +#include + +#include + +using namespace std; +using boost::program_options::value; +using boost::program_options::variables_map; +using I2n::Logger::GlobalLogger; + +//----------------------------------------------------------------------------- +// DnsCacheFileOption +//----------------------------------------------------------------------------- + +/** + * @brief Default constructor. + */ +DnsCacheFileOption::DnsCacheFileOption() : + ConfigurationOption( + "dns-cache-file", + value()->default_value( "/etc/pingcheck_dns_cache.xml" ), + "Name of the DNS cache file." + ) +{ +} + +/** + * @brief Destructor. + */ +DnsCacheFileOption::~DnsCacheFileOption() +{ +} + +bool DnsCacheFileOption::parse( + const variables_map& vm, + Configuration *configuration +) +{ + // dns-cache-file + if ( 1 <= vm.count( get_command_string() ) ) + { + string dns_cache_file = vm[ get_command_string() ].as (); + configuration->set_dns_cache_file( dns_cache_file ); + + GlobalLogger.info() << get_command_string() << "=" << dns_cache_file + << endl; + return true; + } + + return false; +} diff --git a/src/config/option/dnscachefileoption.h b/src/config/option/dnscachefileoption.h new file mode 100644 index 0000000..5016129 --- /dev/null +++ b/src/config/option/dnscachefileoption.h @@ -0,0 +1,48 @@ +/* + 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. + */ + +#ifndef DNS_CACHE_FILE_OPTION_H +#define DNS_CACHE_FILE_OPTION_H + +#include + +#include "config/option/configurationoption.h" + +//----------------------------------------------------------------------------- +// DnsCacheFileOption +//----------------------------------------------------------------------------- + +/** + * @brief DNS Cache file name option. + */ +class DnsCacheFileOption : public ConfigurationOption +{ +public: + DnsCacheFileOption(); + virtual ~DnsCacheFileOption(); + + virtual bool parse( + const boost::program_options::variables_map &vm, + Configuration *configuration + ); + +}; + +#endif // DNS_CACHE_FILE_OPTION_H