/** @file * @brief The abstract service class. This class represents all services. * * * * @copyright Intra2net AG * @license GPLv2 */ #ifndef SERVICE_H #define SERVICE_H #include "logger.hpp" #include #include #include #include #include #include #include class Service { private: std::string Protocol; std::string Hostname; std::string Login; std::string Password; std::string ActualIP; bool ActualIPIsBurnt; bool Activated; int UpdateInterval; int MaxUpdatesWithinInterval; int MaxEqualUpdatesInSuccession; int DNSCacheTTL; std::map LastUpdates; int ErrorCount; time_t ErrorServiceBlockedUntil; friend class boost::serialization::access; template void save(Archive & ar, const unsigned int version) const { // 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 & MaxEqualUpdatesInSuccession; ar & DNSCacheTTL; // Activated was introduced with version 1. ar & Activated; } template void load(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 & MaxEqualUpdatesInSuccession; ar & DNSCacheTTL; // Activated was introduced with version 1. if ( version >= 1 ) ar & Activated; } BOOST_SERIALIZATION_SPLIT_MEMBER() Logger::Ptr Log; protected: enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 }; virtual UpdateErrorCode perform_update(const std::string& ip) = 0; // UpdateOk: Update was successful // UpdateError: Unspecified error code returned from update server // NoChange: IP was not changed_to_online // Blocked: Client blocked due to abusive updates // NotAuth: Authentication was not successful // GenericError: Generic error. For example update server not reached, wrong hostname, not authenticated or network error. // Generic error indicates that the update server couldn't associate the update request to any hostname. public: typedef boost::shared_ptr Ptr; Service(); virtual ~Service(); 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); void set_last_update(const time_t current_time, const std::string& ip); time_t get_last_update_time(); int get_update_interval()const; void set_update_interval(const int _update_interval); int get_max_updates_within_interval() const; void set_max_updates_within_interval(const int _max_updates_within_interval); int get_max_equal_updates_in_succession() const; void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession); int get_dns_cache_ttl() const; void set_dns_cache_ttl(const int _dns_cache_ttl); void set_protocol(const std::string& _protocol); std::string get_protocol() const; void set_hostname(const std::string& _hostname); std::string get_hostname() const; void set_login(const std::string& _login); std::string get_login() const; void set_password(const std::string& _password); std::string get_password() const; void set_last_updates(std::map _last_updates); const std::map get_last_updates() const; void set_actual_ip(const std::string& _actual_ip); std::string get_actual_ip() const; void set_logger(const Logger::Ptr& _log); Logger::Ptr get_logger() const; std::string get_service_name() const; void set_activated(); bool get_activated() const; bool operator== (const Service& other) const; bool operator!= (const Service& other) const; }; BOOST_CLASS_VERSION(Service,1) #endif