* @param _login The login name.
* @param _password The corresponding password.
*/
-ServiceDyndns::ServiceDyndns(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)
+ServiceDyndns::ServiceDyndns(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, const string& _alternative_server)
+ : AlternativeServer(_alternative_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
*/
string ServiceDyndns::assemble_base_url(const string& fqhn) const
{
- string base_url;
+ string base_url = "https://";
+
+ // Test if a AlternativeServer name is given, needed for e.g. NO-IP
+ if ( AlternativeServer.empty() )
+ base_url.append("members.dyndns.org");
+ else
+ base_url.append(AlternativeServer);
- base_url = "https://members.dyndns.org";
base_url.append("/nic/update?hostname=");
base_url.append(fqhn);
base_url.append("&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG&myip=");
string url = BaseUrl;
url.append(ip);
- if ( HTTPHelp->is_initialized() )
+ if ( !HTTPHelp->is_initialized() )
+ {
+ get_logger()->print_httphelper_not_initialized();
+ HTTPHelp->re_initialize();
+ return -1;
+ }
+
+ // Perform curl operation on given url
+ long http_status_code = HTTPHelp->http_get(url);
+
+ get_logger()->print_http_status_code(url,http_status_code);
+
+ // HTTP operation completed successful.
+ // Now we have to parse the data received by curl,
+ // cause http status code is not significant for dyndns update errors
+ if ( http_status_code == 200 )
{
- // Perform curl operation on given url
- long http_status_code = HTTPHelp->http_get(url);
+ // Get the received http data.
+ string curl_data = HTTPHelp->get_curl_data();
- get_logger()->print_http_status_code(url,http_status_code);
+ // Note: We don't handle "nochg" as this shouldn't happen
+ // if only one client is active.
- // HTTP operation completed successful.
- // Now we have to parse the data received by curl,
- // cause http status code is not significant for dyndns update errors
- if ( http_status_code == 200 )
+ if ( curl_data == good )
+ {
+ return 0;
+ }
+ else if ( curl_data == "badauth" )
{
- // Get the received http data.
- string curl_data = HTTPHelp->get_curl_data();
-
- if ( curl_data == good )
- {
- return 0;
- }
- else if ( curl_data == "badauth" )
- {
- get_logger()->print_service_not_authorized(url,get_login(),get_password());
- }
- else
- {
- get_logger()->print_update_failure(url, curl_data);
- }
+ get_logger()->print_service_not_authorized(url,get_login(),get_password());
}
else
{
- get_logger()->print_update_failure(url,http_status_code);
+ get_logger()->print_update_failure(url, curl_data);
}
}
else
{
- get_logger()->print_httphelper_not_initialized();
+ get_logger()->print_update_failure(url,http_status_code);
}
+
return -1;
}