2 * @brief The abstract service class. This class represents all services.
6 * @copyright Intra2net AG
15 #include <boost/archive/text_oarchive.hpp>
16 #include <boost/archive/text_iarchive.hpp>
17 #include <boost/serialization/version.hpp>
18 #include <boost/serialization/split_member.hpp>
20 #include <boost/shared_ptr.hpp>
41 int MaxUpdatesWithinInterval;
42 int MaxEqualUpdatesInSuccession;
45 std::map<time_t,std::string> LastUpdates;
48 time_t ErrorServiceBlockedUntil;
50 friend class boost::serialization::access;
51 template<class Archive>
52 void save(Archive & ar, const unsigned int version) const
54 // protocol and hostname are the unique identifier for each service.
57 // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
61 ar & MaxUpdatesWithinInterval;
62 ar & MaxEqualUpdatesInSuccession;
65 // Activated was introduced with version 1.
68 template<class Archive>
69 void load(Archive & ar, const unsigned int version)
71 // protocol and hostname are the unique identifier for each service.
74 // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
78 ar & MaxUpdatesWithinInterval;
79 ar & MaxEqualUpdatesInSuccession;
82 // Activated was introduced with version 1.
86 BOOST_SERIALIZATION_SPLIT_MEMBER()
92 enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 };
93 virtual UpdateErrorCode perform_update(const std::string& ip) = 0;
95 // UpdateOk: Update was successful
96 // UpdateError: Unspecified error code returned from update server
97 // NoChange: IP was not changed_to_online
98 // Blocked: Client blocked due to abusive updates
99 // NotAuth: Authentication was not successful
100 // GenericError: Generic error. For example update server not reached, wrong hostname, not authenticated or network error.
101 // Generic error indicates that the update server couldn't associate the update request to any hostname.
105 typedef boost::shared_ptr<Service> Ptr;
111 void update(const std::string& ip, const time_t current_time, bool changed_to_online);
113 bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host);
115 void set_last_update(const time_t current_time, const std::string& ip);
117 time_t get_last_update_time();
119 int get_update_interval()const;
120 void set_update_interval(const int _update_interval);
122 int get_max_updates_within_interval() const;
123 void set_max_updates_within_interval(const int _max_updates_within_interval);
125 int get_max_equal_updates_in_succession() const;
126 void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession);
128 int get_dns_cache_ttl() const;
129 void set_dns_cache_ttl(const int _dns_cache_ttl);
131 void set_protocol(const std::string& _protocol);
132 std::string get_protocol() const;
134 void set_hostname(const std::string& _hostname);
135 std::string get_hostname() const;
137 void set_login(const std::string& _login);
138 std::string get_login() const;
140 void set_password(const std::string& _password);
141 std::string get_password() const;
143 void set_last_updates(std::map<time_t,std::string> _last_updates);
144 const std::map<time_t,std::string> get_last_updates() const;
146 void set_actual_ip(const std::string& _actual_ip);
147 std::string get_actual_ip() const;
149 void set_logger(const Logger::Ptr& _log);
150 Logger::Ptr get_logger() const;
152 std::string get_service_name() const;
154 void set_activated();
155 bool get_activated() const;
157 bool operator== (const Service& other) const;
158 bool operator!= (const Service& other) const;
161 BOOST_CLASS_VERSION(Service,1)