Block service for a short period of time on too many update errors
[bpdyndnsd] / src / service.hpp
1 /** @file
2  * @brief The abstract service class. This class represents all services.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #ifndef SERVICE_H
11 #define SERVICE_H
12
13 #include "logger.hpp"
14
15 #include <boost/archive/text_oarchive.hpp>
16 #include <boost/archive/text_iarchive.hpp>
17
18 #include <boost/shared_ptr.hpp>
19 #include <string>
20 #include <list>
21
22
23 class Service
24 {
25
26 private:
27
28     std::string Protocol;
29     std::string Hostname;
30
31     std::string Login;
32     std::string Password;
33
34     std::string ActualIP;
35
36     int UpdateInterval;
37     int MaxUpdatesWithinInterval;
38     int DNSCacheTTL;
39
40     std::list<time_t> LastUpdates;
41
42     int ErrorCount;
43     time_t ErrorServiceBlockedUntil;
44
45     friend class boost::serialization::access;
46     template<class Archive>
47     void serialize(Archive & ar, const unsigned int version)
48     {
49         // protocol and hostname are the unique identifier for each service.
50         ar & Protocol;
51         ar & Hostname;
52         // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
53         ar & LastUpdates;
54         ar & ActualIP;
55         ar & UpdateInterval;
56         ar & MaxUpdatesWithinInterval;
57         ar & DNSCacheTTL;
58     }
59
60     Logger::Ptr Log;
61
62 public:
63
64     typedef boost::shared_ptr<Service> Ptr;
65
66     Service();
67
68     virtual ~Service();
69
70     virtual int perform_update(const std::string& ip) = 0;
71
72     void update(const std::string& ip, const time_t current_time);
73
74     bool update_allowed(const time_t current_time);
75
76     void set_last_update(const time_t current_time);
77
78     int get_update_interval()const;
79     void set_update_interval(const int _update_interval);
80
81     int get_max_updates_within_interval() const;
82     void set_max_updates_within_interval(const int _max_updates_within_interval);
83
84     int get_dns_cache_ttl() const;
85     void set_dns_cache_ttl(const int _dns_cache_ttl);
86
87     void set_protocol(const std::string& _protocol);
88     std::string get_protocol() const;
89
90     void set_hostname(const std::string& _hostname);
91     std::string get_hostname() const;
92
93     void set_login(const std::string& _login);
94     std::string get_login() const;
95
96     void set_password(const std::string& _password);
97     std::string get_password() const;
98
99     void set_last_updates(std::list<time_t> _last_updates);
100     const std::list<time_t> get_last_updates() const;
101
102     void set_actual_ip(const std::string& _actual_ip);
103     std::string get_actual_ip() const;
104
105     void set_logger(const Logger::Ptr& _log);
106     Logger::Ptr get_logger() const;
107
108     std::string get_service_name() const;
109
110     bool operator== (const Service& other) const;
111     bool operator!= (const Service& other) const;
112 };
113
114 #endif