: Log(new Logger)
, ProxyPort(0)
, CurlError(CURLE_OK)
- , CurlEasyHandle(NULL)
{
+ CurlEasyHandle = init_curl(CurlWritedataBuff, CurlErrBuff);
}
CurlEasyHandle = init_curl(CurlWritedataBuff, CurlErrBuff);
if ( CurlEasyHandle != NULL )
{
- set_curl_auth(_username,_password);
+ if ( set_curl_auth(_username,_password) != CURLE_OK )
+ {
+ curl_easy_cleanup(CurlEasyHandle);
+ CurlEasyHandle = NULL;
+ }
}
}
*/
long HTTPHelper::http_get(const string& url)
{
- CURLcode curl_err_code;
long curl_info;
if ( CurlEasyHandle != NULL )
{
- set_curl_url(url);
-
- if ( (curl_err_code = curl_easy_perform(CurlEasyHandle) ) != CURLE_OK )
+ if ( (CurlError = set_curl_url(url)) != CURLE_OK )
+ {
+ Log->print_curl_error(url,CurlError,CurlErrBuff);
+ CurlWritedataBuff.clear();
+ return -1;
+ }
+ if ( (CurlError = curl_easy_perform(CurlEasyHandle) ) != CURLE_OK )
{
- Log->print_curl_error(url,curl_err_code,CurlErrBuff);
+ Log->print_curl_error(url,CurlError,CurlErrBuff);
CurlWritedataBuff.clear();
return -1;
}
- if ( (curl_err_code = curl_easy_getinfo(CurlEasyHandle,CURLINFO_RESPONSE_CODE,&curl_info)) != CURLE_OK )
+ if ( (CurlError = curl_easy_getinfo(CurlEasyHandle,CURLINFO_RESPONSE_CODE,&curl_info)) != CURLE_OK )
{
- Log->print_curl_error(url,curl_err_code);
+ Log->print_curl_error(url,CurlError);
CurlWritedataBuff.clear();
return -1;
}
* Initialized curl easy handle with a few options.
* @param curl_writedata_buff Reference to a string wich will be filled with the curl result
* @param curl_err_buff A pointer to an char array which will be filled with error message.
- * @return A pointer to the easy curl handle.
+ * @return A pointer to the easy curl handle or NULL if something went wrong.
*/
CURL* HTTPHelper::init_curl(string& curl_writedata_buff,char* curl_err_buff)
{
/**
* Sets a url to the easy curl handle
* @param url The url to set.
+ * @return CURLcode CURLE_OK if everything is right.
*/
-void HTTPHelper::set_curl_url(const string& url)
+CURLcode HTTPHelper::set_curl_url(const string& url)
{
- if ( CurlEasyHandle != NULL )
+ if ( (CurlEasyHandle != NULL) && (CurlError == CURLE_OK) )
{
- curl_easy_setopt(CurlEasyHandle,CURLOPT_URL,url.c_str());
+ CurlError = curl_easy_setopt(CurlEasyHandle,CURLOPT_URL,url.c_str());
+ if ( CurlError != CURLE_OK )
+ {
+ // Some options could not be set, so destroy the CURL handle.
+ Log->print_curl_error_init("Could not set CURL URL properly.",CurlError);
+ curl_easy_cleanup(CurlEasyHandle);
+ CurlEasyHandle = NULL;
+ }
}
+ return CurlError;
}
* Sets HTTP AUTH parameters
* @param username The username for HTTP AUTH
* @param password The password for HTTP AUTH
+ * @return CURLcode CURLE_OK if everything is right.
*/
-void HTTPHelper::set_curl_auth(const string& username, const string& password)
+CURLcode HTTPHelper::set_curl_auth(const string& username, const string& password)
{
- if ( CurlEasyHandle != NULL )
+ if ( (CurlEasyHandle != NULL) && (CurlError == CURLE_OK) )
{
- curl_easy_setopt(CurlEasyHandle,CURLOPT_USERNAME,username.c_str());
- curl_easy_setopt(CurlEasyHandle,CURLOPT_PASSWORD,password.c_str());
+ CurlError = curl_easy_setopt(CurlEasyHandle,CURLOPT_USERNAME,username.c_str());
+ if ( CurlError != CURLE_OK )
+ Log->print_curl_error_init("Could not set CURL username properly.",CurlError);
+ CurlError = curl_easy_setopt(CurlEasyHandle,CURLOPT_PASSWORD,password.c_str());
+ if ( CurlError != CURLE_OK )
+ Log->print_curl_error_init("Could not set CURL password properly.",CurlError);
}
+ return CurlError;
}
std::string ReceivedCurlData;
char CurlErrBuff[CURL_ERROR_SIZE];
- void set_curl_url(const std::string& url);
- void set_curl_auth(const std::string& username, const std::string& password);
+ CURLcode set_curl_url(const std::string& url);
+ CURLcode set_curl_auth(const std::string& username, const std::string& password);
CURL* init_curl(std::string& curl_writedata_buff, char* curl_err_buff);
public:
time_t current_time = time(NULL);
// Test if webcheck is allowed due to webcheck_interval.
- if ( (LastWebcheck + (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 );
// Set URL
actual_url = url_list.front();
url_list.pop_front();
- set_curl_url(curl_easy_handle,actual_url);
-
- // Perform curl operation, err_code of 1 indicated connection problem, so try next url.
- curl_err_code = perform_curl_operation(curl_easy_handle, curl_err_buff, actual_url);
+ if (set_curl_url(curl_easy_handle,actual_url) == CURLE_OK )
+ {
+ // Perform curl operation, err_code of 1 indicated connection problem, so try next url.
+ curl_err_code = perform_curl_operation(curl_easy_handle, curl_err_buff, actual_url);
+ }
}
// Cleanup CURL handle
* Sets a url to the easy curl handle
* @param curl_easy_handle The easy curl handle to set the url for.
* @param url The url to set.
+ * @return CURLcode Curl Error code, CURLE_OK if everything is right.
*/
-void IPAddrHelper::set_curl_url(CURL * curl_easy_handle, const string& url) const
+CURLcode IPAddrHelper::set_curl_url(CURL * curl_easy_handle, const string& url) const
{
- curl_easy_setopt(curl_easy_handle,CURLOPT_URL,url.c_str());
+ CURLcode curl_error = CURLE_OK;
+
+ if ( curl_easy_handle != NULL )
+ {
+ curl_error = curl_easy_setopt(curl_easy_handle,CURLOPT_URL,url.c_str());
+ if ( curl_error != CURLE_OK )
+ {
+ // Some options could not be set, so destroy the CURL handle.
+ Log->print_curl_error_init("Could not set CURL URL properly.",curl_error);
+ }
+ }
+ return curl_error;
}
std::string WebcheckIpUrl;
std::string WebcheckIpUrlAlt;
int WebcheckInterval;
- int LastWebcheck;
+ time_t LastWebcheck;
std::string Proxy;
int ProxyPort;
bool UseIPv6;
CURL * init_curl(std::string& curl_writedata_buff, char* curl_err_buff) const;
int perform_curl_operation(CURL * curl_easy_handle, const char* curl_err_buff, const std::string& actual_url) const;
std::string parse_ipv4(const std::string& data) const;
+ CURLcode set_curl_url(CURL * curl_easy_handle, const std::string& url) const;
public:
// libcurl is a C library, so we have to make the callback member function static :-(
static size_t http_receive(const 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;
};
* @param msg The error message
* @param curl_err_code The resulting curl error code
*/
-void Logger::print_curl_error_init(const std::string& msg, const CURLcode curl_err_code) const
+void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
{
string curl_err = "";
if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
{
ostringstream msg;
- msg << "Curl error: " << msg << " Curl error code: " << curl_err_code << " "<< curl_err << endl;
+ msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " "<< curl_err << endl; // lint !e 641
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;
+ msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << endl; // lint !e 641
log_warning(msg.str(),level);
}
}
* @param curl_err_code The resulting curl error code
* @param curl_err_buff The curl error buffer
*/
-void Logger::print_curl_error(const string& url, const int curl_err_code, const char * curl_err_buff) const
+void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
{
string curl_err = "";
- if ( curl_err_code == 3 )
+ if ( curl_err_code == CURLE_URL_MALFORMAT )
curl_err = "CURLE_URL_MALFORMAT";
- else if ( curl_err_code == 6 )
+ else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
curl_err = "CURLE_COULDNT_RESOLVE_HOST";
- else if ( curl_err_code == 7 )
+ else if ( curl_err_code == CURLE_COULDNT_CONNECT )
curl_err = "CURLE_COULDNT_CONNECT";
else
curl_err = "UNKNOWN";
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;
+ msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " "<< curl_err << " " << curl_err_buff << endl; // lint !e 641
log_warning(msg.str(),level);
}
}
* @param webcheck_interval Webcheck interval time.
* @param current_time Current system time.
*/
-void Logger::print_webcheck_exceed_interval( const int last_webcheck, const int webcheck_interval, const time_t current_time ) const
+void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
{
int level = 0;
if ( level <= Loglevel )
* @param current_time Current time
* @param lastupdated Last updated
*/
-void Logger::print_check_service_update(const string& hostname, const int current_time, const int lastupdated) const
+void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
{
int level = 1;
if ( level <= Loglevel )
void print_no_domain_part(const std::string& hostname) const;
- void print_curl_error_init(const std::string& msg, const CURLcode curl_err_code) const;
+ void print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const;
void print_curl_error(const std::string& url, const CURLcode curl_err_code) const;
- void print_curl_error(const std::string& url, const int curl_err_code, const char * curl_err_buff) const;
+ void print_curl_error(const std::string& url, const CURLcode curl_err_code, const char * curl_err_buff) const;
void print_curl_data(const std::string& curl_writedata_buff) const;
void print_error_parsing_cmd(const std::string& error) const;
- void print_webcheck_exceed_interval( const int last_webcheck, const int webcheck_interval, const time_t current_time ) const;
+ void print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const;
- void print_check_service_update(const std::string& hostname, const int current_time, const int lastupdated) const;
+ void print_check_service_update(const std::string& hostname, const time_t current_time, const time_t lastupdated) const;
void print_cached_dns_entry(const std::string& hostname, const std::string& ip_dns_recheck, const std::string& ip_last_update, const std::string& ip_host) const;
if ( kill(pid,SIGTERM) != 0 )
{
updater->get_logger()->print_error_kill_child(pid);
- shutdown_parent(false,-1); // keep pidfile
+ shutdown_parent(false,-1); // lint !e 534 // keep pidfile
}
else
{
updater->get_logger()->print_child_killed(pid);
- shutdown_parent(true,-1); // remove pidfile
+ shutdown_parent(true,-1); // lint !e 534 // remove pidfile
}
}
updater->get_logger()->print_runnig_as_daemon(pid);
- shutdown_parent(false,0); // keep pidfile
+ shutdown_parent(false,0); // lint !e 534 // keep pidfile
}
// child starts here
}
{
if ( write_pidfile(getpid()) != 0 )
{
- shutdown();
+ shutdown(); // lint !e 534
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);
+ sleep(10); // lint !e 534
}while ( updater->get_config()->get_daemon_mode() == 1 );
* Getter for member Lastupdated.
* @return Value of member Lastupdated.
*/
-list<time_t> Service::get_last_updates() const
+const list<time_t> Service::get_last_updates() const
{
return LastUpdates;
}
for (iter = LastUpdates.begin(); (iter != LastUpdates.end()) && ( i < MaxUpdatesWithinInterval ); iter++)
{
- if ( (i == (MaxUpdatesWithinInterval-1)) && ( (*iter + (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;
std::string get_password() const;
void set_last_updates(std::list<time_t> _last_updates);
- std::list<time_t> get_last_updates() const;
+ const std::list<time_t> get_last_updates() const;
void set_actual_ip(const std::string& _actual_ip);
std::string get_actual_ip() const;
// 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()));
+ response.insert(pair<string,string>("salt",matches[1].str())); // lint !e 534
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()));
+ response.insert(pair<string,string>("time",matches[1].str())); // lint !e 534
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()));
+ response.insert(pair<string,string>("sign",matches[1].str())); // lint !e 534
get_logger()->print_regex_match(expr_salt.str(),matches[1].str());
}
else
{
pw_md5_hex = Util::compute_md5_digest(get_password());
}
- catch ( invalid_argument& e )
+ catch ( exception& e )
{
get_logger()->print_exception_md5_sum(e.what());
return -1;
}
+ catch ( ... )
+ {
+ get_logger()->print_exception_md5_sum("Unknown exception");
+ return -1;
+ }
// append "." and salt and compute md5 sum and get the HEX representation
pw_md5_hex.append(".");
{
secret = Util::compute_md5_digest(pw_md5_hex);
}
- catch ( invalid_argument& e )
+ catch ( exception& e )
{
get_logger()->print_exception_md5_sum(e.what());
return -1;
}
+ catch ( ... )
+ {
+ get_logger()->print_exception_md5_sum("Unknown exception");
+ return -1;
+ }
// Now its time to issue the second http_get operation
string url = assemble_update_url(salt, sign_time, sign, secret, ip);
#include "net_helper.h"
#include "util.h"
-#include <time.h>
-
using namespace std;
// Receive the server greeting.
string server_greeting = connection->receive_data();
if ( server_greeting.empty() )
+ {
+ connection->close_connection();
return -1;
+ }
// Send login command
ostringstream login;
login << "LOGIN " << get_login() << " " << get_password() << endl;
- if (connection->send_data(login.str()))
+ if (connection->send_data(login.str()) != 0)
+ {
+ connection->close_connection();
return -1;
+ }
// Receive login reply
string login_reply = connection->receive_data();
if ( login_reply.empty() )
+ {
+ connection->close_connection();
return -1;
+ }
else
{
// Get the return code out of the received data
// Successfully loged in, status_code should be 225
// Perform delete operation until there is no RR or we have performed it 10 times.
- int count = 0;
+ int del_count = 0;
string delete_reply, reply_code;
ostringstream delete_request;
delete_request << "DELRR " << get_hostname() << " A " << endl;
do
{
// Send delete request
- if (connection->send_data(delete_request.str()))
+ if (connection->send_data(delete_request.str()) != 0)
+ {
+ connection->close_connection();
return -1;
+ }
// Get delete reply
delete_reply = connection->receive_data();
if ( delete_reply.empty() )
+ {
+ connection->close_connection();
return -1;
- count++;
+ }
+ del_count++;
reply_code = Util::parse_status_code(delete_reply);
- }while ( (count < 10) && (reply_code != "300") );
+ }while ( (del_count < 10) && (reply_code != "300") );
// Send update request
ostringstream update_request;
update_request << "ADDRR " << get_hostname() << " A " << ip << endl;
- if (connection->send_data(update_request.str()))
+ if (connection->send_data(update_request.str()) != 0)
+ {
+ connection->close_connection();
return -1;
+ }
// Receive update request server reply
string update_reply = connection->receive_data();
if ( update_reply.empty() )
+ {
+ connection->close_connection();
return -1;
+ }
else
{
// Get the return code out of the received data
* This function serializes all Service objects in Services and OldServices (where the update Timeout isn't expired) into a specified file.
* @return 0 if all is fine, -1 if output file could not be opened for reading or error while serializing.
*/
-int Serviceholder::serialize_services()
+int Serviceholder::serialize_services() const
{
// Put Services and OldServices into Serviceholder.
SerializeServiceContainer::Ptr service_container(new SerializeServiceContainer);
- BOOST_FOREACH(Service::Ptr &service, Services)
+ BOOST_FOREACH(const Service::Ptr &service, Services)
{
service_container->add_service(service);
}
time_t current_time = time(NULL);
- BOOST_FOREACH(Service::Ptr &service, OldServices)
+ BOOST_FOREACH(const 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() + ((time_t)(service->get_update_interval()*60) )) >= current_time ) // UpdateInterval timeout of service isn't expired.
service_container->add_service(service);
}
int deserialize_services();
- int serialize_services();
+ int serialize_services() const;
void delete_services();
void TCPService::connect(const std::string& _host, const std::string& _port) throw (boost::system::system_error)
{
// Init boost::system::error_code
- boost::system::error_code error_code;
+ boost::system::error_code err_code;
// Create service object. The IO_Service has to be a member
//boost::asio::io_service io_service;
// Init DNS query object
- boost::asio::ip::tcp::resolver resolver(IOService);
- boost::asio::ip::tcp::resolver::query query(_host, _port);
- boost::asio::ip::tcp::resolver::iterator end;
+ boost::asio::ip::tcp::resolver service_resolver(IOService);
+ boost::asio::ip::tcp::resolver::query dns_query(_host, _port);
+ boost::asio::ip::tcp::resolver::iterator end_iter;
// Perform the DNS query
- boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error_code);
- if ( error_code )
- throw boost::system::system_error(error_code);
+ boost::asio::ip::tcp::resolver::iterator endpoint_iterator = service_resolver.resolve(dns_query, err_code);
+ if ( err_code )
+ throw boost::system::system_error(err_code);
// Init ssl context for service object
boost::asio::ssl::context ctx(IOService, boost::asio::ssl::context::sslv23);
Socket = SocketPtr(new SSLStream(IOService,ctx));
// Try to connect the Socket through all available endpoints
- if (endpoint_iterator != end)
+ if (endpoint_iterator != end_iter)
{
do
{
Socket->lowest_layer().close();
- Socket->lowest_layer().connect(*endpoint_iterator++, error_code);
- } while ( error_code && (endpoint_iterator != end) );
+ Socket->lowest_layer().connect(*endpoint_iterator++, err_code);
+ } while ( err_code && (endpoint_iterator != end_iter) );
}
- if ( error_code )
- throw boost::system::system_error(error_code);
+ if ( err_code )
+ throw boost::system::system_error(err_code);
// Perform SSL handshake
- Socket->handshake(boost::asio::ssl::stream_base::client,error_code);
- if ( error_code )
- throw boost::system::system_error(error_code);
+ Socket->handshake(boost::asio::ssl::stream_base::client,err_code);
+ if ( err_code )
+ throw boost::system::system_error(err_code);
return;
}
// Do not limit the receive buffer size for reusability. By default, max_size == 18446744073709551615
boost::asio::streambuf stream_buffer;
- // Init bytes_read and the error_code
- unsigned int bytes_read = 0;
+ // Init error_code
boost::system::error_code error_code;
// Is blocking until all available data was read or buffer is full
- bytes_read = boost::asio::read(*Socket.get(),stream_buffer,boost::asio::transfer_at_least(1),error_code);
+ size_t bytes_read = boost::asio::read(*Socket.get(),stream_buffer,boost::asio::transfer_at_least(1),error_code);
if ( error_code == boost::asio::error::eof )
throw boost::system::system_error(boost::system::error_code(ECONNABORTED,boost::system::system_category),"Connection closed by peer.");
else if (error_code)
void TCPService::write_to_socket(const string& data) throw (boost::system::system_error)
{
// Get the data size which will be written
- unsigned int data_size = data.size();
+ size_t data_size = data.size();
// Init stream_buffer with data
boost::asio::streambuf stream_buffer(data_size);
request_stream << data;
// Init bytes_read and the error_code
- unsigned int bytes_wrote = 0;
+ size_t bytes_wrote = 0;
boost::system::error_code error_code;
bytes_wrote = boost::asio::write(*Socket.get(), stream_buffer, boost::asio::transfer_at_least(data_size), error_code);
/**
* Initialize the logging facility with loglevel and syslog.
*/
-void Updater::init_log_facility()
+void Updater::init_log_facility() const
{
Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog(),Conf->get_external_warning_log(),Conf->get_external_warning_level());
Log->print_init_log_facility();
/**
* Update all configured services.
*/
-void Updater::update_services()
+void Updater::update_services() const
{
// Get all services from the ServiceHolder.
list<Service::Ptr> services = ServiceHolder->get_services();
{
string ip_last_update = service->get_actual_ip();
string hostname = service->get_hostname();
- int lastupdated = 0;
- int current_time = time(NULL);
+ time_t lastupdated = 0;
+ time_t current_time = time(NULL);
// Try to get the lastupdated time of the actual service if there is one.
if ( service->get_last_updates().size() > 0 )
~Updater();
- void update_services();
+ void update_services() const;
int init_config_from_cmd(int argc, char *argv[]);
int init_helper_classes();
- void init_log_facility();
+ void init_log_facility() const;
int init_ip_helper();
* @param data The string to compute the md5 for
* @return The computed md5 in hex
*/
-std::string compute_md5_digest(std::string data) throw (std::invalid_argument)
+std::string compute_md5_digest(std::string data)
{
// compute an MD5 digest.
EVP_MD_CTX_init(&mdctx);
// Now we can call init_ex.
- EVP_DigestInit_ex(&mdctx, md, NULL);
+ if ( EVP_DigestInit_ex(&mdctx, md, NULL) == 0 )
+ {
+ EVP_MD_CTX_cleanup(&mdctx);
+ EVP_cleanup();
+ 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();
throw std::invalid_argument("Passed data is empty");
+ }
// Hash the data. At this point data is not empty and &mdctx is initialized.
- EVP_DigestUpdate(&mdctx, data.c_str(), data.size());
+ if ( EVP_DigestUpdate(&mdctx, data.c_str(), data.size()) == 0 )
+ {
+ EVP_MD_CTX_cleanup(&mdctx);
+ EVP_cleanup();
+ throw std::invalid_argument("Could not hash data into digest context");
+ }
// Retrieve the digest value from &mdctx and place it in md_value.
- EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
+ if ( EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0 )
+ {
+ EVP_MD_CTX_cleanup(&mdctx);
+ EVP_cleanup();
+ 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();
throw std::invalid_argument("Retrieved invalid digest value");
+ }
// Internal cleanup of the digest content.
EVP_MD_CTX_cleanup(&mdctx);
{
std::list<std::string> tokens;
boost::algorithm::split(tokens,data,boost::is_any_of(" "));
+ if ( tokens.empty() )
+ return "";
return tokens.front();
}
namespace Util
{
- std::string compute_md5_digest(std::string data) throw (std::invalid_argument);
+ std::string compute_md5_digest(std::string data);
std::string parse_status_code(std::string data);
std::string parse_status_code(std::string data, std::string delimiter);
}