Fix 'occurred' typo
[bpdyndnsd] / src / service_tzo.cpp
index 27e062f..486bec7 100644 (file)
@@ -7,8 +7,8 @@
  * @license GPLv2
 */
 
-#include "service_tzo.h"
-#include "util.h"
+#include "service_tzo.hpp"
+#include "util.hpp"
 
 #include <time.h>
 #include <boost/foreach.hpp>
@@ -33,18 +33,23 @@ ServiceTzo::ServiceTzo()
  * @param _login The login name.
  * @param _password The corresponding password.
  */
-ServiceTzo::ServiceTzo(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)
+ServiceTzo::ServiceTzo(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 _max_equal_updates_in_succession, 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
+        set_update_interval(15);              // use default protocol value
     else
         set_update_interval(_update_interval);
 
     if ( _max_updates_within_interval == -1 )
-        set_max_updates_within_interval(0);
+        set_max_updates_within_interval(3);
     else
         set_max_updates_within_interval(_max_updates_within_interval);
 
+    if ( _max_equal_updates_in_succession == -1 )
+        set_max_equal_updates_in_succession(2);
+    else
+        set_max_equal_updates_in_succession(_max_equal_updates_in_succession);
+
     if ( _dns_cache_ttl == -1 )
         set_dns_cache_ttl(60);
     else
@@ -57,8 +62,7 @@ ServiceTzo::ServiceTzo(const string& _protocol, const string& _hostname, const s
     set_logger(_logger);
 
     // create http helper class
-    HTTPHelper::Ptr _http_help(new HTTPHelper(_logger,_proxy,_proxy_port));
-    HTTPHelp.swap(_http_help);
+    HTTPHelp = HTTPHelper::Ptr(new HTTPHelper(_logger,_proxy,_proxy_port));
 
     BaseUrl = assemble_base_url(get_hostname(),get_login(),get_password());
 }
@@ -101,12 +105,12 @@ string ServiceTzo::assemble_base_url(const string& fqhn, const string& username,
  * @param ip IP Address to set.
  * @return 0 if all is fine, -1 otherwise.
  */
-int ServiceTzo::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceTzo::perform_update(const std::string& ip)
 {
     string url = BaseUrl;
     url.append(ip);
 
-    if ( HTTPHelp->is_initialized() == true )
+    if ( HTTPHelp->is_initialized() )
     {
         long http_status_code = HTTPHelp->http_get(url);
 
@@ -123,15 +127,17 @@ int ServiceTzo::perform_update(const std::string& ip)
 
             if ( status_code == "200" )
             {
-                return 0;
+                return UpdateOk;
             }
             else if ( status_code == "401" )
             {
                 get_logger()->print_service_not_authorized(url,get_login(),get_password());
+                return NotAuth;
             }
             else
             {
                 get_logger()->print_update_failure(url,curl_data);
+                return UpdateError;
             }
         }
         else
@@ -141,7 +147,9 @@ int ServiceTzo::perform_update(const std::string& ip)
     }
     else
     {
-        get_logger()->print_service_not_initialized(url);
+        get_logger()->print_httphelper_not_initialized();
+        HTTPHelp->re_initialize();
     }
-    return -1;
+
+    return GenericError;
 }