From fdc3169942c1a9523eb0fca3e2742d14612ca57c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 14 Oct 2007 03:36:34 +0000 Subject: Beginings of a Telnet Protocol handler, I finally solved the general Option negotiation issues that plagued the earlier version, now I just have to actually process data. --- src/protocoltelnet.h | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/protocoltelnet.h (limited to 'src/protocoltelnet.h') diff --git a/src/protocoltelnet.h b/src/protocoltelnet.h new file mode 100644 index 0000000..3a606b5 --- /dev/null +++ b/src/protocoltelnet.h @@ -0,0 +1,90 @@ +#ifndef BU_PROTOCOL_TELNET_H +#define BU_PROTOCOL_TELNET_H + +#include "bu/protocol.h" +#include "bu/hash.h" + +namespace Bu +{ + class ProtocolTelnet : public Protocol + { + public: + ProtocolTelnet(); + virtual ~ProtocolTelnet(); + + virtual void onNewConnection( class Bu::Client *pClient ); + virtual void onNewData( class Bu::Client *pClient ); + + enum OptMode + { + optOff, + optOn, + optDesire, + optRefuse + }; + + OptMode getLocalOptBinary(); + void setLocalOptBinary( OptMode eMode ); + OptMode getRemoteOptBinary(); + void setRemoteOptBinary( OptMode eMode ); + + OptMode getLocalOptEcho(); + void setLocalOptEcho( OptMode eMode ); + OptMode getRemoteOptEcho(); + void setRemoteOptEcho( OptMode eMode ); + + private: + /** + * Represents a basic telnet option, either on or off, no parameters. + * Each Option can negotiate effectively on it's own, and has two + * parameters in each of two classes. Both local and remote can be + * enabled/disabled and set/unset. Enabled represents the ability to + * set the option, disabling an option should also unset it. Set or + * unset represent wether the option is being used, if it is allowed. + */ + class Option + { + friend class Bu::ProtocolTelnet; + private: + Option( ProtocolTelnet &rPT, char cCode ); + virtual ~Option(); + + public: + void localEnable( bool bSet=true ); + void localSet( bool bSet=true ); + + bool isLocalEnabled(); + bool isLocalSet(); + + void remoteEnable( bool bSet=true ); + void remoteSet( bool bSet=true ); + + bool isRemoteEnabled(); + bool isRemoteSet(); + + private: + enum + { + fLocalCant = 0x01, /**< Local can't/won't allow option. */ + fLocalIs = 0x02, /**< Local is using option. */ + fRemoteCant = 0x04, /**< Remote can't/won't allow option. */ + fRemoteIs = 0x08 /**< Remote is using option. */ + }; + + ProtocolTelnet &rPT; + char fOpts; + char cCode; + }; + + Hash hOpts; + + Option oBinary; + Option oEcho; + + Client *pClient; + + friend class Bu::ProtocolTelnet::Option; + }; +} + +#endif -- cgit v1.2.3