Telnet protocol implementation. More...
#include <senf/Utils/Termlib/Telnet.hh>
Classes | |
struct | TelnetHandler |
Telnet handler base class. More... | |
Public Types | |
typedef ClientSocketHandle< senf::MakeSocketPolicy< ConnectedCommunicationPolicy, StreamFramingPolicy, ReadablePolicy, WriteablePolicy >::policy > | Handle |
Type of socket handle required. More... | |
typedef unsigned char | option_type |
Type of telnet option numbers. More... | |
Public Member Functions | |
void | write (std::string const &s) |
Send string to peer. More... | |
void | write (char c) |
Send single character to peer. More... | |
Handle | handle () |
Get socket handle. More... | |
void | sendNOP () |
Send NOP to peer. More... | |
void | sendBRK () |
Send BReaK to peer. More... | |
void | sendIP () |
Send InterruptProcess to peer. More... | |
void | sendAO () |
Send AbortOutput to peer. More... | |
void | sendAYT () |
Send AreYouThere to peer. More... | |
void | sendEC () |
Send EraseCharacter to peer. More... | |
void | sendEL () |
Send EraseLine to peer. More... | |
void | sendGA () |
Send GoAhead to peer. More... | |
void | sendOptionParameters (option_type option, std::string const &data) |
Send extended option parameter to peer. More... | |
void | requestLocalOption (option_type option, bool enabled=true) |
Request option to be enabled here. More... | |
void | acceptLocalOption (option_type option, bool enabled=true) |
Accept a request for an option to be enabled here. More... | |
void | requestPeerOption (option_type option, bool enabled=true) |
Request peer to enable an option. More... | |
void | acceptPeerOption (option_type option, bool enabled=true) |
Accept a request by the peer to enable an option. More... | |
bool | localOption (option_type option) |
true , if option locally enabled More... | |
bool | peerOption (option_type option) |
true , if option enabled in peer More... | |
Static Public Attributes | |
static unsigned const | DEFAULT_REQUEST_TIMEOUT_MS = 500u |
Protected Member Functions | |
BaseTelnetProtocol (Handle handle) | |
Construct telnet protocol handler. More... | |
BaseTelnetProtocol () | |
Provided for TelnetHandler mixins only. More... | |
virtual | ~BaseTelnetProtocol () |
template<class Handler > | |
void | registerHandler (Handler *h, bool request=true) |
Register a TelnetHandler. More... | |
void | incrementRequestCounter () |
Increment request counter. More... | |
void | decrementRequestCounter () |
Decrement request counter. More... | |
bool | requestsPending () |
true , if there are pending requests More... | |
virtual void | v_setupComplete ()=0 |
Called, when no further requests are pending. More... | |
virtual void | v_charReceived (char c)=0 |
Called whenever a data character is received. More... | |
virtual void | v_eof ()=0 |
Called on input EOF. More... | |
virtual void | v_handleNOP () |
Called, when the peer sends a NOP. More... | |
virtual void | v_handleBRK () |
Called, when the peer sends a BReaK. More... | |
virtual void | v_handleIP () |
Called, when the peer sends an InterruptProcess. More... | |
virtual void | v_handleAO () |
Called, when the peer sends an AbortOutput. More... | |
virtual void | v_handleAYT () |
Called, when the peer sends an AreYouThere. More... | |
virtual void | v_handleEC () |
Called, when the peer sends an EraseCharacter. More... | |
virtual void | v_handleEL () |
Called, when the peer sends an EraseLine. More... | |
virtual void | v_handleGA () |
Called, when the peer sends a GoAhead. More... | |
Telnet protocol implementation.
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.
To support complex telnet option which require subnegotiation, TelnetHandler's are provided. A telnet handler is a class derived from TelnetHandler and then inherited into the target telnet implementation class:
It is very important, the BaseTelnetProtocol is \e always inherited by \c public \c 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 \c v_init() member as soon as the peer as asserted the option. Whenever a subnegotiation for the registered handler is received, the handlers \c v_handleOptionParameters() member is called.
typedef unsigned char senf::term::BaseTelnetProtocol::option_type |
|
explicitprotected |
|
protected |
Provided for TelnetHandler mixins only.
|
protectedvirtual |
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
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
|
protected |
Handle senf::term::BaseTelnetProtocol::handle | ( | ) |
Get socket handle.
|
protected |
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.
bool senf::term::BaseTelnetProtocol::localOption | ( | option_type | option | ) |
true
, if option locally enabled
bool senf::term::BaseTelnetProtocol::peerOption | ( | option_type | option | ) |
true
, if option enabled in peer
|
protected |
Register a TelnetHandler.
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
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
|
protected |
true
, if there are pending requests
void senf::term::BaseTelnetProtocol::sendAO | ( | ) |
Send AbortOutput to peer.
void senf::term::BaseTelnetProtocol::sendAYT | ( | ) |
Send AreYouThere to peer.
void senf::term::BaseTelnetProtocol::sendBRK | ( | ) |
Send BReaK to peer.
void senf::term::BaseTelnetProtocol::sendEC | ( | ) |
Send EraseCharacter to peer.
void senf::term::BaseTelnetProtocol::sendEL | ( | ) |
Send EraseLine to peer.
void senf::term::BaseTelnetProtocol::sendGA | ( | ) |
Send GoAhead to peer.
void senf::term::BaseTelnetProtocol::sendIP | ( | ) |
Send InterruptProcess to peer.
void senf::term::BaseTelnetProtocol::sendNOP | ( | ) |
Send NOP to peer.
void senf::term::BaseTelnetProtocol::sendOptionParameters | ( | option_type | option, |
std::string const & | data | ||
) |
|
protectedpure virtual |
Called whenever a data character is received.
|
protectedpure virtual |
Called on input EOF.
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedpure virtual |
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 | ( | std::string const & | s | ) |
void senf::term::BaseTelnetProtocol::write | ( | char | c | ) |
|
static |