aboutsummaryrefslogtreecommitdiff
path: root/src/protocoltelnet.cpp
blob: b0209dba394944fb70b2a3bc06574777c1bcb089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "bu/protocoltelnet.h"
#include "bu/client.h"

#define CODE_SE		'\xf0'	/**< End of subnegotiation params. */
#define CODE_NOP	'\xf1'	/**< No operation (keep-alive). */
#define CODE_DM		'\xf2'	/**< Datastream side of a Synch. */
#define CODE_BRK	'\xf3'	/**< Break character. */
#define CODE_IP		'\xf4' /**< Interrupt Process character. */
#define CODE_AO		'\xf5' /**< Abort Output character. */
#define CODE_AYT	'\xf6' /**< Are You There? character. */
#define CODE_EC		'\xf7' /**< Erase Character character. */
#define CODE_EL		'\xf8'	/**< Erase Line character. */
#define CODE_GA		'\xf9' /**< Go Ahead signal. */
#define CODE_SB		'\xfa'	/**< Begin subnegotiation options. */
#define CODE_WILL	'\xfb'	/**< Desire to do something. */
#define CODE_WONT	'\xfc'	/**< Refuse to perform. */
#define CODE_DO		'\xfd'	/**< Request option. */
#define CODE_DONT	'\xfe'	/**< Demand a stop. */

#define CODE_IAC	'\xff'	/**< Interpret-As-Command. */

#define OPT_BINARY	'\x00'	/**< Binary mode (file transfers?). */
#define OPT_ECHO	'\x01'	/**< (local) Echo mode. */

Bu::ProtocolTelnet::ProtocolTelnet() :
	oBinary(	*this, OPT_BINARY ),
	oEcho(		*this, OPT_ECHO )
{
}

Bu::ProtocolTelnet::~ProtocolTelnet()
{
}

void Bu::ProtocolTelnet::onNewConnection( Bu::Client *pClient )
{
}

void Bu::ProtocolTelnet::onNewData( Bu::Client *pClient )
{
}



Bu::ProtocolTelnet::Option::Option( Bu::ProtocolTelnet &rPT, char cCode ) :
	rPT( rPT ),
	fOpts( 0 ),
	cCode( cCode )
{
	rPT.hOpts.insert( cCode, this );
}

Bu::ProtocolTelnet::Option::~Option()
{
}

void Bu::ProtocolTelnet::Option::localEnable( bool bSet )
{
	if( bSet == (bool)(!(fOpts&fLocalCant)) ) return;

	if( bSet )
		fOpts &= ~fLocalCant;
	else
		fOpts |= fLocalCant;
}

void Bu::ProtocolTelnet::Option::localSet( bool bSet )
{
	if( bSet == (bool)(fOpts&fLocalIs) ) return;

	char buf[2];

	if( bSet )
	{
		buf[0] = CODE_WILL;
		buf[1] = cCode;
		rPT.pClient->write( buf, 2 );
	}
	else
	{
		buf[0] = CODE_WONT;
		buf[1] = cCode;
		rPT.pClient->write( buf, 2 );
	}
}

bool Bu::ProtocolTelnet::Option::isLocalEnabled()
{
	return (bool)(!(fOpts&fLocalCant));
}

bool Bu::ProtocolTelnet::Option::isLocalSet()
{
	return (bool)(fOpts&fLocalIs);
}

void Bu::ProtocolTelnet::Option::remoteEnable( bool bSet )
{
	return;
}

void Bu::ProtocolTelnet::Option::remoteSet( bool bSet )
{
	if( bSet == (bool)(fOpts&fRemoteIs) ) return;

	char buf[2];

	if( bSet )
	{
		buf[0] = CODE_DO;
		buf[1] = cCode;
		rPT.pClient->write( buf, 2 );
	}
	else
	{
		buf[0] = CODE_DONT;
		buf[1] = cCode;
		rPT.pClient->write( buf, 2 );
	}
}

bool Bu::ProtocolTelnet::Option::isRemoteEnabled()
{
	return (bool)(!(fOpts&fRemoteCant));
}

bool Bu::ProtocolTelnet::Option::isRemoteSet()
{
	return (bool)(fOpts&fRemoteIs);
}