// Disable bogus BOOST warnings
-emacro(58,BOOST_ASSERT)
-emacro(*, BOOST_FOREACH)
+-esym(665, BOOST_FOREACH)
-emacro(121, BOOST_CLASS_EXPORT_GUID)
-esym(1024, boost::lexical_cast)
+-esym(534, boost::program_options::options_description_easy_init::operator*)
+-esym(534, boost::algorithm::split)
+-esym(534, boost::program_options::options_description::add)
// Don't show errors in (boost) library headers
-wlib(0)
time_t current_time = time(NULL);
// Test if webcheck is allowed due to webcheck_interval.
- if ( (LastWebcheck + ((time_t)(WebcheckInterval*60))) >= current_time )
+ if ( (LastWebcheck + ((time_t)WebcheckInterval*60)) >= current_time )
{
// Webcheck not allowed, log it and return empty string.
Log->print_webcheck_exceed_interval( LastWebcheck, (WebcheckInterval*60), current_time );
if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
{
ostringstream msg;
- msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " "<< curl_err << endl; // lint !e 641
+ msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
log_error(msg.str());
}
}
if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
{
ostringstream msg;
- msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << endl; // lint !e 641
+ msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
log_warning(msg.str(),level);
}
}
if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
{
ostringstream msg;
- msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << " " << curl_err_buff << endl; // lint !e 641
+ msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */
log_warning(msg.str(),level);
}
}
if ( kill(pid,SIGTERM) != 0 )
{
updater->get_logger()->print_error_kill_child(pid);
- shutdown_parent(false,-1); // lint !e 534 // keep pidfile
+ shutdown_parent(false,-1); /*lint !e534 */
}
else
{
updater->get_logger()->print_child_killed(pid);
- shutdown_parent(true,-1); // lint !e 534 // remove pidfile
+ shutdown_parent(true,-1); /*lint !e534 */
}
}
updater->get_logger()->print_runnig_as_daemon(pid);
- shutdown_parent(false,0); // lint !e 534 // keep pidfile
+ shutdown_parent(false,0); /*lint !e534 */
}
// child starts here
}
{
if ( write_pidfile(getpid()) != 0 )
{
- shutdown(); // lint !e 534
+ shutdown(); /*lint !e534 */
exit(-1);
}
}
// Snore, snore... don't hug the cpu if we are in daemon_mode.
if ( updater->get_config()->get_daemon_mode() == 1 )
- sleep(10); // lint !e 534
+ sleep(10); /*lint !e534 */
}while ( updater->get_config()->get_daemon_mode() == 1 );
Log->print_network_error(out.str());
return -1;
}
+ catch ( exception& e )
+ {
+ ostringstream out;
+ out << "NetHelper::open_connection(): " << e.what() << " Host: " << hostname << " Port: " << port;
+ Log->print_network_error(out.str());
+ return -1;
+ }
+ catch ( ... )
+ {
+ ostringstream out;
+ out << "Unknown exception caught while trying to connect to Host: " << hostname << " Port: " << port;
+ Log->print_network_error(out.str());
+ return -1;
+ }
return 0;
}
for (iter = LastUpdates.begin(); (iter != LastUpdates.end()) && ( i < MaxUpdatesWithinInterval ); iter++)
{
- if ( (i == (MaxUpdatesWithinInterval-1)) && ( (*iter + ((time_t)(UpdateInterval*60))) >= current_time ) )
+ if ( (i == (MaxUpdatesWithinInterval-1)) && ( (*iter + ((time_t)UpdateInterval*60)) >= current_time ) )
{
Log->print_update_not_allowed(current_time,*iter,MaxUpdatesWithinInterval,get_service_name());
return false;
// Get the salt out of received http data
if ( boost::regex_search(curl_data,matches,expr_salt) )
{
- response.insert(pair<string,string>("salt",matches[1].str())); // lint !e 534
+ response.insert(pair<string,string>("salt",matches[1].str())); /*lint !e534 */
get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
}
else
// Get the time out of received http data
if ( boost::regex_search(curl_data,matches,expr_time) )
{
- response.insert(pair<string,string>("time",matches[1].str())); // lint !e 534
+ response.insert(pair<string,string>("time",matches[1].str())); /*lint !e534 */
get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
}
else
// Get the sign out of received http data
if ( boost::regex_search(curl_data,matches,expr_sign) )
{
- response.insert(pair<string,string>("sign",matches[1].str())); // lint !e 534
+ response.insert(pair<string,string>("sign",matches[1].str())); /*lint !e534 */
get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
}
else
string server_greeting = connection->receive_data();
if ( server_greeting.empty() )
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
login << "LOGIN " << get_login() << " " << get_password() << endl;
if (connection->send_data(login.str()) != 0)
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
string login_reply = connection->receive_data();
if ( login_reply.empty() )
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
else
{
// Login failed
get_logger()->print_service_not_authorized(UpdateServer,get_login(),get_password());
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
else if ( status_code != "225" )
{
// Undefined protocol error, Log login_reply
get_logger()->print_undefined_protocol_error("ODS",login_reply);
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
}
// Send delete request
if (connection->send_data(delete_request.str()) != 0)
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
// Get delete reply
delete_reply = connection->receive_data();
if ( delete_reply.empty() )
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
del_count++;
update_request << "ADDRR " << get_hostname() << " A " << ip << endl;
if (connection->send_data(update_request.str()) != 0)
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
string update_reply = connection->receive_data();
if ( update_reply.empty() )
{
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
else
if ( status_code != "795" )
{
get_logger()->print_undefined_protocol_error("ODS",update_reply);
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return -1;
}
}
// Successfully updated host
- connection->close_connection();
+ connection->close_connection(); /*lint !e534 */
return 0;
}
BOOST_FOREACH(const Service::Ptr &service, OldServices)
{
- if ( ( service->get_last_updates().front() + ((time_t)(service->get_update_interval()*60) )) >= current_time ) // UpdateInterval timeout of service isn't expired.
+ if ( ( service->get_last_updates().front() + ((time_t)service->get_update_interval()*60) ) >= current_time ) // UpdateInterval timeout of service isn't expired.
service_container->add_service(service);
}
* @param endpoint_iterator The enpoint iterator.
* @return throws boost::syste::system_error if something went wrong.
*/
-void TCPService::connect(const std::string& _host, const std::string& _port) throw (boost::system::system_error)
+void TCPService::connect(const std::string& _host, const std::string& _port)
{
// Init boost::system::error_code
boost::system::error_code err_code;
{
do
{
- Socket->lowest_layer().close();
- Socket->lowest_layer().connect(*endpoint_iterator++, err_code);
+ Socket->lowest_layer().close(); /*lint !e534 */
+ Socket->lowest_layer().connect(*endpoint_iterator++, err_code); /*lint !e534 */
} while ( err_code && (endpoint_iterator != end_iter) );
}
if ( err_code )
throw boost::system::system_error(err_code);
// Perform SSL handshake
- Socket->handshake(boost::asio::ssl::stream_base::client,err_code);
+ Socket->handshake(boost::asio::ssl::stream_base::client,err_code); /*lint !e534*/
if ( err_code )
throw boost::system::system_error(err_code);
* Will read all available data and return it as a string.
* @return The data read from the socket. Throws boost::syste::system_error if something went wrong.
*/
-std::string TCPService::read_from_socket() throw (boost::system::system_error)
+std::string TCPService::read_from_socket()
{
// Limit stream buffer to 1MB
//unsigned int max_buff_size = 1024*1024;
* @param data The data which will be written to the socket.
* @return Throws boost::syste::system_error if something went wrong.
*/
-void TCPService::write_to_socket(const string& data) throw (boost::system::system_error)
+void TCPService::write_to_socket(const string& data)
{
// Get the data size which will be written
size_t data_size = data.size();
* Will close the session.
* @return 0 if all is fine, throws boost::syste::system_error if something went wrong.
*/
-void TCPService::close() throw (boost::system::system_error)
+void TCPService::close()
{
boost::system::error_code error_code;
// Shutdown send and receive channel on socket. This results in sending FIN flag.
- Socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both,error_code);
+ Socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both,error_code); /*lint !e534*/
if ( error_code )
throw boost::system::system_error(error_code);
// Closing the session.
- Socket->lowest_layer().close( error_code );
+ Socket->lowest_layer().close( error_code ); /*lint !e534*/
if ( error_code )
throw boost::system::system_error(error_code);
~TCPService();
- virtual void connect(const std::string& _hostname, const std::string& _port) throw (boost::system::system_error);
+ virtual void connect(const std::string& _hostname, const std::string& _port);
- std::string read_from_socket() throw (boost::system::system_error);
+ std::string read_from_socket();
- void write_to_socket(const std::string& data) throw (boost::system::system_error);
+ void write_to_socket(const std::string& data);
- void close() throw (boost::system::system_error);
+ void close();
};
#endif
// Now we can call init_ex.
if ( EVP_DigestInit_ex(&mdctx, md, NULL) == 0 )
{
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not set up digest context correctly");
}
// Test if data is empty.
if ( data.empty() )
{
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Passed data is empty");
}
// Hash the data. At this point data is not empty and &mdctx is initialized.
if ( EVP_DigestUpdate(&mdctx, data.c_str(), data.size()) == 0 )
{
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not hash data into digest context");
}
// Retrieve the digest value from &mdctx and place it in md_value.
if ( EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0 )
{
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Could not retrieve digest value");
}
// Test if md_value is filled correctly and md_len is not zero.
if ( (md_len == 0) || (EVP_MD_CTX_size(&mdctx) == 0) )
{
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
throw std::invalid_argument("Retrieved invalid digest value");
}
// Internal cleanup of the digest content.
- EVP_MD_CTX_cleanup(&mdctx);
- EVP_cleanup();
+ EVP_MD_CTX_cleanup(&mdctx); /*lint !e534 */
+ EVP_cleanup(); /*lint !e534 */
// Convert md5 digest C string to hex.
std::ostringstream oss_digest_md5_hex;
{
std::list<std::string> tokens;
boost::algorithm::split(tokens,data,boost::is_any_of(delimiter));
+ if ( tokens.empty() )
+ return "";
return tokens.front();
}
-};
+
+}