From ca28857e0f4c9e6955b842cfd2e9a8c784f9640f Mon Sep 17 00:00:00 2001 From: Gerd von Egidy Date: Mon, 25 May 2015 19:16:11 +0200 Subject: [PATCH] add new protocol variation "gnudip-fullhostname", used by provider dynu.com --- src/CMakeLists.txt | 2 + src/config.cpp | 15 +++++++ src/serializeservicecontainer.cpp | 1 + src/serializeservicecontainer.hpp | 1 + src/service_gnudip.cpp | 2 +- src/service_gnudip.hpp | 4 +- src/service_gnudip_fullhostname.cpp | 74 +++++++++++++++++++++++++++++++++++ src/service_gnudip_fullhostname.hpp | 41 +++++++++++++++++++ 8 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/service_gnudip_fullhostname.cpp create mode 100644 src/service_gnudip_fullhostname.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d2facfd..5bbe984 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(cpp_sources service_dyns.cpp service_easydns.cpp service_gnudip.cpp + service_gnudip_fullhostname.cpp serviceholder.cpp service_ods.cpp service_tzo.cpp @@ -54,6 +55,7 @@ set(cpp_headers service_dyns.hpp service_easydns.hpp service_gnudip.hpp + service_gnudip_fullhostname.hpp service.hpp serviceholder.hpp service_ods.hpp diff --git a/src/config.cpp b/src/config.cpp index 795b2ed..863a978 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,6 +17,7 @@ #include "service_tzo.hpp" #include "service_zoneedit.hpp" #include "service_gnudip.hpp" +#include "service_gnudip_fullhostname.hpp" #include #include @@ -398,6 +399,20 @@ Service::Ptr Config::create_service(const string &protocol, const string& server return service; } } + else if(protocol == "gnudip-fullhostname") + { + if ( !server.empty() ) + { + Service::Ptr service_gnudip_fullhostname(new ServiceGnudipFullhostname(protocol,server,hostname,login,password,Log,update_interval,max_updates_within_interval,max_equal_updates_in_succession,dns_cache_ttl,Proxy,ProxyPort)); + return service_gnudip_fullhostname; + } + else + { + Log->print_gnudip_requires_servername(); + Service::Ptr service; + return service; + } + } else { Log->print_unknown_protocol(protocol); diff --git a/src/serializeservicecontainer.cpp b/src/serializeservicecontainer.cpp index 6291c0a..faf6335 100644 --- a/src/serializeservicecontainer.cpp +++ b/src/serializeservicecontainer.cpp @@ -18,6 +18,7 @@ BOOST_CLASS_EXPORT_GUID(ServiceEasydns, "ServiceEasydns") BOOST_CLASS_EXPORT_GUID(ServiceTzo, "ServiceTzo") BOOST_CLASS_EXPORT_GUID(ServiceZoneedit, "ServiceZoneedit") BOOST_CLASS_EXPORT_GUID(ServiceGnudip, "ServiceGnudip") +BOOST_CLASS_EXPORT_GUID(ServiceGnudipFullhostname, "ServiceGnudipFullhostname") SerializeServiceContainer::SerializeServiceContainer() diff --git a/src/serializeservicecontainer.hpp b/src/serializeservicecontainer.hpp index 0e89d78..2fae390 100644 --- a/src/serializeservicecontainer.hpp +++ b/src/serializeservicecontainer.hpp @@ -30,6 +30,7 @@ #include "service_tzo.hpp" #include "service_zoneedit.hpp" #include "service_gnudip.hpp" +#include "service_gnudip_fullhostname.hpp" class SerializeServiceContainer diff --git a/src/service_gnudip.cpp b/src/service_gnudip.cpp index 934db17..3f35cfd 100644 --- a/src/service_gnudip.cpp +++ b/src/service_gnudip.cpp @@ -300,7 +300,7 @@ Service::UpdateErrorCode ServiceGnudip::perform_update(const std::string& ip) } // 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); diff --git a/src/service_gnudip.hpp b/src/service_gnudip.hpp index c2be8ed..6612f98 100644 --- a/src/service_gnudip.hpp +++ b/src/service_gnudip.hpp @@ -22,7 +22,7 @@ class ServiceGnudip : public Service { -private: +protected: friend class boost::serialization::access; template @@ -38,7 +38,7 @@ private: std::string assemble_base_url(const std::string& gnudip_server) const; std::map parse_initial_request(const std::string& curl_data) const; - std::string assemble_update_url(const std::string& salt, const std::string& curr_time, const std::string& sign, const std::string& secret, const std::string& ip) const; + virtual std::string assemble_update_url(const std::string& salt, const std::string& curr_time, const std::string& sign, const std::string& secret, const std::string& ip) const; std::string parse_return_code(const std::string& curl_data) const; public: diff --git a/src/service_gnudip_fullhostname.cpp b/src/service_gnudip_fullhostname.cpp new file mode 100644 index 0000000..7b01199 --- /dev/null +++ b/src/service_gnudip_fullhostname.cpp @@ -0,0 +1,74 @@ +/** @file + * @brief GNUDIP Service class implementation. This class represents the GNUDIP service. + * + * + * + * @copyright Intra2net AG + * @license GPLv2 +*/ + +#include "service_gnudip_fullhostname.hpp" +#include "util.hpp" + + +using namespace std; + + +/** + * Default Constructor, needed for object serialization. + */ +ServiceGnudipFullhostname::ServiceGnudipFullhostname() +{ +} + + +/** + * Constructor. + * @param _hostname The hostname to update + * @param _login The login name. + * @param _password The corresponding password. + */ +ServiceGnudipFullhostname::ServiceGnudipFullhostname(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) + : ServiceGnudip(_protocol, _gnudip_server, _hostname, _login, _password, _logger, _update_interval, _max_updates_within_interval, _max_equal_updates_in_succession, _dns_cache_ttl, _proxy, _proxy_port) +{ +} + + +/** + * Default destructor + */ +ServiceGnudipFullhostname::~ServiceGnudipFullhostname() +{ +} + +/** + * Get the assembled update url. + * @param salt Salt from the initial request + * @param time Time from the initial request + * @param sign Sign from the initial request + * @param secret Computed md5 secret in HEX + * @param ip IP to update + * @return The assembled update url. + */ +string ServiceGnudipFullhostname::assemble_update_url(const string& salt, const string& curr_time, const string& sign, const string& secret, const string& ip) const +{ + string url = BaseUrl; + + url.append("?salt="); + url.append(salt); + url.append("&time="); + url.append(curr_time); + url.append("&sign="); + url.append(sign); + url.append("&user="); + url.append(get_login()); + url.append("&domn="); + url.append(get_hostname()); + url.append("&pass="); + url.append(secret); + url.append("&reqc=0&addr="); + url.append(ip); + + return url; +} + diff --git a/src/service_gnudip_fullhostname.hpp b/src/service_gnudip_fullhostname.hpp new file mode 100644 index 0000000..d496ceb --- /dev/null +++ b/src/service_gnudip_fullhostname.hpp @@ -0,0 +1,41 @@ +/** @file + * @brief GNUDIP Service class header. This class represents the GNUDIP service. + * + * + * + * @copyright Intra2net AG + * @license GPLv2 +*/ + +#ifndef ServiceGnudipFullhostname_H +#define ServiceGnudipFullhostname_H + +#include "service_gnudip.hpp" + +class ServiceGnudipFullhostname : public ServiceGnudip +{ + +private: + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } + + std::string assemble_update_url(const std::string& salt, const std::string& curr_time, const std::string& sign, const std::string& secret, const std::string& ip) const; + +public: + + typedef boost::shared_ptr Ptr; + + ServiceGnudipFullhostname(); + + ServiceGnudipFullhostname(const std::string& _protocol, const std::string& _gnudip_server ,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 _max_equal_updates_in_succession, const int dns_cache_ttl, const std::string& proxy, const int proxy_port); + + ~ServiceGnudipFullhostname(); + +}; + +#endif -- 1.7.1