From ca5d6889aa371a904f395aa2b511a8c868960c7c Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Fri, 18 Sep 2009 17:51:01 +0200 Subject: [PATCH] Fixed includes. Fixed BOOST::SERIALIZATION linking error after fixed includes. --- src/config.cpp | 1 - src/httphelper.cpp | 1 + src/logger.cpp | 5 +++++ src/main.cpp | 27 +++------------------------ src/serializeservicecontainer.cpp | 4 ++-- src/serializeservicecontainer.h | 33 +++++++++++++++++++++++++++++---- src/service.cpp | 7 +++++-- src/service.h | 19 ++++++++++++++++--- src/service_dhs.cpp | 12 ------------ src/service_dhs.h | 12 +++++++----- src/service_dyndns.cpp | 12 ------------ src/service_dyndns.h | 12 +++++++----- src/service_dyns.cpp | 12 ------------ src/service_dyns.h | 12 +++++++----- src/service_easydns.cpp | 12 ------------ src/service_easydns.h | 12 +++++++----- src/service_gnudip.cpp | 12 ------------ src/service_gnudip.h | 12 +++++++----- src/service_ods.cpp | 13 +------------ src/service_ods.h | 9 +++++---- src/service_tzo.cpp | 12 ------------ src/service_tzo.h | 12 +++++++----- src/service_zoneedit.cpp | 12 ------------ src/service_zoneedit.h | 12 +++++++----- src/serviceholder.cpp | 12 ++++++------ src/serviceholder.h | 5 +++-- src/tcp_service.h | 1 + src/updater.cpp | 24 +++--------------------- src/util.cpp | 26 ++++++++++++++------------ src/util.h | 8 ++++++-- 30 files changed, 149 insertions(+), 214 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index cb9cbf8..8ca4025 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -28,7 +28,6 @@ #include - namespace po = boost::program_options; namespace fs = boost::filesystem; namespace ba = boost::algorithm; diff --git a/src/httphelper.cpp b/src/httphelper.cpp index 890388d..a490520 100644 --- a/src/httphelper.cpp +++ b/src/httphelper.cpp @@ -9,6 +9,7 @@ #include "httphelper.h" +using namespace std; /** * Constructor. Use this constructor if HTTP AUTH should be used. Username and password will then be set as HTTP auth options. diff --git a/src/logger.cpp b/src/logger.cpp index a1fd53c..bf8a58a 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -10,11 +10,16 @@ #include "logger.h" +#include #include #include #include +#define VERSION 0 +#define REVISION 1 +#define RELEASE 0 + namespace po = boost::program_options; typedef boost::shared_ptr Options_descriptionPtr; diff --git a/src/main.cpp b/src/main.cpp index a2a221f..48513ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,6 @@ #define RELEASE 0 #define PIDFILE "/home/bjoern/intranator/bpdyndnsd/var/run/bpdyndnsd.pid" -#define OBJECT_FILE "/home/bjoern/intranator/bpdyndnsd/objects.ser" #include #include @@ -28,28 +27,6 @@ #include "updater.h" -#include "config.cpp" -#include "logger.cpp" -#include "serviceholder.cpp" -#include "updater.cpp" -#include "ip_addr_helper.cpp" -#include "net_helper.cpp" -#include "tcp_service.cpp" -#include "httphelper.cpp" -#include "serializeservicecontainer.cpp" -#include "util.cpp" - -#include "service.cpp" -#include "service_dyndns.cpp" -#include "service_dyns.cpp" -#include "service_ods.cpp" -#include "service_dhs.cpp" -#include "service_easydns.cpp" -#include "service_tzo.cpp" -#include "service_zoneedit.cpp" -#include "service_gnudip.cpp" - - using namespace std; Updater::Ptr updater; @@ -281,7 +258,9 @@ int init_daemon_mode(bool daemon_mode) int main(int argc, char *argv[]) { // initialize Updater - Updater::Ptr updater(new Updater); + Updater::Ptr _updater(new Updater); + updater.swap(_updater); + _updater.reset(); // load config and initialize helper classes if ( updater->load_config(argc,argv) != 0 ) diff --git a/src/serializeservicecontainer.cpp b/src/serializeservicecontainer.cpp index 8366a3b..b3857fc 100644 --- a/src/serializeservicecontainer.cpp +++ b/src/serializeservicecontainer.cpp @@ -9,7 +9,6 @@ #include "serializeservicecontainer.h" -#include SerializeServiceContainer::SerializeServiceContainer() { @@ -26,12 +25,13 @@ SerializeServiceContainer::~SerializeServiceContainer() * @param ar Archive * @param version Version */ +/* template void SerializeServiceContainer::serialize(Archive & ar, const unsigned int version) { ar & ContainingServices; } - +*/ void SerializeServiceContainer::add_service(Service::Ptr service) { diff --git a/src/serializeservicecontainer.h b/src/serializeservicecontainer.h index ab450d9..b890865 100644 --- a/src/serializeservicecontainer.h +++ b/src/serializeservicecontainer.h @@ -10,13 +10,35 @@ #ifndef SERIALIZESERVICECONTAINER_H #define SERIALIZESERVICECONTAINER_H -#include - #include "service.h" #include "logger.h" -#include +#include +#include +#include + #include +#include + +#include "service_dhs.h" +#include "service_ods.h" +#include "service_dyndns.h" +#include "service_dyns.h" +#include "service_easydns.h" +#include "service_tzo.h" +#include "service_zoneedit.h" +#include "service_gnudip.h" + +// Following boost macros are needed for serialization of derived classes through a base class pointer (Service *). +BOOST_CLASS_EXPORT_GUID(ServiceOds, "ServiceOds") +BOOST_CLASS_EXPORT_GUID(ServiceDhs, "ServiceDhs") +BOOST_CLASS_EXPORT_GUID(ServiceDyns, "ServiceDyns") +BOOST_CLASS_EXPORT_GUID(ServiceDyndns, "ServiceDyndns") +BOOST_CLASS_EXPORT_GUID(ServiceEasydns, "ServiceEasydns") +BOOST_CLASS_EXPORT_GUID(ServiceTzo, "ServiceTzo") +BOOST_CLASS_EXPORT_GUID(ServiceZoneedit, "ServiceZoneedit") +BOOST_CLASS_EXPORT_GUID(ServiceGnudip, "ServiceGnudip") + class SerializeServiceContainer { @@ -27,7 +49,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & ContainingServices; + } public: diff --git a/src/service.cpp b/src/service.cpp index a9869e0..7dc10e8 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -9,7 +9,9 @@ #include "service.h" #include -#include + +using namespace std; + /** * Default Constructor @@ -39,6 +41,7 @@ Service::~Service() * @param ar Archive. * @param version Version. */ +/* template void Service::serialize(Archive & ar, const unsigned int version) { @@ -52,7 +55,7 @@ void Service::serialize(Archive & ar, const unsigned int version) ar & MaxUpdatesWithinInterval; ar & DNSCacheTTL; } - +*/ /** * Setter for member Protocol. diff --git a/src/service.h b/src/service.h index ca204d6..572a600 100644 --- a/src/service.h +++ b/src/service.h @@ -12,10 +12,12 @@ #include "logger.h" -#include +#include +#include -#include #include +#include +#include class Service @@ -39,7 +41,18 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + // protocol and hostname are the unique identifier for each service. + ar & Protocol; + ar & Hostname; + // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. + ar & LastUpdates; + ar & ActualIP; + ar & UpdateInterval; + ar & MaxUpdatesWithinInterval; + ar & DNSCacheTTL; + } Logger::Ptr Log; diff --git a/src/service_dhs.cpp b/src/service_dhs.cpp index e98d864..df107a7 100644 --- a/src/service_dhs.cpp +++ b/src/service_dhs.cpp @@ -173,15 +173,3 @@ int ServiceDhs::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceDhs::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_dhs.h b/src/service_dhs.h index cb7f46a..283c8af 100644 --- a/src/service_dhs.h +++ b/src/service_dhs.h @@ -10,15 +10,15 @@ #ifndef ServiceDhs_H #define ServiceDhs_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include +#include #include + class ServiceDhs : public Service { @@ -26,14 +26,16 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; HTTPHelper::Ptr HTTPHelp; std::list separate_domain_and_host_part(const std::string& str) const; - std::string assemble_base_url(const std::string& hostname, const std::string& domain_part) const; public: diff --git a/src/service_dyndns.cpp b/src/service_dyndns.cpp index dd6fee0..a867211 100644 --- a/src/service_dyndns.cpp +++ b/src/service_dyndns.cpp @@ -133,15 +133,3 @@ int ServiceDyndns::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceDyndns::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_dyndns.h b/src/service_dyndns.h index 8373b71..1e18db7 100644 --- a/src/service_dyndns.h +++ b/src/service_dyndns.h @@ -10,14 +10,13 @@ #ifndef ServiceDyndns_H #define ServiceDyndns_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include +#include + class ServiceDyndns : public Service { @@ -26,7 +25,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; diff --git a/src/service_dyns.cpp b/src/service_dyns.cpp index d8e9eb8..b3a68cd 100644 --- a/src/service_dyns.cpp +++ b/src/service_dyns.cpp @@ -139,15 +139,3 @@ int ServiceDyns::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceDyns::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_dyns.h b/src/service_dyns.h index 2fc868a..14caf3d 100644 --- a/src/service_dyns.h +++ b/src/service_dyns.h @@ -10,14 +10,13 @@ #ifndef ServiceDyns_H #define ServiceDyns_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include +#include + class ServiceDyns : public Service { @@ -26,7 +25,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; diff --git a/src/service_easydns.cpp b/src/service_easydns.cpp index 75ce7ac..70d33c2 100644 --- a/src/service_easydns.cpp +++ b/src/service_easydns.cpp @@ -215,15 +215,3 @@ int ServiceEasydns::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceEasydns::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_easydns.h b/src/service_easydns.h index 777a942..b018665 100644 --- a/src/service_easydns.h +++ b/src/service_easydns.h @@ -10,14 +10,13 @@ #ifndef ServiceEasydns_H #define ServiceEasydns_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include +#include + class ServiceEasydns : public Service { @@ -26,7 +25,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; diff --git a/src/service_gnudip.cpp b/src/service_gnudip.cpp index 6c2a517..aaba8e5 100644 --- a/src/service_gnudip.cpp +++ b/src/service_gnudip.cpp @@ -291,15 +291,3 @@ int ServiceGnudip::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceGnudip::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_gnudip.h b/src/service_gnudip.h index 8e6306f..b58e6ff 100644 --- a/src/service_gnudip.h +++ b/src/service_gnudip.h @@ -10,15 +10,14 @@ #ifndef ServiceGnudip_H #define ServiceGnudip_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include #include +#include + class ServiceGnudip : public Service { @@ -27,7 +26,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string GnudipServer; std::string BaseUrl; diff --git a/src/service_ods.cpp b/src/service_ods.cpp index a586c0b..26d862d 100644 --- a/src/service_ods.cpp +++ b/src/service_ods.cpp @@ -9,6 +9,7 @@ #include "service_ods.h" #include "net_helper.h" +#include "util.h" #include @@ -160,15 +161,3 @@ int ServiceOds::perform_update(const std::string& ip) connection->close_connection(); return 0; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceOds::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_ods.h b/src/service_ods.h index b832daf..5e9ffff 100644 --- a/src/service_ods.h +++ b/src/service_ods.h @@ -10,13 +10,11 @@ #ifndef ServiceOds_H #define ServiceOds_H -#include - #include "service.h" #include "logger.h" -#include #include +#include class ServiceOds : public Service @@ -26,7 +24,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string UpdateServer; std::string Port; diff --git a/src/service_tzo.cpp b/src/service_tzo.cpp index 71a76c3..895e816 100644 --- a/src/service_tzo.cpp +++ b/src/service_tzo.cpp @@ -139,15 +139,3 @@ int ServiceTzo::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceTzo::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_tzo.h b/src/service_tzo.h index 7e58f9d..0e8da5a 100644 --- a/src/service_tzo.h +++ b/src/service_tzo.h @@ -10,14 +10,13 @@ #ifndef ServiceTzo_H #define ServiceTzo_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include +#include + class ServiceTzo : public Service { @@ -26,7 +25,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; diff --git a/src/service_zoneedit.cpp b/src/service_zoneedit.cpp index 9365529..75ef63a 100644 --- a/src/service_zoneedit.cpp +++ b/src/service_zoneedit.cpp @@ -133,15 +133,3 @@ int ServiceZoneedit::perform_update(const std::string& ip) return -1; } - - -/** - * Serialize function needed by boost/serialization to define which members should be stored as the object state. - * @param ar Archive - * @param version Version - */ -template -void ServiceZoneedit::serialize(Archive & ar, const unsigned int version) -{ - ar & boost::serialization::base_object(*this); -} diff --git a/src/service_zoneedit.h b/src/service_zoneedit.h index 7e5dc5b..bd58161 100644 --- a/src/service_zoneedit.h +++ b/src/service_zoneedit.h @@ -10,14 +10,13 @@ #ifndef ServiceZoneedit_H #define ServiceZoneedit_H -#include - #include "service.h" #include "logger.h" +#include "httphelper.h" -#include #include -#include +#include + class ServiceZoneedit : public Service { @@ -26,7 +25,10 @@ private: friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version); + void serialize(Archive & ar, const unsigned int version) + { + ar & boost::serialization::base_object(*this); + } std::string BaseUrl; diff --git a/src/serviceholder.cpp b/src/serviceholder.cpp index e07f84e..7dfbd3f 100644 --- a/src/serviceholder.cpp +++ b/src/serviceholder.cpp @@ -9,17 +9,17 @@ #include "serviceholder.h" -#include "serializeservicecontainer.h" +#include +#include #include -#include -#include -#include -#include -#include + +#define OBJECT_FILE "/home/bjoern/intranator/bpdyndnsd/objects.ser" using namespace std; +namespace fs = boost::filesystem; + /** * Default constructor with Logger object. diff --git a/src/serviceholder.h b/src/serviceholder.h index a103cf2..2653783 100644 --- a/src/serviceholder.h +++ b/src/serviceholder.h @@ -10,12 +10,13 @@ #ifndef SERVICEHOLDER_H #define SERVICEHOLDER_H -#include - #include "service.h" +#include "serializeservicecontainer.h" #include "logger.h" #include +#include + class Serviceholder { diff --git a/src/tcp_service.h b/src/tcp_service.h index ef5bdd6..74cdb3f 100644 --- a/src/tcp_service.h +++ b/src/tcp_service.h @@ -11,6 +11,7 @@ #define TCPSERVICE_H #include "logger.h" +#include "ip_service.h" #include #include diff --git a/src/updater.cpp b/src/updater.cpp index 4a62541..9d055f2 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -10,33 +10,15 @@ #include "updater.h" #include "serviceholder.h" -#include "service_dhs.h" -#include "service_ods.h" -#include "service_dyndns.h" -#include "service_dyns.h" -#include "service_easydns.h" -#include "service_tzo.h" -#include "service_zoneedit.h" -#include "service_gnudip.h" -#include - - -// Following boost macros are needed for serialization of derived classes through a base class pointer (Service *). -BOOST_CLASS_EXPORT_GUID(ServiceOds, "ServiceOds") -BOOST_CLASS_EXPORT_GUID(ServiceDhs, "ServiceDhs") -BOOST_CLASS_EXPORT_GUID(ServiceDyns, "ServiceDyns") -BOOST_CLASS_EXPORT_GUID(ServiceDyndns, "ServiceDyndns") -BOOST_CLASS_EXPORT_GUID(ServiceEasydns, "ServiceEasydns") -BOOST_CLASS_EXPORT_GUID(ServiceTzo, "ServiceTzo") -BOOST_CLASS_EXPORT_GUID(ServiceZoneedit, "ServiceZoneedit") -BOOST_CLASS_EXPORT_GUID(ServiceGnudip, "ServiceGnudip") +#include +#include -namespace fs = boost::filesystem; using namespace std; + /** * Default constructor which initializes the member Conf. */ diff --git a/src/util.cpp b/src/util.cpp index 18ad24c..96cd7e7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,5 @@ /** @file - * @brief Util namespace implementation. + * @brief Util namespace header. * * * @@ -11,15 +11,16 @@ #include #include +#include -using namespace std; - +namespace Util +{ /** * Computes a MD5 Digest from the given string and returns the HEX representation * @param data The string to compute the md5 for * @return The computed md5 in hex */ -string Util::compute_md5_digest(string data) throw (invalid_argument) +std::string compute_md5_digest(std::string data) throw (std::invalid_argument) { // compute an MD5 digest. @@ -36,7 +37,7 @@ string Util::compute_md5_digest(string data) throw (invalid_argument) // Test if md is initialized. if ( (md == NULL) || (EVP_MD_size(md) == 0) ) - throw invalid_argument("NULL pointer: md"); + throw std::invalid_argument("NULL pointer: md"); // Initalize digest content mdctx. EVP_MD_CTX_init(&mdctx); @@ -46,7 +47,7 @@ string Util::compute_md5_digest(string data) throw (invalid_argument) // Test if data is empty. if ( data.empty() ) - throw invalid_argument("Passed data is empty"); + throw std::invalid_argument("Passed data is empty"); // Hash the data. At this point data is not empty and &mdctx is initialized. EVP_DigestUpdate(&mdctx, data.c_str(), data.size()); @@ -56,19 +57,19 @@ string Util::compute_md5_digest(string data) throw (invalid_argument) // Test if md_value is filled correctly and md_len is not zero. if ( (md_len == 0) || (md_value == NULL) || (EVP_MD_CTX_size(&mdctx) == 0) ) - throw invalid_argument("Retrieved invalid digest value"); + throw std::invalid_argument("Retrieved invalid digest value"); // Internal cleanup of the digest content. EVP_MD_CTX_cleanup(&mdctx); EVP_cleanup(); // Convert md5 digest C string to hex. - ostringstream oss_digest_md5_hex; + std::ostringstream oss_digest_md5_hex; for(unsigned int i = 0; i < md_len; ++i) { // We have to do a static cast to an decimal representation, cause otherwise ostringstream would interpret // the stream as a character and output the character representation of the hex value. - oss_digest_md5_hex << hex << static_cast(md_value[i]); + oss_digest_md5_hex << std::hex << static_cast(md_value[i]); } return oss_digest_md5_hex.str(); @@ -80,9 +81,10 @@ string Util::compute_md5_digest(string data) throw (invalid_argument) * @param data The data containing the status code at front, limited by " ". * @return The parsed status code. */ -string Util::parse_status_code(string data) +std::string parse_status_code(std::string data) { - list tokens; - ba::split(tokens,data,boost::is_any_of(" ")); + std::list tokens; + boost::algorithm::split(tokens,data,boost::is_any_of(" ")); return tokens.front(); } +}; diff --git a/src/util.h b/src/util.h index cf8299b..1d470d0 100644 --- a/src/util.h +++ b/src/util.h @@ -10,11 +10,15 @@ #ifndef UTIL_H #define UTIL_H +#include +#include +#include + namespace Util { - static std::string compute_md5_digest(std::string data) throw (std::invalid_argument); - static std::string parse_status_code(std::string data); + std::string compute_md5_digest(std::string data) throw (std::invalid_argument); + std::string parse_status_code(std::string data); }; #endif -- 1.7.1