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