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 ddb0559 commit 639b314
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,33 @@ data_connection_ptr client::process_eprt_command(std::string_view command, repli
return connection;
}

std::string client::make_eprt_command(const boost::asio::ip::tcp::endpoint & endpoint)
{
std::string command = "EPRT";
command.append(" ");
command.append("|");

if (endpoint.address().is_v4())
{
command.append("1");
}
else if (endpoint.address().is_v6())
{
command.append("2");
}
else
{
throw ftp_exception("Cannot make the EPRT command. The IP address type is invalid.");
}

command.append("|");
command.append(net_utils::address_to_string(endpoint.address()));
command.append("|");
command.append(std::to_string(endpoint.port()));
command.append("|");
return command;
}

data_connection_ptr client::process_pasv_command(std::string_view command, replies & replies)
{
std::string pasv_command = make_command("PASV");
Expand Down Expand Up @@ -820,46 +847,6 @@ data_connection_ptr client::process_port_command(std::string_view command, repli
return connection;
}

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

if (argument)
{
result.append(" ");
result.append(argument.value());
}

return result;
}

std::string client::make_eprt_command(const boost::asio::ip::tcp::endpoint & endpoint)
{
std::string command = "EPRT";
command.append(" ");
command.append("|");

if (endpoint.address().is_v4())
{
command.append("1");
}
else if (endpoint.address().is_v6())
{
command.append("2");
}
else
{
throw ftp_exception("Cannot make the EPRT command. The IP address type is invalid.");
}

command.append("|");
command.append(net_utils::address_to_string(endpoint.address()));
command.append("|");
command.append(std::to_string(endpoint.port()));
command.append("|");
return command;
}

std::string client::make_port_command(const boost::asio::ip::tcp::endpoint & endpoint)
{
std::string command = "PORT";
Expand All @@ -884,6 +871,19 @@ std::string client::make_port_command(const boost::asio::ip::tcp::endpoint & end
return command;
}

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

if (argument)
{
result.append(" ");
result.append(argument.value());
}

return result;
}

std::string client::make_type_command(transfer_type type)
{
if (type == transfer_type::binary)
Expand Down

0 comments on commit 639b314

Please sign in to comment.