1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_TELNET_SERVER_H_
6 #define NET_BASE_TELNET_SERVER_H_
8 #include "net/base/listen_socket.h"
10 // Implements the telnet protocol on top of the raw socket interface.
11 // DidRead calls to the delegate are buffered on a line by line basis.
12 // (for now this means that basic line editing is handled in this object)
13 class TelnetServer
: public ListenSocket
{
15 static TelnetServer
* Listen(std::string ip
, int port
,
16 ListenSocketDelegate
*del
);
19 void Listen() { ListenSocket::Listen(); }
21 virtual void Accept();
22 virtual void SendInternal(const char* bytes
, int len
);
25 enum TelnetInputState
{
26 // Currently not processing any IAC or ESC sequence.
27 NOT_IN_IAC_OR_ESC_SEQUENCE
,
28 // Received carriage return (CR) expecting new line (LF).
30 // Processing IAC expecting command.
32 // Processing IAC expecting option.
34 // Inside subnegoation IAC,SE will end it.
35 SUBNEGOTIATION_EXPECTING_IAC
,
36 // Ending subnegoation expecting SE.
37 SUBNEGOTIATION_EXPECTING_SE
,
38 // Processing ESC sequence.
39 EXPECTING_FIRST_ESC_CHARACTER
,
40 // Processing ESC sequence with two characters.
41 EXPECTING_SECOND_ESC_CHARACTER
,
42 // Processing "ESC [" sequence.
43 EXPECTING_NUMBER_SEMICOLON_OR_END
46 TelnetServer(SOCKET s
, ListenSocketDelegate
* del
);
47 virtual ~TelnetServer();
50 void SendIAC(int command
, int option
);
51 void StateMachineStep(unsigned char c
);
53 TelnetInputState input_state_
;
54 int iac_command_
; // Last command read.
55 int iac_option_
; // Last option read.
56 std::string command_line_
;
58 DISALLOW_EVIL_CONSTRUCTORS(TelnetServer
);
61 #endif // NET_BASE_TELNET_SERVER_H_