Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 3338 → Rev 3339

/branches/STF525/ccsrc/Protocols/Tcp/tcp_layer.cc
4,14 → 4,11
#include <errno.h>
#include <chrono>
 
using namespace std; // Required for isnan()
#include "Port.hh"
 
#include "tcp_layer_factory.hh"
 
#include "loggers.hh"
 
tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : SSL_Socket(), layer(p_type), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("tcp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} {
tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("tcp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} {
loggers::get_instance().log(">>> tcp_layer::tcp_layer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
params::convert(_params, param);
22,7 → 19,7
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("debug"), "0"));
} else if (it->second.compare("1") == 0) {
set_socket_debugging(true);
set_socket_debugging(true);
}
it = _params.find(params::server);
if (it == _params.cend()) {
31,13 → 28,6
if (!parameter_set(params::server.c_str(), _params[params::server].c_str())) {
loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::server.c_str());
}
it = _params.find(params::port);
if (it == _params.cend()) {
_params.insert(std::pair<std::string, std::string>(std::string("port"), "80"));
}
if (!parameter_set(params::port.c_str(), _params[params::port].c_str())) {
loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::server.c_str());
}
set_ssl_use_ssl(false);
it = _params.find(params::use_ssl);
if (it == _params.cend()) {
45,11 → 35,22
} else if (it->second.compare("1") == 0) {
set_ssl_use_ssl(true);
}
it = _params.find(params::port);
if (it == _params.cend()) {
if (_params[params::use_ssl].compare("0") == 0) { // Use standard HTTP port
_params.insert(std::pair<std::string, std::string>(std::string("port"), "80"));
} else { // Use standard HTTPS port
_params.insert(std::pair<std::string, std::string>(std::string("port"), "443"));
}
}
if (!parameter_set(params::port.c_str(), _params[params::port].c_str())) {
loggers::get_instance().warning("tcp_layer::set_parameter: Unprocessed parameter: %s", params::server.c_str());
}
 
parameter_set(use_connection_ASPs_name(), "yes");
parameter_set(server_backlog_name(), "1024");
set_server_mode(false);
set_ttcn_buffer_usercontrol(true);
set_ttcn_buffer_usercontrol(false);
set_handle_half_close(true);
 
map_user();
57,10 → 58,10
if (!_reconnect_on_send) {
open_client_connection(_params[params::server].c_str(), _params[params::port].c_str(), NULL, NULL);
}
}
}
 
tcp_layer::~tcp_layer() {
loggers::get_instance().log(">>> tcp_layer::~tcp_layer: %d", _client_id);
loggers::get_instance().log(">>> tcp_layer::~tcp_layer: %d", _client_id);
if (_client_id != -1) {
remove_client(_client_id);
}
117,13 → 118,13
 
bool tcp_layer::add_user_data(int p_client_id)
{
loggers::get_instance().log(">>> tcp_layer::add_user_data: %d", p_client_id);
if (_params[params::use_ssl].compare("0") == 0) {
loggers::get_instance().log("tcp_layer::add_user_data: Non secured mode");
return Abstract_Socket::add_user_data(p_client_id);
}
loggers::get_instance().log("tcp_layer::add_user_data: SSL mode");
return SSL_Socket::add_user_data(p_client_id);
loggers::get_instance().log(">>> tcp_layer::add_user_data: %d", p_client_id);
if (_params[params::use_ssl].compare("0") == 0) {
loggers::get_instance().log("tcp_layer::add_user_data: Non secured mode");
return Abstract_Socket::add_user_data(p_client_id);
}
loggers::get_instance().log("tcp_layer::add_user_data: SSL mode");
return SSL_Socket::add_user_data(p_client_id);
}
 
int tcp_layer::send_message_on_fd(int p_client_id, const unsigned char * message_buffer, int length_of_message)
130,14 → 131,14
{
loggers::get_instance().log(">>> tcp_layer::send_message_on_fd: %d", p_client_id);
 
if(get_user_data(p_client_id))
if(get_user_data(p_client_id))
{
loggers::get_instance().log("tcp_layer::send_message_on_fd: SSL mode");
return SSL_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message);
return SSL_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message);
}
 
loggers::get_instance().log("tcp_layer::send_message_on_fd: Non secured mode");
return Abstract_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message);
loggers::get_instance().log("tcp_layer::send_message_on_fd: Non secured mode");
return Abstract_Socket::send_message_on_fd(p_client_id, message_buffer, length_of_message);
}
 
int tcp_layer::send_message_on_nonblocking_fd(int p_client_id, const unsigned char * message_buffer, int length_of_message)
144,14 → 145,14
{
loggers::get_instance().log(">>> tcp_layer::send_message_on_nonblocking_fd: %d", p_client_id);
 
if(get_user_data(p_client_id))
if(get_user_data(p_client_id))
{
loggers::get_instance().log("tcp_layer::send_message_on_nonblocking_fd: SSL mode");
return SSL_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message);
return SSL_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message);
}
 
loggers::get_instance().log("tcp_layer::send_message_on_nonblocking_fd: Non secured mode");
return Abstract_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message);
loggers::get_instance().log("tcp_layer::send_message_on_nonblocking_fd: Non secured mode");
return Abstract_Socket::send_message_on_nonblocking_fd(p_client_id, message_buffer, length_of_message);
}
 
int tcp_layer::receive_message_on_fd(int p_client_id)
158,14 → 159,14
{
loggers::get_instance().log(">>> tcp_layer::receive_message_on_fd: %d", p_client_id);
 
if(get_user_data(p_client_id)) {
// INFO: it is assumed that only SSL_Socket assigns user data to each peer
loggers::get_instance().log("tcp_layer::receive_message_on_fd: SSL mode");
return SSL_Socket::receive_message_on_fd(p_client_id);
}
if(get_user_data(p_client_id)) {
// INFO: it is assumed that only SSL_Socket assigns user data to each peer
loggers::get_instance().log("tcp_layer::receive_message_on_fd: SSL mode");
return SSL_Socket::receive_message_on_fd(p_client_id);
}
 
loggers::get_instance().log("tcp_layer::receive_message_on_fd: Non secured mode");
return Abstract_Socket::receive_message_on_fd(p_client_id);
loggers::get_instance().log("tcp_layer::receive_message_on_fd: Non secured mode");
return Abstract_Socket::receive_message_on_fd(p_client_id);
}
 
void tcp_layer::peer_disconnected(int p_client_id)
172,7 → 173,7
{
loggers::get_instance().log(">>> tcp_layer::peer_disconnected: %d", p_client_id);
 
Abstract_Socket::peer_disconnected(p_client_id);
Abstract_Socket::peer_disconnected(p_client_id);
_client_id = -1;
}
 
/branches/STF525/ccsrc/Protocols/Tcp/tcp_layer.hh
10,7 → 10,7
*/
#pragma once
 
#include "t_layer.hh"
#include "layer.hh"
 
#include "Abstract_Socket.hh"
 
20,7 → 20,7
* \class tcp_layer
* \brief This class provides description of ITS TCP port protocol layer
*/
class tcp_layer : public SSL_Socket, public layer, public PORT {
class tcp_layer : public layer, public SSL_Socket, public PORT {
params _params; //! Layer parameters
int _client_id; //! Connection identifier
std::string _time_key; //! \todo