Concetptionally each service needs it's own HTTPHelper class.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 1 Sep 2009 10:01:15 +0000 (12:01 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Tue, 1 Sep 2009 10:01:15 +0000 (12:01 +0200)
src/config.cpp
src/config.h
src/dhs.cpp
src/dhs.h
src/updater.cpp

index 4d334af..f46a562 100644 (file)
@@ -118,7 +118,7 @@ Config::~Config()
  * @param argv[] Pointer to command line argument array given to main.
  * @return 0 if all is fine, -1 if not.
  */
-int Config::parse_cmd_line(int argc, char *argv[], HTTPHelper::Ptr http_help)
+int Config::parse_cmd_line(int argc, char *argv[])
 {
     try
     {
@@ -159,7 +159,7 @@ int Config::parse_cmd_line(int argc, char *argv[], HTTPHelper::Ptr http_help)
             if ( VariablesMap.count("dns_cache_ttl") )
                 dns_cache_ttl = VariablesMap["dns_cache_ttl"].as<int>();
 
-            Service::Ptr service = create_service(protocol,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl,http_help);
+            Service::Ptr service = create_service(protocol,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl);
             if ( service )
             {
                 ServiceHolder->add_service(service);
@@ -248,11 +248,11 @@ int Config::parse_cmd_line(int argc, char *argv[], HTTPHelper::Ptr http_help)
  * @param password Password.
  * @return A pointer to the created Service object.
  */
-Service::Ptr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl, const HTTPHelper::Ptr http_help)
+Service::Ptr Config::create_service(const string &protocol,const string &hostname, const string &login, const string &password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl)
 {
     if(protocol == "dhs")
     {
-        Service::Ptr service_dhs(new DHS(protocol,hostname,login,password,Log,http_help,update_interval,max_updates_within_interval,dns_cache_ttl));
+        Service::Ptr service_dhs(new DHS(protocol,hostname,login,password,Log,update_interval,max_updates_within_interval,dns_cache_ttl,Proxy,ProxyPort));
         return service_dhs;
     }
     else if(protocol == "ods")
@@ -274,7 +274,7 @@ Service::Ptr Config::create_service(const string &protocol,const string &hostnam
  * @param full_filename Filename of the service config file to load.
  * @return 0 if all is fine, -1 otherwise.
  */
-int Config::load_service_config_file(const string& full_filename, const HTTPHelper::Ptr http_help)
+int Config::load_service_config_file(const string& full_filename)
 {
     Log->print_load_service_conf(full_filename);
 
@@ -310,7 +310,7 @@ int Config::load_service_config_file(const string& full_filename, const HTTPHelp
                 if ( vm.count("dns_cache_ttl") )
                     dns_cache_ttl = VariablesMap["dns_cache_ttl"].as<int>();
 
-                Service::Ptr service = create_service(protocol,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl,http_help);
+                Service::Ptr service = create_service(protocol,host,login,password,update_interval,max_updates_within_interval,dns_cache_ttl);
                 if ( service )
                 {
                     ServiceHolder->add_service(service);
@@ -436,7 +436,7 @@ int Config::load_main_config_file(const string& full_filename)
  * @param config_path The path to the config directory.
  * @return 0 if all is fine, -1 otherwise
  */
-int Config::load_config_from_files(const HTTPHelper::Ptr http_help)
+int Config::load_config_from_files()
 {
     fs::path full_config_path = fs::path(ConfigPath);
 
@@ -459,7 +459,7 @@ int Config::load_config_from_files(const HTTPHelper::Ptr http_help)
             else if ( boost::regex_search( actual_file,expr ) )
             {
                 string full_filename = dir_itr->path().string();
-                if ( load_service_config_file(full_filename,http_help) != 0 )
+                if ( load_service_config_file(full_filename) != 0 )
                     return -1;
             }
         }
index 12f6e27..daa169d 100644 (file)
@@ -46,9 +46,9 @@ private:
     std::string ExternalWarningLog;
     int ExternalWarningLevel;
 
-    Service::Ptr create_service(const std::string &protocol,const std::string &hostname, const std::string &login, const std::string &password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl, const HTTPHelper::Ptr http_help);
+    Service::Ptr create_service(const std::string &protocol,const std::string &hostname, const std::string &login, const std::string &password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl);
     int load_main_config_file(const std::string& full_filename);
-    int load_service_config_file(const std::string& full_filename, const HTTPHelper::Ptr http_help);
+    int load_service_config_file(const std::string& full_filename);
 
 public:
 
@@ -58,9 +58,9 @@ public:
 
     ~Config();
 
-    int parse_cmd_line(int argc, char *argv[], const HTTPHelper::Ptr http_help);
+    int parse_cmd_line(int argc, char *argv[]);
 
-    int load_config_from_files(const HTTPHelper::Ptr http_help);
+    int load_config_from_files();
 
     Options_descriptionPtr get_opt_desc_cmd() const;
 
index 9229a72..49bd832 100644 (file)
@@ -28,7 +28,7 @@ DHS::DHS()
  * @param _login The login name.
  * @param _password The corresponding password.
  */
-DHS::DHS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const HTTPHelper::Ptr& _http_help, const int _update_interval, const int _max_updates_within_interval, const int _dns_cache_ttl)
+DHS::DHS(const string& _protocol, const string& _hostname, const string& _login, const string& _password, const Logger::Ptr& _logger, const int _update_interval, const int _max_updates_within_interval, const int _dns_cache_ttl, const string& _proxy, const int _proxy_port)
 {
     if ( _update_interval == -1 )        // If _update_interval is default po::option_desc (not specified via config)
         set_update_interval(0);              // use default protocol value
@@ -51,7 +51,10 @@ DHS::DHS(const string& _protocol, const string& _hostname, const string& _login,
     set_password(_password);
     set_logger(_logger);
 
+    // create http helper class
+    HTTPHelper::Ptr _http_help(new HTTPHelper(_logger,_proxy,_proxy_port));
     HTTPHelp = _http_help;
+    _http_help.reset();
 }
 
 
index 0196ae9..54c85c2 100644 (file)
--- a/src/dhs.h
+++ b/src/dhs.h
@@ -36,7 +36,7 @@ public:
 
     DHS();
 
-    DHS(const std::string& _protocol, const std::string& _hostname, const std::string& _login, const std::string& _password, const Logger::Ptr& _logger, const HTTPHelper::Ptr& _http_help, const int _update_interval, const int _max_updates_within_interval, const int dns_cache_ttl);
+    DHS(const std::string& _protocol, const std::string& _hostname, const std::string& _login, const std::string& _password, const Logger::Ptr& _logger, const int _update_interval, const int _max_updates_within_interval, const int dns_cache_ttl, const std::string& proxy, const int proxy_port);
 
     ~DHS();
 
index bcb11ca..1c82dbe 100644 (file)
@@ -115,7 +115,7 @@ int Updater::reload_config()
 int Updater::init_config_from_cmd(int argc, char *argv[])
 {
     // Load the command line parameters
-    if( Conf->parse_cmd_line( argc, argv, HTTPHelp) != 0)
+    if( Conf->parse_cmd_line( argc, argv) != 0)
         return -1;
 
     // If we have loaded the cmd options we need to init the log facility immediately in case debugging is enabled from cmd.
@@ -134,7 +134,7 @@ int Updater::init_config_from_cmd(int argc, char *argv[])
 int Updater::init_config_from_files()
 {
     // Load the main and service config files in config path
-    if ( Conf->load_config_from_files(HTTPHelp) != 0 )
+    if ( Conf->load_config_from_files() != 0 )
         return -1;
 
     // Re-init log facility, perhaps new config file options for logger are set.
@@ -161,10 +161,6 @@ int Updater::init_helper_classes()
     if ( init_ip_helper() != 0 )
         return -1;
 
-    // Initialize HTTPHelper
-    if ( init_http_helper() != 0 )
-        return -1;
-
     return 0;
 }
 
@@ -185,21 +181,6 @@ int Updater::init_ip_helper()
 
 
 /**
- * Init the IPHelp member with needed values.
- * @return 0 if all is fine, -1 otherwise.
- */
-int Updater::init_http_helper()
-{
-    // initialize IPHelper
-    HTTPHelper::Ptr _httphelp(new HTTPHelper(Log,Conf->get_proxy(),Conf->get_proxy_port()));
-    HTTPHelp = _httphelp;
-    _httphelp.reset();
-
-    return 0;
-}
-
-
-/**
  * Getter for member Config.
  * @return Member Config.
  */