added dns cache file option
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 10 Apr 2015 10:35:50 +0000 (12:35 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 4 May 2015 14:57:57 +0000 (16:57 +0200)
src/CMakeLists.txt
src/config/configuration.cpp
src/config/configuration.h
src/config/configurationoptions.cpp
src/config/option/dnscachefileoption.cpp [new file with mode: 0644]
src/config/option/dnscachefileoption.h [new file with mode: 0644]

index 1645316..b7e366d 100644 (file)
@@ -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
index 0a17909..5843563 100644 (file)
@@ -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;
index bf8e396..45752ff 100644 (file)
@@ -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;
 };
 
index 45981f1..5010921 100644 (file)
@@ -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 (file)
index 0000000..3dd97d3
--- /dev/null
@@ -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 <iostream>
+
+#include <logfunc.hpp>
+
+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<string>()->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<string> ();
+        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 (file)
index 0000000..5016129
--- /dev/null
@@ -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 <boost/program_options.hpp>
+
+#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