{
Log->print_update_service(service_name);
- if ( perform_update(ip) == 0 )
+ if ( perform_update(ip) == UpdateOk )
{
// if update was successful, we need to set the Lastupdated and ActualIP base member.
set_last_update(current_time,ip);
Logger::Ptr Log;
+protected:
+
+ enum UpdateErrorCode { UpdateOk=0, GenericError=1, NoChange=2, Blocked=3 };
+ virtual UpdateErrorCode perform_update(const std::string& ip) = 0;
+
public:
typedef boost::shared_ptr<Service> Ptr;
virtual ~Service();
- virtual int perform_update(const std::string& ip) = 0;
-
void update(const std::string& ip, const time_t current_time, bool changed_to_online);
bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host);
* @param ip IP Address to set.
* @return 0 if all is fine, -1 otherwise.
*/
-int ServiceDhs::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceDhs::perform_update(const std::string& ip)
{
string url = BaseUrl;
url.append(ip);
if ( boost::regex_search(curl_data,expr_done) )
{
// Update successful
- return 0;
+ return UpdateOk;
}
else
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+
+ return GenericError;
}
~ServiceDhs();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
#endif
* @param ip IP Address to set.
* @return 0 if all is fine, -1 otherwise.
*/
-int ServiceDyndns::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceDyndns::perform_update(const std::string& ip)
{
string url = BaseUrl;
url.append(ip);
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
- return -1;
+ return GenericError;
}
// Perform curl operation on given url
if ( curl_data.compare(0,4,"good") == 0 )
{
- return 0;
+ return UpdateOk;
}
else if (curl_data.compare(0,5,"nochg") == 0 )
{
// IP didn't change, this might indicate a problem at the
// dyndns backend or another client is running elsewhere.
- return 0;
+ get_logger()->print_update_failure(url, curl_data);
+ return UpdateOk;
}
else if (curl_data.compare(0,5,"abuse") == 0 )
{
// Account is blocked. Log it as a successful update
// so the IP address will be "burnt" until it changes.
- return 0;
+ get_logger()->print_update_failure(url, curl_data);
+ return UpdateOk;
}
else if ( curl_data == "badauth" )
{
get_logger()->print_update_failure(url,http_status_code);
}
- return -1;
+ return GenericError;
}
~ServiceDyndns();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
* @param ip IP Address to set.
* @return 0 if all is fine, -1 otherwise.
*/
-int ServiceDyns::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceDyns::perform_update(const std::string& ip)
{
string url = BaseUrl;
url.append(ip);
if ( status_code == "200" )
{
- return 0;
+ return UpdateOk;
}
else if ( status_code == "401" )
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+ return GenericError;
}
~ServiceDyns();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
#endif
* @param ip IP Address to set.
* @return 0 if all is fine, -1 otherwise.
*/
-int ServiceEasydns::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceEasydns::perform_update(const std::string& ip)
{
string url = BaseUrl;
url.append(ip);
if ( status_code == "NOERROR" )
{
- return 0;
+ return UpdateOk;
}
else if ( status_code == "NOACCESS" )
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+
+ return GenericError;
}
~ServiceEasydns();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
* @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() )
{
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
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
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 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_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+ return GenericError;
}
~ServiceGnudip();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
* @param ip IP Address to set.
* @return 0 if all is fine, -1 otherwise.
*/
-int ServiceOds::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceOds::perform_update(const std::string& ip)
{
// First of all create a boost shared pointer to the NetHelper.
NetHelper::Ptr connection(new NetHelper(get_logger()));
// Then open the connection to the ODS update server.
if (connection->open_connection(UpdateServer,Port) != 0)
- return -1;
+ return GenericError;
// Receive the server greeting.
string server_greeting = connection->receive_data();
if ( server_greeting.empty() )
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
// Send login command
if (connection->send_data(login.str()) != 0)
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
// Receive login reply
if ( login_reply.empty() )
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
else
{
// Login failed
get_logger()->print_service_not_authorized(UpdateServer,get_login(),get_password());
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
else if ( status_code != "225" )
{
// Undefined protocol error, Log login_reply
get_logger()->print_undefined_protocol_error("ODS",login_reply);
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
}
if (connection->send_data(delete_request.str()) != 0)
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
// Get delete reply
delete_reply = connection->receive_data();
if ( delete_reply.empty() )
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
del_count++;
reply_code = Util::parse_status_code(delete_reply);
if (connection->send_data(update_request.str()) != 0)
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
// Receive update request server reply
if ( update_reply.empty() )
{
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
else
{
{
get_logger()->print_undefined_protocol_error("ODS",update_reply);
connection->close_connection(); /*lint !e534 */
- return -1;
+ return GenericError;
}
}
// Successfully updated host
connection->close_connection(); /*lint !e534 */
- return 0;
+ return UpdateOk;
}
~ServiceOds();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
#endif
* @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 ( status_code == "200" )
{
- return 0;
+ return UpdateOk;
}
else if ( status_code == "401" )
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+
+ return GenericError;
}
~ServiceTzo();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
#endif
/**
* Performs the Service update.
* @param ip IP Address to set.
- * @return 0 if all is fine, -1 otherwise.
+ * @return UpdateOk if all is fine, GenericError otherwise.
*/
-int ServiceZoneedit::perform_update(const std::string& ip)
+Service::UpdateErrorCode ServiceZoneedit::perform_update(const std::string& ip)
{
string url = BaseUrl;
url.append(ip);
if ( status_code == "200" )
{
- return 0;
+ return UpdateOk;
}
else
{
get_logger()->print_httphelper_not_initialized();
HTTPHelp->re_initialize();
}
- return -1;
+ return GenericError;
}
~ServiceZoneedit();
- int perform_update(const std::string& ip);
+ UpdateErrorCode perform_update(const std::string& ip);
};
#endif