Don't update the same IP more than 2 times in success.
[bpdyndnsd] / src / service.hpp
CommitLineData
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
23class Service
24{
92beaba3 25
2bc1878a 26private:
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;
3a89ac31 35
3c0cd271
BS
36 int UpdateInterval;
37 int MaxUpdatesWithinInterval;
4553e833 38 int MaxEqualUpdatesInSuccession;
c3dea5dc 39 int DNSCacheTTL;
3c0cd271 40
4553e833 41 std::map<time_t,std::string> LastUpdates;
2bc1878a 42
0f0908e1
TJ
43 int ErrorCount;
44 time_t ErrorServiceBlockedUntil;
45
2bc1878a
BS
46 friend class boost::serialization::access;
47 template<class Archive>
ca5d6889
BS
48 void serialize(Archive & ar, const unsigned int version)
49 {
50 // protocol and hostname are the unique identifier for each service.
51 ar & Protocol;
52 ar & Hostname;
53 // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
54 ar & LastUpdates;
55 ar & ActualIP;
56 ar & UpdateInterval;
57 ar & MaxUpdatesWithinInterval;
4553e833 58 ar & MaxEqualUpdatesInSuccession;
ca5d6889
BS
59 ar & DNSCacheTTL;
60 }
2bc1878a 61
88a594e8 62 Logger::Ptr Log;
27baf279 63
4545a371 64public:
88a594e8
BS
65
66 typedef boost::shared_ptr<Service> Ptr;
67
4545a371
BS
68 Service();
69
4248e8ca 70 virtual ~Service();
4545a371 71
c3dea5dc
BS
72 virtual int perform_update(const std::string& ip) = 0;
73
0ebcd4ef 74 void update(const std::string& ip, const time_t current_time, bool changed_to_online);
c3dea5dc 75
0ebcd4ef 76 bool update_allowed(const time_t current_time, bool changed_to_online);
4545a371 77
4553e833
BS
78 void set_last_update(const time_t current_time, const std::string& ip);
79
80 time_t get_last_update_time();
fc613942 81
3c0cd271 82 int get_update_interval()const;
e8d4a6f8 83 void set_update_interval(const int _update_interval);
6d64d311 84
3c0cd271 85 int get_max_updates_within_interval() const;
e8d4a6f8 86 void set_max_updates_within_interval(const int _max_updates_within_interval);
b38684ce 87
4553e833
BS
88 int get_max_equal_updates_in_succession() const;
89 void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession);
90
c3dea5dc
BS
91 int get_dns_cache_ttl() const;
92 void set_dns_cache_ttl(const int _dns_cache_ttl);
93
e8d4a6f8 94 void set_protocol(const std::string& _protocol);
b38684ce 95 std::string get_protocol() const;
3a89ac31 96
e8d4a6f8 97 void set_hostname(const std::string& _hostname);
b38684ce 98 std::string get_hostname() const;
3a89ac31 99
e8d4a6f8 100 void set_login(const std::string& _login);
b38684ce 101 std::string get_login() const;
3a89ac31 102
e8d4a6f8 103 void set_password(const std::string& _password);
b38684ce 104 std::string get_password() const;
3a89ac31 105
4553e833
BS
106 void set_last_updates(std::map<time_t,std::string> _last_updates);
107 const std::map<time_t,std::string> get_last_updates() const;
2bc1878a 108
e8d4a6f8 109 void set_actual_ip(const std::string& _actual_ip);
b38684ce 110 std::string get_actual_ip() const;
27baf279 111
e8d4a6f8 112 void set_logger(const Logger::Ptr& _log);
b38684ce 113 Logger::Ptr get_logger() const;
27baf279 114
c3dea5dc 115 std::string get_service_name() const;
3c0cd271 116
e8d4a6f8
BS
117 bool operator== (const Service& other) const;
118 bool operator!= (const Service& other) const;
4545a371
BS
119};
120
121#endif