Finds the plan file and returns its contents
This commit is contained in:
@@ -22,18 +22,33 @@ namespace this_coro = boost::asio::this_coro;
|
||||
|
||||
awaitable<std::string> dofinger(const std::string &username) {
|
||||
co_return process(username);
|
||||
//co_return std::string("this is some finger information for ") + username + std::string("\r\n");
|
||||
// co_return std::string("this is some finger information for ") + username +
|
||||
// std::string("\r\n");
|
||||
}
|
||||
|
||||
awaitable<void> echo(tcp::socket socket) {
|
||||
try {
|
||||
char data[1024];
|
||||
co_await socket.async_read_some(boost::asio::buffer(data), deferred);
|
||||
auto response = co_await dofinger(std::string(data));
|
||||
auto bytes_read =
|
||||
co_await socket.async_read_some(boost::asio::buffer(data), deferred);
|
||||
// strip \r\n from data
|
||||
std::string username(data, bytes_read);
|
||||
// Remove trailing \r\n characters
|
||||
while (!username.empty() &&
|
||||
(username.back() == '\r' || username.back() == '\n')) {
|
||||
username.pop_back();
|
||||
}
|
||||
auto response = co_await dofinger(username);
|
||||
if (response.compare(std::string(username)) == 0) {
|
||||
// No plan found
|
||||
co_await async_write(
|
||||
socket, boost::asio::buffer(std::string("No plan found\r\n")),
|
||||
deferred);
|
||||
co_return;
|
||||
}
|
||||
co_await async_write(socket, boost::asio::buffer(response), deferred);
|
||||
co_return;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
} catch (std::exception &e) {
|
||||
std::printf("echo Exception: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user