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>
18 #include <boost/shared_ptr.hpp>
39 int MaxUpdatesWithinInterval;
40 int MaxEqualUpdatesInSuccession;
43 std::map<time_t,std::string> LastUpdates;
46 time_t ErrorServiceBlockedUntil;
48 friend class boost::serialization::access;
49 template<class Archive>
50 void serialize(Archive & ar, const unsigned int version)
52 // protocol and hostname are the unique identifier for each service.
55 // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
59 ar & MaxUpdatesWithinInterval;
60 ar & MaxEqualUpdatesInSuccession;
69 enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 };
70 virtual UpdateErrorCode perform_update(const std::string& ip) = 0;
72 // UpdateOk: Update was successful
73 // UpdateError: Unspecified error code returned from update server
74 // NoChange: IP was not changed_to_online
75 // Blocked: Client blocked due to abusive updates
76 // NotAuth: Authentication was not successful
77 // GenericError: Generic error. For example update server not reached, wrong hostname, not authenticated or network error.
78 // Generic error indicates that the update server couldn't associate the update request to any hostname.
82 typedef boost::shared_ptr<Service> Ptr;
88 void update(const std::string& ip, const time_t current_time, bool changed_to_online);
90 bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host);
92 void set_last_update(const time_t current_time, const std::string& ip);
94 time_t get_last_update_time();
96 int get_update_interval()const;
97 void set_update_interval(const int _update_interval);
99 int get_max_updates_within_interval() const;
100 void set_max_updates_within_interval(const int _max_updates_within_interval);
102 int get_max_equal_updates_in_succession() const;
103 void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession);
105 int get_dns_cache_ttl() const;
106 void set_dns_cache_ttl(const int _dns_cache_ttl);
108 void set_protocol(const std::string& _protocol);
109 std::string get_protocol() const;
111 void set_hostname(const std::string& _hostname);
112 std::string get_hostname() const;
114 void set_login(const std::string& _login);
115 std::string get_login() const;
117 void set_password(const std::string& _password);
118 std::string get_password() const;
120 void set_last_updates(std::map<time_t,std::string> _last_updates);
121 const std::map<time_t,std::string> get_last_updates() const;
123 void set_actual_ip(const std::string& _actual_ip);
124 std::string get_actual_ip() const;
126 void set_logger(const Logger::Ptr& _log);
127 Logger::Ptr get_logger() const;
129 std::string get_service_name() const;
131 void set_activated();
132 bool get_activated() const;
134 bool operator== (const Service& other) const;
135 bool operator!= (const Service& other) const;