Skip to content

Commit

Permalink
redirect all output
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaharHD committed Dec 4, 2024
1 parent 1075764 commit 8586742
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions fineftp-server/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace Filesystem
hFind = FindFirstFileW(w_find_file_path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
std::cerr << "FindFirstFile Error" << std::endl;
error_ << "FindFirstFile Error" << std::endl;
return content;
}

Expand All @@ -312,7 +312,7 @@ namespace Filesystem
struct dirent *dirp = nullptr;
if(dp == nullptr)
{
std::cerr << "Error opening directory: " << strerror(errno) << std::endl;
error << "Error opening directory: " << strerror(errno) << std::endl;
return content;
}

Expand Down
26 changes: 13 additions & 13 deletions fineftp-server/src/ftp_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace fineftp
FtpSession::~FtpSession()
{
#ifndef NDEBUG
std::cout << "Ftp Session shutting down" << std::endl;
output_ << "Ftp Session shutting down" << std::endl;
#endif // !NDEBUG

{
Expand Down Expand Up @@ -87,7 +87,7 @@ namespace fineftp
{
asio::error_code ec;
command_socket_.set_option(asio::ip::tcp::no_delay(true), ec);
if (ec) std::cerr << "Unable to set socket option tcp::no_delay: " << ec.message() << std::endl;
if (ec) error_ << "Unable to set socket option tcp::no_delay: " << ec.message() << std::endl;

command_strand_.post([me = shared_from_this()]() { me->readFtpCommand(); });
sendFtpMessage(FtpMessage(FtpReplyCode::SERVICE_READY_FOR_NEW_USER, "Welcome to fineFTP Server"));
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace fineftp
void FtpSession::startSendingMessages()
{
#ifndef NDEBUG
std::cout << "FTP >> " << command_output_queue_.front() << std::endl;
output_ << "FTP >> " << command_output_queue_.front() << std::endl;
#endif

asio::async_write(command_socket_
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace fineftp
}
else
{
std::cerr << "Command write error for message " << me->command_output_queue_.front() << ec.message() << std::endl;
me->error_ << "Command write error for message " << me->command_output_queue_.front() << ec.message() << std::endl;
}
}
));
Expand All @@ -167,12 +167,12 @@ namespace fineftp
{
if (ec != asio::error::eof)
{
std::cerr << "read_until error: " << ec.message() << std::endl;
me->error_ << "read_until error: " << ec.message() << std::endl;
}
#ifndef NDEBUG
else
{
std::cout << "Control connection closed by client." << std::endl;
me->output_ << "Control connection closed by client." << std::endl;
}
#endif // !NDEBUG
// Close the data connection, if it is open
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace fineftp

stream.ignore(2); // Remove the "\r\n"
#ifndef NDEBUG
std::cout << "FTP << " << packet_string << std::endl;
me->output_ << "FTP << " << packet_string << std::endl;
#endif

me->handleFtpCommand(packet_string);
Expand Down Expand Up @@ -414,7 +414,7 @@ namespace fineftp
data_acceptor_.close(ec);
if (ec)
{
std::cerr << "Error closing data acceptor: " << ec.message() << std::endl;
error_ << "Error closing data acceptor: " << ec.message() << std::endl;
}
}

Expand All @@ -425,7 +425,7 @@ namespace fineftp
data_acceptor_.open(endpoint.protocol(), ec);
if (ec)
{
std::cerr << "Error opening data acceptor: " << ec.message() << std::endl;
error_ << "Error opening data acceptor: " << ec.message() << std::endl;
sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode.");
return;
}
Expand All @@ -435,7 +435,7 @@ namespace fineftp
data_acceptor_.bind(endpoint, ec);
if (ec)
{
std::cerr << "Error binding data acceptor: " << ec.message() << std::endl;
error_ << "Error binding data acceptor: " << ec.message() << std::endl;
sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode.");
return;
}
Expand All @@ -445,7 +445,7 @@ namespace fineftp
data_acceptor_.listen(asio::socket_base::max_connections, ec);
if (ec)
{
std::cerr << "Error listening on data acceptor: " << ec.message() << std::endl;
error_ << "Error listening on data acceptor: " << ec.message() << std::endl;
sendFtpMessage(FtpReplyCode::SERVICE_NOT_AVAILABLE, "Failed to enter passive mode.");
return;
}
Expand Down Expand Up @@ -1376,7 +1376,7 @@ namespace fineftp

if (ec)
{
std::cerr << "Data write error: " << ec.message() << std::endl;
me->error_ << "Data write error: " << ec.message() << std::endl;
return;
}

Expand Down Expand Up @@ -1417,7 +1417,7 @@ namespace fineftp
{
if (ec)
{
std::cerr << "Data transfer aborted: " << ec.message() << std::endl;
me->error_ << "Data transfer aborted: " << ec.message() << std::endl;
me->sendFtpMessage(FtpReplyCode::TRANSFER_ABORTED, "Data transfer aborted");
return;
}
Expand Down
16 changes: 8 additions & 8 deletions fineftp-server/src/server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace fineftp
const asio::ip::tcp::endpoint endpoint(asio::ip::make_address(address_, make_address_ec), port_);
if (make_address_ec)
{
std::cerr << "Error creating address from string \"" << address_<< "\": " << make_address_ec.message() << std::endl;
error_ << "Error creating address from string \"" << address_<< "\": " << make_address_ec.message() << std::endl;
return false;
}

Expand All @@ -59,7 +59,7 @@ namespace fineftp
acceptor_.open(endpoint.protocol(), ec);
if (ec)
{
std::cerr << "Error opening acceptor: " << ec.message() << std::endl;
error_ << "Error opening acceptor: " << ec.message() << std::endl;
return false;
}
}
Expand All @@ -69,7 +69,7 @@ namespace fineftp
acceptor_.set_option(asio::ip::tcp::acceptor::reuse_address(true), ec);
if (ec)
{
std::cerr << "Error setting reuse_address option: " << ec.message() << std::endl;
error_ << "Error setting reuse_address option: " << ec.message() << std::endl;
return false;
}
}
Expand All @@ -79,7 +79,7 @@ namespace fineftp
acceptor_.bind(endpoint, ec);
if (ec)
{
std::cerr << "Error binding acceptor: " << ec.message() << std::endl;
error_ << "Error binding acceptor: " << ec.message() << std::endl;
return false;
}
}
Expand All @@ -89,13 +89,13 @@ namespace fineftp
acceptor_.listen(asio::socket_base::max_listen_connections, ec);
if (ec)
{
std::cerr << "Error listening on acceptor: " << ec.message() << std::endl;
error_ << "Error listening on acceptor: " << ec.message() << std::endl;
return false;
}
}

#ifndef NDEBUG
std::cout << "FTP Server created." << std::endl << "Listening at address " << acceptor_.local_endpoint().address() << " on port " << acceptor_.local_endpoint().port() << ":" << std::endl;
output_ << "FTP Server created." << std::endl << "Listening at address " << acceptor_.local_endpoint().address() << " on port " << acceptor_.local_endpoint().port() << ":" << std::endl;
#endif // NDEBUG

acceptor_.async_accept(ftp_session->getSocket()
Expand Down Expand Up @@ -129,13 +129,13 @@ namespace fineftp
if (error)
{
#ifndef NDEBUG
std::cerr << "Error handling connection: " << error.message() << std::endl;
error_ << "Error handling connection: " << error.message() << std::endl;
#endif
return;
}

#ifndef NDEBUG
std::cout << "FTP Client connected: " << ftp_session->getSocket().remote_endpoint().address().to_string() << ":" << ftp_session->getSocket().remote_endpoint().port() << std::endl;
output_ << "FTP Client connected: " << ftp_session->getSocket().remote_endpoint().address().to_string() << ":" << ftp_session->getSocket().remote_endpoint().port() << std::endl;
#endif

ftp_session->start();
Expand Down
8 changes: 4 additions & 4 deletions fineftp-server/src/user_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace fineftp
{
if (anonymous_user_)
{
std::cerr << "Error adding user with username \"" << username << "\". The username denotes the anonymous user, which is already present." << std::endl;
error_ << "Error adding user with username \"" << username << "\". The username denotes the anonymous user, which is already present." << std::endl;
return false;
}
else
{
anonymous_user_ = std::make_shared<FtpUser>(password, local_root_path, permissions);
#ifndef NDEBUG
std::cout << "Successfully added anonymous user." << std::endl;
output_ << "Successfully added anonymous user." << std::endl;
#endif // !NDEBUG
return true;
}
Expand All @@ -44,13 +44,13 @@ namespace fineftp
{
database_.emplace(username, std::make_shared<FtpUser>(password, local_root_path, permissions));
#ifndef NDEBUG
std::cout << "Successfully added user \"" << username << "\"." << std::endl;
output_ << "Successfully added user \"" << username << "\"." << std::endl;
#endif // !NDEBUG
return true;
}
else
{
std::cerr << "Error adding user with username \"" << username << "\". The user already exists." << std::endl;
error_ << "Error adding user with username \"" << username << "\". The user already exists." << std::endl;
return false;
}
}
Expand Down

0 comments on commit 8586742

Please sign in to comment.