This is needed to prevent massiv use of webcheck IP url's.
IPAddrHelper::IPAddrHelper()
: Log(new Logger)
, WebcheckInterval(0)
+ , LastWebcheck(0)
, ProxyPort(0)
, UseIPv6(false)
{
/**
* Constructor.
*/
-IPAddrHelper::IPAddrHelper(const Logger::Ptr _log, const string& _webcheck_url, const string& _webcheck_url_alt, const int _webcheck_interval ,const bool _use_ipv6, const string& _proxy, const int _proxy_port)
+IPAddrHelper::IPAddrHelper(const Logger::Ptr _log, const string& _webcheck_url, const string& _webcheck_url_alt, const int _webcheck_interval, const int _last_webcheck ,const bool _use_ipv6, const string& _proxy, const int _proxy_port)
: Log(_log)
, WebcheckIpUrl(_webcheck_url)
, WebcheckIpUrlAlt(_webcheck_url_alt)
, WebcheckInterval(_webcheck_interval)
- , LastWebcheck(0)
+ , LastWebcheck(_last_webcheck)
, Proxy(_proxy)
, ProxyPort(_proxy_port)
, UseIPv6(_use_ipv6)
outBuffer->append(inBuffer);
return (size*nmemb);
}
+
+
+/**
+ * Get member LastWebcheck
+ * @return LastWebcheck
+ */
+int IPAddrHelper::get_last_webcheck() const
+{
+ return LastWebcheck;
+}
#include <boost/shared_ptr.hpp>
#include <curl/curl.h>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
class IPAddrHelper
{
private:
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & LastWebcheck;
+ }
+
Logger::Ptr Log;
std::string WebcheckIpUrl;
std::string WebcheckIpUrlAlt;
IPAddrHelper();
- IPAddrHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const int _webcheck_interval, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port);
+ IPAddrHelper(const Logger::Ptr _log, const std::string& _webcheck_url, const std::string& _webcheck_url_alt, const int _webcheck_interval, const int _last_webcheck, const bool _use_ipv6, const std::string& _proxy, const int _proxy_port);
~IPAddrHelper();
static int http_receive(char *inBuffer, size_t size, size_t nmemb, std::string *outBuffer);
void set_curl_url(CURL * curl_easy_handle, const std::string& url) const;
+
+ int get_last_webcheck() const;
};
#endif
*/
Serviceholder::Serviceholder(Logger::Ptr _log)
:Log(_log)
+ ,IPAddrHelp()
{
}
service_container->add_service(service);
}
- // Serialize Serviceholder into file.
+ // Serialize SerializeServiceContainer and IPAddrHelper into file.
ofstream ofs(OBJECT_FILE);
if ( ofs.is_open() )
{
SerializeServiceContainer* _service_container = service_container.get();
+ IPAddrHelper* _ip_addr_helper = IPAddrHelp.get();
try
{
boost::archive::text_oarchive oa(ofs);
- oa << _service_container;
+ oa << _service_container << _ip_addr_helper;
}
catch( boost::archive::archive_exception e )
{
{
// deserialize SerializeServiceContainer
SerializeServiceContainer* _service_container;
+ IPAddrHelper* _ip_addr_helper;
try
{
boost::archive::text_iarchive ia(ifs);
- ia >> _service_container;
+ ia >> _service_container >> _ip_addr_helper;
}
catch( boost::archive::archive_exception e )
{
return -1;
}
SerializeServiceContainer::Ptr service_container(_service_container);
+ IPAddrHelper::Ptr ip_addr_helper(_ip_addr_helper);
+ IPAddrHelp.swap(ip_addr_helper);
ifs.close();
// Get the list of old Services from de-serialized SerializeServiceContainer object.
service.reset();
}
OldServices.clear();
+
+ IPAddrHelp.reset();
}
{
return Services;
}
+
+
+/**
+ * Set member IPAddrHelp
+ * @param _ip_addr_helper The IPAddrHelper.
+ */
+void Serviceholder::set_ip_addr_helper(IPAddrHelper::Ptr _ip_addr_helper)
+{
+ IPAddrHelp = _ip_addr_helper;
+}
+
+
+/**
+ * Get member IPAddrHelp
+ * @return IPAddrHelp
+ */
+IPAddrHelper::Ptr Serviceholder::get_ip_addr_helper() const
+{
+ return IPAddrHelp;
+}
#include "service.h"
#include "serializeservicecontainer.h"
#include "logger.h"
+#include "ip_addr_helper.h"
#include <boost/shared_ptr.hpp>
#include <list>
std::list<Service::Ptr> OldServices; // Represents all old Services where the timeout isn't expired (in case the same Service is redefined).
std::list<Service::Ptr> Services; // Represents all active Services.
+ IPAddrHelper::Ptr IPAddrHelp;
+
public:
typedef boost::shared_ptr<Serviceholder> Ptr;
void delete_services();
+ void set_ip_addr_helper(IPAddrHelper::Ptr _ip_addr_helper);
+
+ IPAddrHelper::Ptr get_ip_addr_helper() const;
+
std::list<Service::Ptr> get_services() const;
};
*/
int Updater::init_ip_helper()
{
- // initialize IPHelper
- IPAddrHelper::Ptr _ipaddrhelp( new IPAddrHelper( Log, Conf->get_webcheck_ip_url(), Conf->get_webcheck_ip_url_alt(), Conf->get_webcheck_interval(), Conf->get_enable_ipv6(), Conf->get_proxy(), Conf->get_proxy_port() ) );
- IPAddrHelp.swap(_ipaddrhelp);
+ // Try to get deserialized IPAddrHelper from ServiceHolder
+ IPAddrHelper::Ptr _ip_addr_help = ServiceHolder->get_ip_addr_helper();
+ if ( _ip_addr_help.use_count() != 0 )
+ {
+ // Initialize IPHelper
+ IPAddrHelper::Ptr ip_addr_help( new IPAddrHelper( Log, Conf->get_webcheck_ip_url(), Conf->get_webcheck_ip_url_alt(), Conf->get_webcheck_interval(), _ip_addr_help->get_last_webcheck(), Conf->get_enable_ipv6(), Conf->get_proxy(), Conf->get_proxy_port() ) );
+ IPAddrHelp.swap(ip_addr_help);
+ }
+ else
+ {
+ // IPAddrHelper from ServiceHolder was not declared, so init oen with LastWebcheck 0
+ IPAddrHelper::Ptr ip_addr_help( new IPAddrHelper( Log, Conf->get_webcheck_ip_url(), Conf->get_webcheck_ip_url_alt(), Conf->get_webcheck_interval(), 0, Conf->get_enable_ipv6(), Conf->get_proxy(), Conf->get_proxy_port() ) );
+ IPAddrHelp.swap(ip_addr_help);
+ }
+
+ // Put the IPAddrHelper into ServiceHolder, so the LastWebcheck state will be serialized too.
+ ServiceHolder->set_ip_addr_helper(IPAddrHelp);
return 0;
}