Commit | Line | Data |
---|---|---|
b1be615b | 1 | /** @file |
3a89ac31 | 2 | * @brief The abstract service class. This class represents all services. |
b1be615b BS |
3 | * |
4 | * | |
5 | * | |
6 | * @copyright Intra2net AG | |
7 | * @license GPLv2 | |
8 | */ | |
9 | ||
4545a371 BS |
10 | #ifndef SERVICE_H |
11 | #define SERVICE_H | |
12 | ||
4de6a9b8 | 13 | #include "logger.hpp" |
88a594e8 | 14 | |
ca5d6889 BS |
15 | #include <boost/archive/text_oarchive.hpp> |
16 | #include <boost/archive/text_iarchive.hpp> | |
8dbf6830 BS |
17 | #include <boost/serialization/version.hpp> |
18 | #include <boost/serialization/split_member.hpp> | |
4545a371 | 19 | |
88a594e8 | 20 | #include <boost/shared_ptr.hpp> |
ca5d6889 BS |
21 | #include <string> |
22 | #include <list> | |
2bc1878a | 23 | |
3a89ac31 | 24 | |
4248e8ca TJ |
25 | class Service |
26 | { | |
92beaba3 | 27 | |
2bc1878a | 28 | private: |
88a594e8 | 29 | |
3a89ac31 BS |
30 | std::string Protocol; |
31 | std::string Hostname; | |
27baf279 | 32 | |
3a89ac31 BS |
33 | std::string Login; |
34 | std::string Password; | |
35 | ||
025abebb | 36 | std::string ActualIP; |
7be9aed9 | 37 | bool ActualIPIsBurnt; |
7335d7a7 | 38 | bool Activated; |
3a89ac31 | 39 | |
3c0cd271 BS |
40 | int UpdateInterval; |
41 | int MaxUpdatesWithinInterval; | |
4553e833 | 42 | int MaxEqualUpdatesInSuccession; |
c3dea5dc | 43 | int DNSCacheTTL; |
3c0cd271 | 44 | |
4553e833 | 45 | std::map<time_t,std::string> LastUpdates; |
2bc1878a | 46 | |
0f0908e1 TJ |
47 | int ErrorCount; |
48 | time_t ErrorServiceBlockedUntil; | |
49 | ||
2bc1878a BS |
50 | friend class boost::serialization::access; |
51 | template<class Archive> | |
8dbf6830 | 52 | void save(Archive & ar, const unsigned int version) const |
ca5d6889 BS |
53 | { |
54 | // protocol and hostname are the unique identifier for each service. | |
55 | ar & Protocol; | |
56 | ar & Hostname; | |
57 | // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. | |
58 | ar & LastUpdates; | |
59 | ar & ActualIP; | |
60 | ar & UpdateInterval; | |
61 | ar & MaxUpdatesWithinInterval; | |
4553e833 | 62 | ar & MaxEqualUpdatesInSuccession; |
ca5d6889 | 63 | ar & DNSCacheTTL; |
8dbf6830 BS |
64 | |
65 | // Activated was introduced with version 1. | |
7335d7a7 | 66 | ar & Activated; |
ca5d6889 | 67 | } |
8dbf6830 BS |
68 | template<class Archive> |
69 | void load(Archive & ar, const unsigned int version) | |
70 | { | |
71 | // protocol and hostname are the unique identifier for each service. | |
72 | ar & Protocol; | |
73 | ar & Hostname; | |
74 | // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. | |
75 | ar & LastUpdates; | |
76 | ar & ActualIP; | |
77 | ar & UpdateInterval; | |
78 | ar & MaxUpdatesWithinInterval; | |
79 | ar & MaxEqualUpdatesInSuccession; | |
80 | ar & DNSCacheTTL; | |
81 | ||
82 | // Activated was introduced with version 1. | |
83 | if ( version >= 1 ) | |
84 | ar & Activated; | |
85 | } | |
86 | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
2bc1878a | 87 | |
88a594e8 | 88 | Logger::Ptr Log; |
27baf279 | 89 | |
d008afbe TJ |
90 | protected: |
91 | ||
7335d7a7 | 92 | enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 }; |
d008afbe TJ |
93 | virtual UpdateErrorCode perform_update(const std::string& ip) = 0; |
94 | ||
7335d7a7 BS |
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. | |
102 | ||
4545a371 | 103 | public: |
88a594e8 BS |
104 | |
105 | typedef boost::shared_ptr<Service> Ptr; | |
106 | ||
4545a371 BS |
107 | Service(); |
108 | ||
4248e8ca | 109 | virtual ~Service(); |
4545a371 | 110 | |
0ebcd4ef | 111 | void update(const std::string& ip, const time_t current_time, bool changed_to_online); |
c3dea5dc | 112 | |
08e6f339 | 113 | bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host); |
4545a371 | 114 | |
4553e833 BS |
115 | void set_last_update(const time_t current_time, const std::string& ip); |
116 | ||
117 | time_t get_last_update_time(); | |
fc613942 | 118 | |
3c0cd271 | 119 | int get_update_interval()const; |
e8d4a6f8 | 120 | void set_update_interval(const int _update_interval); |
6d64d311 | 121 | |
3c0cd271 | 122 | int get_max_updates_within_interval() const; |
e8d4a6f8 | 123 | void set_max_updates_within_interval(const int _max_updates_within_interval); |
b38684ce | 124 | |
4553e833 BS |
125 | int get_max_equal_updates_in_succession() const; |
126 | void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession); | |
127 | ||
c3dea5dc BS |
128 | int get_dns_cache_ttl() const; |
129 | void set_dns_cache_ttl(const int _dns_cache_ttl); | |
130 | ||
e8d4a6f8 | 131 | void set_protocol(const std::string& _protocol); |
b38684ce | 132 | std::string get_protocol() const; |
3a89ac31 | 133 | |
e8d4a6f8 | 134 | void set_hostname(const std::string& _hostname); |
b38684ce | 135 | std::string get_hostname() const; |
3a89ac31 | 136 | |
e8d4a6f8 | 137 | void set_login(const std::string& _login); |
b38684ce | 138 | std::string get_login() const; |
3a89ac31 | 139 | |
e8d4a6f8 | 140 | void set_password(const std::string& _password); |
b38684ce | 141 | std::string get_password() const; |
3a89ac31 | 142 | |
4553e833 BS |
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; | |
2bc1878a | 145 | |
e8d4a6f8 | 146 | void set_actual_ip(const std::string& _actual_ip); |
b38684ce | 147 | std::string get_actual_ip() const; |
27baf279 | 148 | |
e8d4a6f8 | 149 | void set_logger(const Logger::Ptr& _log); |
b38684ce | 150 | Logger::Ptr get_logger() const; |
27baf279 | 151 | |
c3dea5dc | 152 | std::string get_service_name() const; |
3c0cd271 | 153 | |
7335d7a7 BS |
154 | void set_activated(); |
155 | bool get_activated() const; | |
156 | ||
e8d4a6f8 BS |
157 | bool operator== (const Service& other) const; |
158 | bool operator!= (const Service& other) const; | |
4545a371 BS |
159 | }; |
160 | ||
8dbf6830 BS |
161 | BOOST_CLASS_VERSION(Service,1) |
162 | ||
4545a371 | 163 | #endif |