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> | |
4545a371 | 17 | |
88a594e8 | 18 | #include <boost/shared_ptr.hpp> |
ca5d6889 BS |
19 | #include <string> |
20 | #include <list> | |
2bc1878a | 21 | |
3a89ac31 | 22 | |
4248e8ca TJ |
23 | class Service |
24 | { | |
92beaba3 | 25 | |
2bc1878a | 26 | private: |
88a594e8 | 27 | |
3a89ac31 BS |
28 | std::string Protocol; |
29 | std::string Hostname; | |
27baf279 | 30 | |
3a89ac31 BS |
31 | std::string Login; |
32 | std::string Password; | |
33 | ||
025abebb | 34 | std::string ActualIP; |
7be9aed9 | 35 | bool ActualIPIsBurnt; |
7335d7a7 | 36 | bool Activated; |
3a89ac31 | 37 | |
3c0cd271 BS |
38 | int UpdateInterval; |
39 | int MaxUpdatesWithinInterval; | |
4553e833 | 40 | int MaxEqualUpdatesInSuccession; |
c3dea5dc | 41 | int DNSCacheTTL; |
3c0cd271 | 42 | |
4553e833 | 43 | std::map<time_t,std::string> LastUpdates; |
2bc1878a | 44 | |
0f0908e1 TJ |
45 | int ErrorCount; |
46 | time_t ErrorServiceBlockedUntil; | |
47 | ||
2bc1878a BS |
48 | friend class boost::serialization::access; |
49 | template<class Archive> | |
ca5d6889 BS |
50 | void serialize(Archive & ar, const unsigned int version) |
51 | { | |
52 | // protocol and hostname are the unique identifier for each service. | |
53 | ar & Protocol; | |
54 | ar & Hostname; | |
55 | // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. | |
56 | ar & LastUpdates; | |
57 | ar & ActualIP; | |
58 | ar & UpdateInterval; | |
59 | ar & MaxUpdatesWithinInterval; | |
4553e833 | 60 | ar & MaxEqualUpdatesInSuccession; |
ca5d6889 | 61 | ar & DNSCacheTTL; |
7335d7a7 | 62 | ar & Activated; |
ca5d6889 | 63 | } |
2bc1878a | 64 | |
88a594e8 | 65 | Logger::Ptr Log; |
27baf279 | 66 | |
d008afbe TJ |
67 | protected: |
68 | ||
7335d7a7 | 69 | enum UpdateErrorCode { UpdateOk=0, UpdateError=1, NoChange=2, Blocked=3, NotAuth=4, GenericError=4 }; |
d008afbe TJ |
70 | virtual UpdateErrorCode perform_update(const std::string& ip) = 0; |
71 | ||
7335d7a7 BS |
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. | |
79 | ||
4545a371 | 80 | public: |
88a594e8 BS |
81 | |
82 | typedef boost::shared_ptr<Service> Ptr; | |
83 | ||
4545a371 BS |
84 | Service(); |
85 | ||
4248e8ca | 86 | virtual ~Service(); |
4545a371 | 87 | |
0ebcd4ef | 88 | void update(const std::string& ip, const time_t current_time, bool changed_to_online); |
c3dea5dc | 89 | |
08e6f339 | 90 | bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host); |
4545a371 | 91 | |
4553e833 BS |
92 | void set_last_update(const time_t current_time, const std::string& ip); |
93 | ||
94 | time_t get_last_update_time(); | |
fc613942 | 95 | |
3c0cd271 | 96 | int get_update_interval()const; |
e8d4a6f8 | 97 | void set_update_interval(const int _update_interval); |
6d64d311 | 98 | |
3c0cd271 | 99 | int get_max_updates_within_interval() const; |
e8d4a6f8 | 100 | void set_max_updates_within_interval(const int _max_updates_within_interval); |
b38684ce | 101 | |
4553e833 BS |
102 | int get_max_equal_updates_in_succession() const; |
103 | void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession); | |
104 | ||
c3dea5dc BS |
105 | int get_dns_cache_ttl() const; |
106 | void set_dns_cache_ttl(const int _dns_cache_ttl); | |
107 | ||
e8d4a6f8 | 108 | void set_protocol(const std::string& _protocol); |
b38684ce | 109 | std::string get_protocol() const; |
3a89ac31 | 110 | |
e8d4a6f8 | 111 | void set_hostname(const std::string& _hostname); |
b38684ce | 112 | std::string get_hostname() const; |
3a89ac31 | 113 | |
e8d4a6f8 | 114 | void set_login(const std::string& _login); |
b38684ce | 115 | std::string get_login() const; |
3a89ac31 | 116 | |
e8d4a6f8 | 117 | void set_password(const std::string& _password); |
b38684ce | 118 | std::string get_password() const; |
3a89ac31 | 119 | |
4553e833 BS |
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; | |
2bc1878a | 122 | |
e8d4a6f8 | 123 | void set_actual_ip(const std::string& _actual_ip); |
b38684ce | 124 | std::string get_actual_ip() const; |
27baf279 | 125 | |
e8d4a6f8 | 126 | void set_logger(const Logger::Ptr& _log); |
b38684ce | 127 | Logger::Ptr get_logger() const; |
27baf279 | 128 | |
c3dea5dc | 129 | std::string get_service_name() const; |
3c0cd271 | 130 | |
7335d7a7 BS |
131 | void set_activated(); |
132 | bool get_activated() const; | |
133 | ||
e8d4a6f8 BS |
134 | bool operator== (const Service& other) const; |
135 | bool operator!= (const Service& other) const; | |
4545a371 BS |
136 | }; |
137 | ||
138 | #endif |