Skip to content
Snippets Groups Projects
Commit c41153fb authored by Marco De Marco's avatar Marco De Marco
Browse files

Remote endpoint added to protocol manager

parent 7cd4071a
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ PlainSession::~PlainSession() ...@@ -26,7 +26,7 @@ PlainSession::~PlainSession()
DEBUG_STREAM << "PlainSession::~PlainSession()" << endl; DEBUG_STREAM << "PlainSession::~PlainSession()" << endl;
INFO_STREAM << "PlainSession::~PlainSession() Disconnection from " INFO_STREAM << "PlainSession::~PlainSession() Disconnection from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
boost::system::error_code errorCode; boost::system::error_code errorCode;
...@@ -65,11 +65,13 @@ void PlainSession::start() ...@@ -65,11 +65,13 @@ void PlainSession::start()
{ {
DEBUG_STREAM << "PlainSession::start()" << endl; DEBUG_STREAM << "PlainSession::start()" << endl;
remoteEndpoint = boost::lexical_cast<std::string>( m_remoteEndpoint = boost::lexical_cast<std::string>(
m_plainSocket.remote_endpoint()); m_plainSocket.remote_endpoint());
INFO_STREAM << "PlainSession::start() Connection from " INFO_STREAM << "PlainSession::start() Connection from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
m_protocolManager_sp->setRemoteEndpoint(m_remoteEndpoint);
startReadRequestHeader(); startReadRequestHeader();
} }
...@@ -102,7 +104,7 @@ void PlainSession::startReadRequestBody(boost::uint32_t bodySize) ...@@ -102,7 +104,7 @@ void PlainSession::startReadRequestBody(boost::uint32_t bodySize)
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
INFO_STREAM << "PlainSession::startReadRequestBody() " INFO_STREAM << "PlainSession::startReadRequestBody() "
<< remoteEndpoint << " >>>> " << bodySize << " BYTE" << endl; << m_remoteEndpoint << " >>>> " << bodySize << " BYTE" << endl;
#endif #endif
boost::asio::async_read(m_plainSocket, mutableBuffer, boost::asio::async_read(m_plainSocket, mutableBuffer,
...@@ -136,7 +138,7 @@ void PlainSession::startWriteResponse() ...@@ -136,7 +138,7 @@ void PlainSession::startWriteResponse()
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
INFO_STREAM << "PlainSession::startWriteResponse() " INFO_STREAM << "PlainSession::startWriteResponse() "
<< remoteEndpoint << " <<<< " << bodySize << " byte" << endl; << m_remoteEndpoint << " <<<< " << bodySize << " byte" << endl;
#endif #endif
boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff), boost::asio::async_write(m_plainSocket, boost::asio::buffer(writeBuff),
...@@ -146,12 +148,12 @@ void PlainSession::startWriteResponse() ...@@ -146,12 +148,12 @@ void PlainSession::startWriteResponse()
catch(std::runtime_error& ec) catch(std::runtime_error& ec)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() " ERROR_STREAM << "SSLSession::startWriteResponse() "
<< ec.what() << " from " << remoteEndpoint << endl; << ec.what() << " from " << m_remoteEndpoint << endl;
} }
catch(...) catch(...)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
} }
} }
......
...@@ -37,6 +37,16 @@ ProtocolManager::SP ProtocolManager::create(Tango::DeviceImpl* deviceImpl_p, ...@@ -37,6 +37,16 @@ ProtocolManager::SP ProtocolManager::create(Tango::DeviceImpl* deviceImpl_p,
return d_sp; return d_sp;
} }
//==============================================================================
// ProtocolManager::ProtocolManager()
//==============================================================================
void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint)
{
DEBUG_STREAM << "ProtocolManager::setRemoteEndpoint()" << endl;
m_remoteEndpoint = remoteEndpoint;
}
//============================================================================== //==============================================================================
// ProtocolManager::prepareResponse() // ProtocolManager::prepareResponse()
//============================================================================== //==============================================================================
...@@ -97,7 +107,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -97,7 +107,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
if(m_configuration_sp->isUserAuthorized(username, password)) if(m_configuration_sp->isUserAuthorized(username, password))
{ {
INFO_STREAM << "ProtocolManager::prepareAuthroisation() " INFO_STREAM << "ProtocolManager::prepareAuthroisation() "
<< "Authorization accepted" << endl; << "Authorization accepted from " << m_remoteEndpoint << endl;
m_isAuthorised = true; m_isAuthorised = true;
...@@ -107,7 +117,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -107,7 +117,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
else else
{ {
WARN_STREAM << "ProtocolManager::prepareAuthroisation() " WARN_STREAM << "ProtocolManager::prepareAuthroisation() "
<< "Invalid username or password" << endl; << "Invalid username or password from " << m_remoteEndpoint << endl;
m_isAuthorised = false; m_isAuthorised = false;
...@@ -118,7 +128,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) ...@@ -118,7 +128,7 @@ ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp)
else else
{ {
WARN_STREAM << "ProtocolManager::prepareAuthroisation() " WARN_STREAM << "ProtocolManager::prepareAuthroisation() "
<< "Already authorized" << endl; << "Already authorized from " << m_remoteEndpoint << endl;
auth_resp->set_state(Response::Authorization::REJECTED); auth_resp->set_state(Response::Authorization::REJECTED);
auth_resp->set_status("Already authorized"); auth_resp->set_status("Already authorized");
...@@ -167,6 +177,9 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) ...@@ -167,6 +177,9 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp)
for(it=columns.begin(); it!=columns.end(); ++it) for(it=columns.begin(); it!=columns.end(); ++it)
validateColumn(*it, informationList); validateColumn(*it, informationList);
INFO_STREAM << "ProtocolManager::prepareValidation() "
<< "Validation accepted from " << m_remoteEndpoint << endl;
m_isValidated = true; m_isValidated = true;
validationRes->set_state(Response::Validation::ACCEPTED); validationRes->set_state(Response::Validation::ACCEPTED);
...@@ -181,7 +194,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) ...@@ -181,7 +194,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp)
else else
{ {
WARN_STREAM << "ProtocolManager::prepareValidation() " WARN_STREAM << "ProtocolManager::prepareValidation() "
<< "Already validated" << endl; << "Already validated from " << m_remoteEndpoint << endl;
validationRes->set_state(Response::Validation::REJECTED); validationRes->set_state(Response::Validation::REJECTED);
validationRes->set_status("Already validated"); validationRes->set_status("Already validated");
...@@ -190,7 +203,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) ...@@ -190,7 +203,7 @@ ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp)
else else
{ {
WARN_STREAM << "ProtocolManager::prepareValidation() " WARN_STREAM << "ProtocolManager::prepareValidation() "
<< "Not authorised" << endl; << "Not authorised from " << m_remoteEndpoint << endl;
validationRes->set_state(Response::Validation::REJECTED); validationRes->set_state(Response::Validation::REJECTED);
validationRes->set_status("Not authorised"); validationRes->set_status("Not authorised");
......
...@@ -48,6 +48,11 @@ public: ...@@ -48,6 +48,11 @@ public:
static ProtocolManager::SP create(Tango::DeviceImpl*, Configuration::SP, static ProtocolManager::SP create(Tango::DeviceImpl*, Configuration::SP,
DBManager::SP); DBManager::SP);
//------------------------------------------------------------------------------
// [Public] Remote endpoint setter method
//------------------------------------------------------------------------------
void setRemoteEndpoint(std::string);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] Request response management method // [Public] Request response management method
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -87,6 +92,9 @@ protected: ...@@ -87,6 +92,9 @@ protected:
//Table structure is validated //Table structure is validated
bool m_isValidated; bool m_isValidated;
//Address and port of remote endpoint
std::string m_remoteEndpoint;
}; };
} //End of namespace } //End of namespace
......
...@@ -29,9 +29,9 @@ SSLServer::SSLServer(Tango::DeviceImpl* deviceImpl_p, ...@@ -29,9 +29,9 @@ SSLServer::SSLServer(Tango::DeviceImpl* deviceImpl_p,
std::string privateKey = m_configuration_sp->getPrivateKeyFile(); std::string privateKey = m_configuration_sp->getPrivateKeyFile();
std::string dHTempFile = m_configuration_sp->getDHTempFile(); std::string dHTempFile = m_configuration_sp->getDHTempFile();
INFO_STREAM << "CERTIFICATE FILE: " << certificateFile << endl; INFO_STREAM << "SSLServer::SSLServer() Certificate " << certificateFile << endl;
INFO_STREAM << "PRIVATE KEY FILE: " << privateKey << endl; INFO_STREAM << "SSLServer::SSLServer() Private key " << privateKey << endl;
INFO_STREAM << "DH TEMPORARY FILE: " << dHTempFile << endl; INFO_STREAM << "SSLServer::SSLServer() DH Temporary " << dHTempFile << endl;
//@todo: check error_code use in load file methods //@todo: check error_code use in load file methods
m_context_sp->use_certificate_chain_file(certificateFile); m_context_sp->use_certificate_chain_file(certificateFile);
......
...@@ -27,7 +27,7 @@ SSLSession::~SSLSession() ...@@ -27,7 +27,7 @@ SSLSession::~SSLSession()
DEBUG_STREAM << "SSLSession::~SSLSession()" << endl; DEBUG_STREAM << "SSLSession::~SSLSession()" << endl;
INFO_STREAM << "SSLSession::~SSLSession() Disconnection from " INFO_STREAM << "SSLSession::~SSLSession() Disconnection from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
boost::system::error_code errorCode; boost::system::error_code errorCode;
...@@ -70,10 +70,13 @@ void SSLSession::start() ...@@ -70,10 +70,13 @@ void SSLSession::start()
{ {
DEBUG_STREAM << "SSLSession::start()" << endl; DEBUG_STREAM << "SSLSession::start()" << endl;
remoteEndpoint = boost::lexical_cast<std::string>( m_remoteEndpoint = boost::lexical_cast<std::string>(
m_sslSocket.lowest_layer().remote_endpoint()); m_sslSocket.lowest_layer().remote_endpoint());
INFO_STREAM << "SSLSession::start() Connection from " << remoteEndpoint << endl; INFO_STREAM << "SSLSession::start() Connection from "
<< m_remoteEndpoint << endl;
m_protocolManager_sp->setRemoteEndpoint(m_remoteEndpoint);
startHandShake(); startHandShake();
} }
...@@ -104,7 +107,7 @@ void SSLSession::handleHandShake(const boost::system::error_code& errorCode) ...@@ -104,7 +107,7 @@ void SSLSession::handleHandShake(const boost::system::error_code& errorCode)
else else
{ {
ERROR_STREAM << "SSLSession::handleHandShake() error " ERROR_STREAM << "SSLSession::handleHandShake() error "
<< errorCode.message() << " from " << remoteEndpoint << endl; << errorCode.message() << " from " << m_remoteEndpoint << endl;
} }
} }
...@@ -136,7 +139,7 @@ void SSLSession::startReadRequestBody(boost::uint32_t bodySize) ...@@ -136,7 +139,7 @@ void SSLSession::startReadRequestBody(boost::uint32_t bodySize)
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
INFO_STREAM << "SSLSession::startReadRequestBody() " INFO_STREAM << "SSLSession::startReadRequestBody() "
<< remoteEndpoint << " >>>> " << bodySize << " byte" << endl; << m_remoteEndpoint << " >>>> " << bodySize << " byte" << endl;
#endif #endif
boost::asio::async_read(m_sslSocket, mutableBuffer, boost::asio::async_read(m_sslSocket, mutableBuffer,
...@@ -171,7 +174,7 @@ void SSLSession::startWriteResponse() ...@@ -171,7 +174,7 @@ void SSLSession::startWriteResponse()
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
INFO_STREAM << "SSLSession::startWriteResponse() " INFO_STREAM << "SSLSession::startWriteResponse() "
<< remoteEndpoint << " <<<< " << bodySize << " byte" << endl; << m_remoteEndpoint << " <<<< " << bodySize << " byte" << endl;
#endif #endif
boost::asio::async_write(m_sslSocket, boost::asio::buffer(writeBuff), boost::asio::async_write(m_sslSocket, boost::asio::buffer(writeBuff),
...@@ -181,12 +184,12 @@ void SSLSession::startWriteResponse() ...@@ -181,12 +184,12 @@ void SSLSession::startWriteResponse()
catch(std::runtime_error& ec) catch(std::runtime_error& ec)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() " ERROR_STREAM << "SSLSession::startWriteResponse() "
<< ec.what() << " from " << remoteEndpoint << endl; << ec.what() << " from " << m_remoteEndpoint << endl;
} }
catch(...) catch(...)
{ {
ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from " ERROR_STREAM << "SSLSession::startWriteResponse() unknown error from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
} }
} }
......
...@@ -41,12 +41,12 @@ void Session::handleReadRequestHeader(const boost::system::error_code& errorCode ...@@ -41,12 +41,12 @@ void Session::handleReadRequestHeader(const boost::system::error_code& errorCode
else if(errorCode == boost::asio::error::eof) else if(errorCode == boost::asio::error::eof)
{ {
DEBUG_STREAM << "Session::handleReadRequestBody() end of file from " DEBUG_STREAM << "Session::handleReadRequestBody() end of file from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
} }
else else
{ {
ERROR_STREAM << "Session::handleReadRequestHeader() " ERROR_STREAM << "Session::handleReadRequestHeader() "
<< errorCode.message() << " from " << remoteEndpoint << endl; << errorCode.message() << " from " << m_remoteEndpoint << endl;
} }
} }
...@@ -64,12 +64,12 @@ void Session::handleReadRequestBody(const boost::system::error_code& errorCode) ...@@ -64,12 +64,12 @@ void Session::handleReadRequestBody(const boost::system::error_code& errorCode)
else if(errorCode == boost::asio::error::eof) else if(errorCode == boost::asio::error::eof)
{ {
DEBUG_STREAM << "Session::handleReadRequestBody() end of file from" DEBUG_STREAM << "Session::handleReadRequestBody() end of file from"
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
} }
else else
{ {
ERROR_STREAM << "Session::handleReadRequestBody() " ERROR_STREAM << "Session::handleReadRequestBody() "
<< errorCode.message() << " from " << remoteEndpoint << endl; << errorCode.message() << " from " << m_remoteEndpoint << endl;
} }
} }
...@@ -87,12 +87,12 @@ void Session::handleWriteResponse(const boost::system::error_code& errorCode) ...@@ -87,12 +87,12 @@ void Session::handleWriteResponse(const boost::system::error_code& errorCode)
else if(errorCode == boost::asio::error::eof) else if(errorCode == boost::asio::error::eof)
{ {
DEBUG_STREAM << "Session::handleWriteResponse() end of file from " DEBUG_STREAM << "Session::handleWriteResponse() end of file from "
<< remoteEndpoint << endl; << m_remoteEndpoint << endl;
} }
else else
{ {
ERROR_STREAM << "Session::handleWriteResponse() " ERROR_STREAM << "Session::handleWriteResponse() "
<< errorCode.message() << " from " << remoteEndpoint << endl; << errorCode.message() << " from " << m_remoteEndpoint << endl;
} }
} }
......
...@@ -91,7 +91,7 @@ protected: ...@@ -91,7 +91,7 @@ protected:
std::vector<boost::uint8_t> m_readBuff; std::vector<boost::uint8_t> m_readBuff;
//Address and port of remote endpoint //Address and port of remote endpoint
std::string remoteEndpoint; std::string m_remoteEndpoint;
}; };
} //End of namespace } //End of namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment