Don't use pointer to std::list<int>, make a copy.
Log->print_usage(OptDescCmd);
return -1;
}
+ catch( po::error e )
+ {
+ Log->print_error_parsing_cmd(e.what());
+ Log->print_usage(OptDescCmd);
+ return -1;
+ }
return 0;
}
string protocol = vm["protocol"].as<string>();
string host = vm["host"].as<string>();
string login = vm["login"].as<string>();
- string password = vm["password"].as<string>();
+ string password = vm["password"].as<string>();
protocol = ba::to_lower_copy(protocol);
Log->print_unknown_service_conf_option(full_filename,e.what());
return -1;
}
- catch(po::multiple_occurrences e)
+ catch( po::multiple_occurrences e )
{
service_config_file.close();
Log->print_multiple_service_conf_option(full_filename,e.what());
return -1;
}
+ catch( po::error e )
+ {
+ service_config_file.close();
+ Log->print_error_parsing_config_file(full_filename,e.what());
+ return -1;
+ }
service_config_file.close();
}
else
* @param actual_ip Service's actual_ip.
* @param lastupdated Service's lastupdated.
*/
-void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list<int>* lastupdated) const
+void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list<int> lastupdated) const
{
int level = 1;
if ( level <= Loglevel )
msg << "\t" << "Max Updates: " << max_updates_within_interval << endl;
msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl;
msg << "\t" << "Actual_IP: " << actual_ip << endl;
- BOOST_FOREACH( int update_time, *lastupdated)
+ BOOST_FOREACH( int update_time, lastupdated)
{
msg << "\t" << "Lastupdated: " << update_time << endl;
}
* An exception occured while computing the md5 sum.
* @param what The exception occured.
*/
-void Logger::print_exception_md5_sum(const std::string& what) const
+void Logger::print_exception_md5_sum(const string& what) const
{
int level = 0;
if ( level <= Loglevel )
* An network exception occured.
* @param what The exception occured.
*/
-void Logger::print_network_error(const std::string& what) const
+void Logger::print_network_error(const string& what) const
{
int level = 0;
if ( level <= Loglevel )
* @param protocol The protocol
* @param error The error
*/
-void Logger::print_undefined_protocol_error(const std::string& protocol, const std::string& error) const
+void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
{
int level = 0;
if ( level <= Loglevel )
* Error while trying to log through external program.
* @param external_prog The external program called.
*/
-void Logger::print_error_external_logging(const std::string& external_prog) const
+void Logger::print_error_external_logging(const string& external_prog) const
{
int level = 0;
if ( level <= Loglevel )
log_notice(msg.str(),level);
}
}
+
+
+/**
+ * Error while parsing config file.
+ * @param error Error occured.
+ * @param config_file Config file.
+ */
+void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
+{
+ int level = 0;
+ if ( level <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
+ log_notice(msg.str(),level);
+ }
+}
+
+
+/**
+ * Error while parsing cmd option
+ * @param error Error
+ */
+void Logger::print_error_parsing_cmd(const string& error) const
+{
+ int level = 0;
+ if ( level <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Error while parsing cmd options: " << error << endl;
+ log_error(msg.str(),level);
+ }
+}
void print_deserialized_objects_success() const;
- void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const std::string& actual_ip, std::list<int>* lastupdated) const;
+ void print_service_object(const std::string& message, const std::string& protocol, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const std::string& actual_ip, std::list<int> lastupdated) const;
void print_exception_serialize(const std::string& exception) const;
void print_undefined_protocol_error(const std::string& protocol, const std::string& error) const;
void print_error_external_logging(const std::string& external_prog) const;
+
+ void print_error_parsing_config_file(const std::string& filename, const std::string& error) const;
+
+ void print_error_parsing_cmd(const std::string& error) const;
};
#endif
#include "logger.h"
#include <boost/serialization/list.hpp>
+#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/export.hpp>
/**
- * Although this is an abstract class, we need the serialize function that we can serialize derived classes through a Service *.
- * @param ar Archive.
- * @param version Version.
- */
-/*
-template<class Archive>
-void Service::serialize(Archive & ar, const unsigned int version)
-{
- // protocol and hostname are the unique identifier for each service.
- ar & Protocol;
- ar & Hostname;
- // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
- ar & LastUpdates;
- ar & ActualIP;
- ar & UpdateInterval;
- ar & MaxUpdatesWithinInterval;
- ar & DNSCacheTTL;
-}
-*/
-
-/**
* Setter for member Protocol.
* @param _protocol Value to set Protocol to.
*/
}
-void Service::set_last_updates(std::list<int>* _last_updates)
+void Service::set_last_updates(std::list<int> _last_updates)
{
LastUpdates.clear();
- BOOST_FOREACH( int update_time, *_last_updates )
+ BOOST_FOREACH( int update_time, _last_updates )
{
LastUpdates.push_back(update_time);
}
* Getter for member Lastupdated.
* @return Value of member Lastupdated.
*/
-list<int>* Service::get_last_updates()
+list<int> Service::get_last_updates()
{
- return &LastUpdates;
+ return LastUpdates;
}
void set_password(const std::string& _password);
std::string get_password() const;
- void set_last_updates(std::list<int>* _last_updates);
- std::list<int>* get_last_updates();
+ void set_last_updates(std::list<int> _last_updates);
+ std::list<int> get_last_updates();
void set_actual_ip(const std::string& _actual_ip);
std::string get_actual_ip() const;
BOOST_FOREACH(Service::Ptr &service, OldServices)
{
- if ( ( service->get_last_updates()->front() + (service->get_update_interval()*60) ) >= current_time ) // UpdateInterval timeout of service isn't expired.
+ if ( ( service->get_last_updates().front() + (service->get_update_interval()*60) ) >= current_time ) // UpdateInterval timeout of service isn't expired.
service_container->add_service(service);
}
int current_time = time(NULL);
int lastupdated = 0;
- if ( service->get_last_updates()->size() > 0 )
- lastupdated = service->get_last_updates()->front();
+ if ( service->get_last_updates().size() > 0 )
+ lastupdated = service->get_last_updates().front();
// If the dns cache ttl is expired or the service is updated for the first time, then get the actual ip of the dns record (this should be the IP in the last update)
if ( ((lastupdated != 0) && ((lastupdated + service->get_dns_cache_ttl()) < current_time)) || (lastupdated == 0) )