45#include <sys/socket.h>
56class TelnetSession :
public std::enable_shared_from_this<TelnetSession> {
88 void echoBack(
const char *buffer,
unsigned long length);
90 static void stripNVT(std::string &buffer);
130class TelnetServer :
public std::enable_shared_from_this<TelnetServer> {
159 bool initialise(
unsigned long listenPort,
const std::shared_ptr<std::atomic_flag> &checkFlag,
160 std::string
promptString =
"",
const std::shared_ptr<prometheus::Registry> ® =
nullptr,
161 const std::string &prependName =
"");
std::vector< SP_TelnetSession > VEC_SP_TelnetSession
std::function< std::string(SP_TelnetSession, std::string)> FPTR_TabCallback
void TelnetConnectedCallback(const SP_TelnetSession &session)
std::shared_ptr< TelnetSession > SP_TelnetSession
std::string TelnetTabCallback(const SP_TelnetSession &session, std::string_view line)
std::function< void(SP_TelnetSession)> FPTR_ConnectedCallback
std::function< bool(SP_TelnetSession, std::string)> FPTR_NewLineCallback
bool TelnetMessageCallback(const SP_TelnetSession &session, const std::string &line)
void promptString(const std::string_view &prompt)
TelnetServer()=default
Constructor for server.
std::unique_ptr< TelnetStats > m_stats
void newLineCallback(FPTR_NewLineCallback func)
FPTR_NewLineCallback m_newlineCallback
FPTR_NewLineCallback newLineCallBack() const
FPTR_TabCallback m_tabCallback
unsigned long m_listenPort
std::atomic_flag m_shouldStop
std::string m_promptString
bool interactivePrompt() const
const VEC_SP_TelnetSession & sessions() const
std::unique_ptr< std::thread > m_serverThread
FPTR_TabCallback tabCallback() const
bool initialise(unsigned long listenPort, const std::shared_ptr< std::atomic_flag > &checkFlag, std::string promptString="", const std::shared_ptr< prometheus::Registry > ®=nullptr, const std::string &prependName="")
void shutdown()
Closes the Telnet Server.
VEC_SP_TelnetSession m_sessions
void threadFunc() noexcept
void connectedCallback(FPTR_ConnectedCallback func)
TelnetServer(TelnetServer &&)=delete
Move constructor.
void tabCallback(FPTR_TabCallback func)
FPTR_ConnectedCallback connectedCallback() const
std::shared_ptr< std::atomic_flag > m_checkFlag
const std::string & promptString() const
TelnetServer & operator=(TelnetServer &&)=delete
Move assignment operator.
~TelnetServer()
Destructor for server.
void update()
Process new connections and messages.
TelnetServer(const TelnetServer &)=delete
Copy constructor.
FPTR_ConnectedCallback m_connectedCallback
TelnetServer & operator=(TelnetServer)=delete
Copy assignment operator.
void update()
Called every frame/loop by the Terminal Server.
TelnetSessionStats stats
Statistics variables.
bool processTab(std::string &buffer)
void markTimeout()
Marks timeout to close session.
bool processCommandHistory(std::string &buffer)
std::chrono::system_clock::time_point lastSeenTime
static bool processBackspace(std::string &buffer)
TelnetSession(Socket ClientSocket, std::shared_ptr< TelnetServer > tServer)
Constructor for session.
static void stripEscapeCharacters(std::string &buffer)
static void stripNVT(std::string &buffer)
bool checkTimeout() const
Checks the connection timeout.
void sendLine(std::string data)
Send a line of data to the Telnet Server.
std::shared_ptr< TelnetServer > m_telnetServer
void sendPromptAndBuffer()
static std::vector< std::string > getCompleteLines(std::string &buffer)
void closeClient()
Finish the session.
std::list< std::string > m_history
void initialise()
Initialise session.
void echoBack(const char *buffer, unsigned long length)
void addToHistory(const std::string &line)
std::string getPeerIP() const
std::list< std::string >::iterator m_historyCursor