Skip to content

Commit

Permalink
refactor: reorder methods
Browse files Browse the repository at this point in the history
No functional changes.
  • Loading branch information
deniskovalchuk committed Oct 2, 2023
1 parent 8e816cd commit ddb0559
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,35 +722,6 @@ data_connection_ptr client::process_pasv_command(std::string_view command, repli
return connection;
}

data_connection_ptr client::process_port_command(std::string_view command, replies & replies)
{
boost::asio::ip::tcp::endpoint local_endpoint = control_connection_.get_local_endpoint();
boost::asio::ip::tcp::endpoint listen_endpoint(local_endpoint.address(), 0);

data_connection_ptr connection = std::make_unique<data_connection>();
connection->listen(listen_endpoint);
listen_endpoint = connection->get_listen_endpoint();

std::string port_command = make_port_command(listen_endpoint);

reply reply = process_command(port_command, replies);

if (reply.is_negative())
{
return nullptr;
}

reply = process_command(command, replies);

if (reply.is_negative())
{
return nullptr;
}

connection->accept();
return connection;
}

/* This address information is broken into 8-bit fields and the
* value of each field is transmitted as a decimal number (in
* character string representation). The fields are separated
Expand Down Expand Up @@ -820,6 +791,35 @@ bool client::try_parse_pasv_reply(const reply & reply, std::string & ip, uint16_
return true;
}

data_connection_ptr client::process_port_command(std::string_view command, replies & replies)
{
boost::asio::ip::tcp::endpoint local_endpoint = control_connection_.get_local_endpoint();
boost::asio::ip::tcp::endpoint listen_endpoint(local_endpoint.address(), 0);

data_connection_ptr connection = std::make_unique<data_connection>();
connection->listen(listen_endpoint);
listen_endpoint = connection->get_listen_endpoint();

std::string port_command = make_port_command(listen_endpoint);

reply reply = process_command(port_command, replies);

if (reply.is_negative())
{
return nullptr;
}

reply = process_command(command, replies);

if (reply.is_negative())
{
return nullptr;
}

connection->accept();
return connection;
}

std::string client::make_command(std::string_view command, const std::optional<std::string_view> & argument)
{
std::string result(command);
Expand Down

0 comments on commit ddb0559

Please sign in to comment.