Telnet protocol implementation. More...

#include <senf/Utils/Termlib/Telnet.hh>

Inheritance diagram for senf::term::BaseTelnetProtocol:

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...
 

Detailed Description

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.

Telnet option handlers

    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:
class MyTelnet
{
MyTelnet(Handle handle) : BaseTelnetProtocol(handle) {}
// ...
};
    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.
class MyTelnetHandler
{
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");
}
virtual void v_handleOptionParameters(std::string const & data)
{
if (data == "another special subnegotiation")
}
};
Todo:
SYNCH handling

Definition at line 131 of file Telnet.hh.

Member Typedef Documentation

◆ Handle

◆ option_type

Type of telnet option numbers.

Definition at line 142 of file Telnet.hh.

Constructor & Destructor Documentation

◆ BaseTelnetProtocol() [1/2]

senf::term::BaseTelnetProtocol::BaseTelnetProtocol ( Handle  handle)
explicitprotected

Construct telnet protocol handler.

Definition at line 30 of file Telnet.cc.

◆ BaseTelnetProtocol() [2/2]

senf::term::BaseTelnetProtocol::BaseTelnetProtocol ( )
protected

Provided for TelnetHandler mixins only.

Definition at line 44 of file Telnet.cc.

◆ ~BaseTelnetProtocol()

virtual senf::term::BaseTelnetProtocol::~BaseTelnetProtocol ( )
protectedvirtual

Member Function Documentation

◆ acceptLocalOption()

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

◆ acceptPeerOption()

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

◆ decrementRequestCounter()

void senf::term::BaseTelnetProtocol::decrementRequestCounter ( )
protected

Decrement request counter.

See also
inrementRequestCounter()

Definition at line 430 of file Telnet.cc.

◆ handle()

Handle senf::term::BaseTelnetProtocol::handle ( )

Get socket handle.

◆ incrementRequestCounter()

void senf::term::BaseTelnetProtocol::incrementRequestCounter ( )
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.

Definition at line 327 of file Telnet.cc.

◆ localOption()

bool senf::term::BaseTelnetProtocol::localOption ( option_type  option)

true, if option locally enabled

◆ peerOption()

bool senf::term::BaseTelnetProtocol::peerOption ( option_type  option)

true, if option enabled in peer

◆ registerHandler()

template<class Handler >
void senf::term::BaseTelnetProtocol::registerHandler ( Handler *  h,
bool  request = true 
)
protected

Register a TelnetHandler.

◆ requestLocalOption()

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

◆ requestPeerOption()

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

◆ requestsPending()

bool senf::term::BaseTelnetProtocol::requestsPending ( )
protected

true, if there are pending requests

◆ sendAO()

void senf::term::BaseTelnetProtocol::sendAO ( )

Send AbortOutput to peer.

◆ sendAYT()

void senf::term::BaseTelnetProtocol::sendAYT ( )

Send AreYouThere to peer.

◆ sendBRK()

void senf::term::BaseTelnetProtocol::sendBRK ( )

Send BReaK to peer.

◆ sendEC()

void senf::term::BaseTelnetProtocol::sendEC ( )

Send EraseCharacter to peer.

◆ sendEL()

void senf::term::BaseTelnetProtocol::sendEL ( )

Send EraseLine to peer.

◆ sendGA()

void senf::term::BaseTelnetProtocol::sendGA ( )

Send GoAhead to peer.

◆ sendIP()

void senf::term::BaseTelnetProtocol::sendIP ( )

Send InterruptProcess to peer.

◆ sendNOP()

void senf::term::BaseTelnetProtocol::sendNOP ( )

Send NOP to peer.

◆ sendOptionParameters()

void senf::term::BaseTelnetProtocol::sendOptionParameters ( option_type  option,
std::string const &  data 
)

Send extended option parameter to peer.

This will send data as extended option parameter of option option to peer via a subnegotiation.

Definition at line 86 of file Telnet.cc.

◆ v_charReceived()

virtual void senf::term::BaseTelnetProtocol::v_charReceived ( char  c)
protectedpure virtual

Called whenever a data character is received.

◆ v_eof()

virtual void senf::term::BaseTelnetProtocol::v_eof ( )
protectedpure virtual

Called on input EOF.

◆ v_handleAO()

void senf::term::BaseTelnetProtocol::v_handleAO ( )
protectedvirtual

Called, when the peer sends an AbortOutput.

Definition at line 112 of file Telnet.cc.

◆ v_handleAYT()

void senf::term::BaseTelnetProtocol::v_handleAYT ( )
protectedvirtual

Called, when the peer sends an AreYouThere.

Definition at line 115 of file Telnet.cc.

◆ v_handleBRK()

void senf::term::BaseTelnetProtocol::v_handleBRK ( )
protectedvirtual

Called, when the peer sends a BReaK.

Definition at line 106 of file Telnet.cc.

◆ v_handleEC()

void senf::term::BaseTelnetProtocol::v_handleEC ( )
protectedvirtual

Called, when the peer sends an EraseCharacter.

Definition at line 118 of file Telnet.cc.

◆ v_handleEL()

void senf::term::BaseTelnetProtocol::v_handleEL ( )
protectedvirtual

Called, when the peer sends an EraseLine.

Definition at line 121 of file Telnet.cc.

◆ v_handleGA()

void senf::term::BaseTelnetProtocol::v_handleGA ( )
protectedvirtual

Called, when the peer sends a GoAhead.

Definition at line 124 of file Telnet.cc.

◆ v_handleIP()

void senf::term::BaseTelnetProtocol::v_handleIP ( )
protectedvirtual

Called, when the peer sends an InterruptProcess.

Definition at line 109 of file Telnet.cc.

◆ v_handleNOP()

void senf::term::BaseTelnetProtocol::v_handleNOP ( )
protectedvirtual

Called, when the peer sends a NOP.

Definition at line 103 of file Telnet.cc.

◆ v_setupComplete()

virtual void senf::term::BaseTelnetProtocol::v_setupComplete ( )
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.

◆ write() [1/2]

void senf::term::BaseTelnetProtocol::write ( std::string const &  s)

Send string to peer.

The string will be correctly quoted and newline chars will be sent as CR/LF pairs.

Definition at line 58 of file Telnet.cc.

◆ write() [2/2]

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.

Definition at line 64 of file Telnet.cc.

Member Data Documentation

◆ DEFAULT_REQUEST_TIMEOUT_MS

unsigned const senf::term::BaseTelnetProtocol::DEFAULT_REQUEST_TIMEOUT_MS = 500u
static

Definition at line 134 of file Telnet.hh.


The documentation for this class was generated from the following files: