Fix 'occurred' typo
[bpdyndnsd] / src / service_gnudip.cpp
index 4f757e2..3f35cfd 100644 (file)
@@ -31,19 +31,24 @@ ServiceGnudip::ServiceGnudip()
  * @param _login The login name.
  * @param _password The corresponding password.
  */
-ServiceGnudip::ServiceGnudip(const string& _protocol, const string& _gnudip_server, 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)
+ServiceGnudip::ServiceGnudip(const string& _protocol, const string& _gnudip_server, 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)
     : GnudipServer(_gnudip_server)
 {
     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
@@ -216,7 +221,7 @@ string ServiceGnudip::assemble_update_url(const string& salt, const string& curr
  * @param ip IP Address to set.
  * @return 0 if all is fine, -1 otherwise.
  */
-int ServiceGnudip::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceGnudip::perform_update(const std::string& ip)
 {
     if ( HTTPHelp->is_initialized() )
     {
@@ -236,7 +241,7 @@ int ServiceGnudip::perform_update(const std::string& ip)
             if ( salt_time_sign.empty() )
             {
                 get_logger()->print_could_not_parse_received_data(curl_data);
-                return -1;
+                return GenericError;
             }
 
             // at this point we have salt, time and sign parsed successfully
@@ -266,12 +271,12 @@ int ServiceGnudip::perform_update(const std::string& ip)
             catch ( exception& e )
             {
                 get_logger()->print_exception_md5_sum(e.what());
-                return -1;
+                return GenericError;
             }
             catch ( ... )
             {
                 get_logger()->print_exception_md5_sum("Unknown exception");
-                return -1;
+                return GenericError;
             }
 
             // append "." and salt and compute md5 sum and get the HEX representation
@@ -286,16 +291,16 @@ int ServiceGnudip::perform_update(const std::string& ip)
             catch ( exception& e )
             {
                 get_logger()->print_exception_md5_sum(e.what());
-                return -1;
+                return GenericError;
             }
             catch ( ... )
             {
                 get_logger()->print_exception_md5_sum("Unknown exception");
-                return -1;
+                return GenericError;
             }
 
             // Now its time to issue the second http_get operation
-            string url = assemble_update_url(salt, sign_time, sign, secret, ip);
+            string url = this->assemble_update_url(salt, sign_time, sign, secret, ip);
 
             // perform the update operation
             http_status_code = HTTPHelp->http_get(url);
@@ -309,15 +314,17 @@ int ServiceGnudip::perform_update(const std::string& ip)
                 string update_return_code = parse_return_code(curl_data);
                 if ( update_return_code == "0" )
                 {
-                    return 0;
+                    return UpdateOk;
                 }
                 else if ( update_return_code == "1" )
                 {
                     get_logger()->print_service_not_authorized(url,get_login(),get_password());
+                    return NotAuth;
                 }
                 else
                 {
                     get_logger()->print_update_failure(url,update_return_code);
+                    return UpdateError;
                 }
             }
             else
@@ -337,5 +344,5 @@ int ServiceGnudip::perform_update(const std::string& ip)
         get_logger()->print_httphelper_not_initialized();
         HTTPHelp->re_initialize();
     }
-    return -1;
+    return GenericError;
 }