Files
2026-05-20 03:08:08 +09:00

71 lines
2.7 KiB
C++

#ifndef TELNET_HANDLER__H_
#define TELNET_HANDLER__H_
#ifdef _WIN32
#pragma once
#endif
class HTelnetHandler : public HProtocolHandler
{
public:
enum eCommand
{
SE = 240, // End of subnegotiation parameters.
NOP = 241, // No operation Data mark. Indicates the position of a Synch event within the data stream.
DM = 242, // This should always be accompanied by a TCP urgent notification.
BRK = 243, // Break. Indicates that the "break" or "attention" key was hit.
IP = 244, // Suspend, interrupt or abort the process to which the NVT is connected.
AO = 245, // Abort output. Allows the current process to run to completion but donot send its output to the user.
AYT = 246, // Are you there. Send back to the NVT some visible evidence that the AYT was received.
EC = 247, // Erase character. The receiver should delete the last preceding undeleted character from the data stream.
EL = 248, // Erase line. Delete characters from the data stream back to but not including the previous CRLF.
GA = 249, // Go ahead. Used, under certain circumstances, to tell the other end that it can transmit.
SB = 250, // Subnegotiation of the indicated option follows.
WILL = 251, // Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.
WONT = 252, // Indicates the refusal to perform, or continue performing, the indicated option.
DO = 253, // Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.
DONT = 254, // Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.
IAC = 255 // Interpret as command.
};
enum EOption
{
ECHO = 1, // echo (RFC 857)
SGAHEAD = 3, // suppress go ahead (RFC 858)
STATUS = 5, // status (RFC 859)
TMARK = 6, // timing mark (RFC 860)
TTYPE = 24, // terminal type (RFC 1091)
WSIZE = 31, // window size (RFC 1073)
TSPEED = 32, // terminal speed (RFC 1079)
RFCONTROL = 33, // remote flow control (RFC 1372)
LMODE = 34, // linemode (RFC 1184)
EVARIABLES = 36, // environment variables (RFC 1408)
};
enum
{
MAX_COMMAND_BUFFER_SIZE = 4096
};
HTelnetHandler();
~HTelnetHandler();
protected:
void OnReceivedStatusFromTransport(int nStatus);
int OnReceivedFromTransport(const char * pData, int nSize);
virtual void OnEstablished() {}
virtual bool OnInitialReceive(const char * pData, unsigned nSize) { return true; }
virtual int OnReceivedCommand(const char * pszCommand) = 0;
protected:
char m_pCommandBuffer[MAX_COMMAND_BUFFER_SIZE + 1];
unsigned int m_nCommandBufferedLength;
int m_bInitialStep;
};
#endif // PROTOCOL_HANDLER__H_