#include <senf/Utils/Termlib/Telnet.hh>
This class implements the basic telnet protocol. It provides option parsing and negotiation and implements the necessary character quoting.
This class is a base class. Several virtual function hooks are provided which will be called by the protocol implementation.
The telnet protocol implementation is symmetric: At this level, there is no difference between a telnet client and a telnet server.
This telnet protocol base class integrates with the SENF Scheduler, it relies on the scheduler main loop to be active.
class MyTelnet : public senf::term::telnethandler::TerminalType, public senf::term::telnethandler::NAWS { MyTelnet(Handle handle) : BaseTelnetProtocol(handle) {} // ... };
It is very important, the BaseTelnetProtocol is always inherited by public
virtual
inheritance. This allows the BaseTelnetProtocol constructor to be called by the most derived class directly as above.
Each terminal handler may provide an additional API and/or additional virtual function callbacks.
To implement a new terminal handler, derive from TelnetHandler and register the handler. BaseTelnetProtocol will automatically request the corresponding option to be enabled and will call the handlers v_init()
member as soon as the peer as asserted the option.
Whenever a subnegotiation for the registered handler is received, the handlers v_handleOptionParameters()
member is called.
class MyTelnetHandler : public senf::term::BaseTelnetProtocol::TelnetHandler { public: // This constant is MANDATORY and gives the option code which this handler services static option_type const OPTION_CODE = MY_OPTION_CODE; void frobble() { // ... } protected: MyTelnetHandler() { registerHandler(this); } private: virtual void v_init() { sendOptionParameters(OPTION_CODE, "my special subnegotiation"); incrementRequestCounter(); } virtual void v_handleOptionParameters(std::string const & data) { if (data == "another special subnegotiation") decrementRequestCounter(); } };
Definition at line 135 of file Telnet.hh.
Classes |
|
struct | OptInfo |
struct | TelnetHandler |
Telnet handler base class. More... |
|
Public Types |
|
typedef ClientSocketHandle < senf::MakeSocketPolicy < ConnectedCommunicationPolicy, StreamFramingPolicy, ReadablePolicy, WriteablePolicy >::policy > |
Handle |
Type of socket handle required. |
|
typedef unsigned char | option_type |
Type of telnet option numbers. |
|
Public Member Functions |
|
void | write (std::string const &s) |
Send string to peer. |
|
void | write (char c) |
Send single character to peer. |
|
Handle | handle () |
Get socket handle. |
|
void | sendNOP () |
Send NOP to peer. |
|
void | sendBRK () |
Send BReaK to peer. |
|
void | sendIP () |
Send InterruptProcess to peer. |
|
void | sendAO () |
Send AbortOutput to peer. |
|
void | sendAYT () |
Send AreYouThere to peer. |
|
void | sendEC () |
Send EraseCharacter to peer. |
|
void | sendEL () |
Send EraseLine to peer. |
|
void | sendGA () |
Send GoAhead to peer. |
|
void | sendOptionParameters (option_type option, std::string const &data) |
Send extended option parameter to peer. |
|
void | requestLocalOption (option_type option, bool enabled=true) |
Request option to be enabled here. |
|
void | acceptLocalOption (option_type option, bool enabled=true) |
Accept a request for an option to be enabled here. |
|
void | requestPeerOption (option_type option, bool enabled=true) |
Request peer to enable an option. |
|
void | acceptPeerOption (option_type option, bool enabled=true) |
Accept a request by the peer to enable an option. |
|
bool | localOption (option_type option) |
true , if option locally enabled |
|
bool | peerOption (option_type option) |
true , if option enabled in peer |
|
Static Public Attributes |
|
static unsigned const | DEFAULT_REQUEST_TIMEOUT_MS = 500u |
Protected Member Functions |
|
BaseTelnetProtocol (Handle handle) | |
Construct telnet protocol handler. |
|
BaseTelnetProtocol () | |
Provided for TelnetHandler mixins only. |
|
virtual | ~BaseTelnetProtocol () |
template<class Handler > | |
void | registerHandler (Handler *h, bool request=true) |
Register a TelnetHandler. |
|
void | incrementRequestCounter () |
Increment request counter. |
|
void | decrementRequestCounter () |
Decrement request counter. |
|
bool | requestsPending () |
true , if there are pending requests |
|
virtual void | v_setupComplete ()=0 |
Called, when no further requests are pending. |
|
virtual void | v_charReceived (char c)=0 |
Called whenever a data character is received. |
|
virtual void | v_eof ()=0 |
Called on input EOF. |
|
virtual void | v_handleNOP () |
Called, when the peer sends a NOP. |
|
virtual void | v_handleBRK () |
Called, when the peer sends a BReaK. |
|
virtual void | v_handleIP () |
Called, when the peer sends an InterruptProcess. |
|
virtual void | v_handleAO () |
Called, when the peer sends an AbortOutput. |
|
virtual void | v_handleAYT () |
Called, when the peer sends an AreYouThere. |
|
virtual void | v_handleEC () |
Called, when the peer sends an EraseCharacter. |
|
virtual void | v_handleEL () |
Called, when the peer sends an EraseLine. |
|
virtual void | v_handleGA () |
Called, when the peer sends a GoAhead. |
typedef ClientSocketHandle<senf::MakeSocketPolicy< ConnectedCommunicationPolicy, StreamFramingPolicy, ReadablePolicy, WriteablePolicy>::policy> senf::term::BaseTelnetProtocol:: | ||||
Handle | ||||
typedef unsigned char senf::term::BaseTelnetProtocol:: | ||||
option_type | ||||
senf::term::BaseTelnetProtocol:: | ||||
BaseTelnetProtocol | ( | Handle | handle | ) |
senf::term::BaseTelnetProtocol:: | ||||
BaseTelnetProtocol | () | |||
Provided for TelnetHandler mixins only.
senf::term::BaseTelnetProtocol:: | ||||
~BaseTelnetProtocol | () | |||
Definition at line 74 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
acceptLocalOption | ( | option_type | option, | |
bool |
enabled = true
|
) | ||
Accept a request for an option to be enabled here.
If the peer sends a DO option request, the request will be granted
Definition at line 147 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
acceptPeerOption | ( | option_type | option, | |
bool |
enabled = true
|
) | ||
Accept a request by the peer to enable an option.
If the peer sends a WILL option request, the request will be ganted
Definition at line 159 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
decrementRequestCounter | () | |||
senf::term::BaseTelnetProtocol::Handle senf::term::BaseTelnetProtocol:: | ||||
handle | () | |||
Get socket handle.
Definition at line 77 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
incrementRequestCounter | () | |||
Increment request counter.
This member may be called by a telnet handler to wait for additional negotiations. It must be paired with a corresponding decrementRequestCounter() call when that negotiation is received.
Definition at line 82 of file Telnet.cci.
bool senf::term::BaseTelnetProtocol:: | ||||
localOption | ( | option_type | option | ) |
true
, if option locally enabled
Definition at line 165 of file Telnet.cci.
bool senf::term::BaseTelnetProtocol:: | ||||
peerOption | ( | option_type | option | ) |
true
, if option enabled in peer
Definition at line 170 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
registerHandler | ( | Handler * | h, | |
bool |
request = true
|
) | ||
Register a TelnetHandler.
Definition at line 37 of file Telnet.cti.
void senf::term::BaseTelnetProtocol:: | ||||
requestLocalOption | ( | option_type | option, | |
bool |
enabled = true
|
) | ||
Request option to be enabled here.
This will send a WILL option request to the peer
Definition at line 141 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
requestPeerOption | ( | option_type | option, | |
bool |
enabled = true
|
) | ||
Request peer to enable an option.
This will send a DO option request to the peer
Definition at line 153 of file Telnet.cci.
bool senf::term::BaseTelnetProtocol:: | ||||
requestsPending | () | |||
true
, if there are pending requests
Definition at line 88 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendAO | () | |||
Send AbortOutput to peer.
Definition at line 111 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendAYT | () | |||
Send AreYouThere to peer.
Definition at line 117 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendBRK | () | |||
Send BReaK to peer.
Definition at line 99 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendEC | () | |||
Send EraseCharacter to peer.
Definition at line 123 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendEL | () | |||
Send EraseLine to peer.
Definition at line 129 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendGA | () | |||
Send GoAhead to peer.
Definition at line 135 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendIP | () | |||
Send InterruptProcess to peer.
Definition at line 105 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendNOP | () | |||
Send NOP to peer.
Definition at line 93 of file Telnet.cci.
void senf::term::BaseTelnetProtocol:: | ||||
sendOptionParameters | ( | option_type | option, | |
std::string const & | data | ) | ||
virtual void senf::term::BaseTelnetProtocol:: | ||||
v_charReceived | ( | char | c | ) |
Called whenever a data character is received.
virtual void senf::term::BaseTelnetProtocol:: | ||||
v_eof | () | |||
Called on input EOF.
void senf::term::BaseTelnetProtocol:: | ||||
v_handleAO | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleAYT | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleBRK | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleEC | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleEL | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleGA | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleIP | () | |||
void senf::term::BaseTelnetProtocol:: | ||||
v_handleNOP | () | |||
virtual void senf::term::BaseTelnetProtocol:: | ||||
v_setupComplete | () | |||
Called, when no further requests are pending.
This callback will be called, when no further negotiations are to be expected. The default negotiation timeout is 500ms. If no reply is received in this time, the request is abandoned and v_setupComplete() is called.
mixin TelnetHandler's may additionally increment the request counter to wait for specific subnegotiations. v_setupComplete() will be called, when all these negotiations are complete or have timed out.
void senf::term::BaseTelnetProtocol:: | ||||
write | ( | char | c | ) |
Send single character to peer.
The character will be correctly quoted and newline chars will be sent as CR/LF pairs.
Reimplemented in senf::term::TelnetTerminal.
void senf::term::BaseTelnetProtocol:: | ||||
write | ( | std::string const & | s | ) |
unsigned const senf::term::BaseTelnetProtocol::DEFAULT_REQUEST_TIMEOUT_MS = 500u | ||||
[static] | ||||