19 #ifndef UUID_TELNET_H_
20 #define UUID_TELNET_H_
23 #ifdef ARDUINO_ARCH_ESP8266
24 # include <ESP8266WiFi.h>
36 #include <uuid/console.h>
103 size_t write(uint8_t data)
override;
114 size_t write(
const uint8_t *buffer,
size_t size)
override;
125 void flush()
override;
128 static constexpr
const unsigned char NUL = 0;
129 static constexpr
const unsigned char BEL = 7;
130 static constexpr
const unsigned char BS = 8;
131 static constexpr
const unsigned char HT = 9;
132 static constexpr
const unsigned char LF = 10;
133 static constexpr
const unsigned char VT = 11;
134 static constexpr
const unsigned char FF = 12;
135 static constexpr
const unsigned char CR = 13;
136 static constexpr
const unsigned char SE = 240;
137 static constexpr
const unsigned char NOP = 241;
138 static constexpr
const unsigned char DM = 242;
139 static constexpr
const unsigned char BRK = 243;
140 static constexpr
const unsigned char IP = 244;
141 static constexpr
const unsigned char AO = 245;
142 static constexpr
const unsigned char AYT = 246;
143 static constexpr
const unsigned char EC = 247;
144 static constexpr
const unsigned char EL = 248;
145 static constexpr
const unsigned char GA = 249;
146 static constexpr
const unsigned char SB = 250;
147 static constexpr
const unsigned char WILL = 251;
148 static constexpr
const unsigned char WONT = 252;
149 static constexpr
const unsigned char DO = 253;
150 static constexpr
const unsigned char DONT = 254;
151 static constexpr
const unsigned char IAC = 255;
155 static constexpr
const unsigned char OPT_SGA = 3;
203 size_t raw_write(
const std::vector<unsigned char> &data);
214 size_t raw_write(
const uint8_t *buffer,
size_t size);
245 using shell_factory_function = std::function<std::shared_ptr<uuid::console::Shell>(Stream &stream,
const IPAddress &addr, uint16_t port)>;
255 TelnetService(std::shared_ptr<uuid::console::Commands> commands,
unsigned int context = 0,
unsigned int flags = 0);
266 TelnetService(uint16_t port, std::shared_ptr<uuid::console::Commands> commands,
unsigned int context = 0,
unsigned int flags = 0);
413 std::weak_ptr<uuid::console::Shell>
shell_;
Logger instance used to make log messages.
std::weak_ptr< uuid::console::Shell > shell_
Connection(shell_factory_function &shell_factory, WiFiClient &&client, unsigned long idle_timeout, unsigned long write_timeout)
Create a telnet connection shell.
bool loop()
Stop the shell if the client is not connected.
bool stop()
Stop the shell.
Provides access to a console shell as a telnet server.
static constexpr unsigned long DEFAULT_IDLE_TIMEOUT
std::list< Connection > connections_
unsigned long initial_idle_timeout() const
Get the initial idle timeout for new connections.
void close_all()
Close all connections.
static constexpr uint16_t DEFAULT_PORT
static uuid::log::Logger logger_
void stop()
Stop listening for connections.
size_t maximum_connections() const
Get the maximum number of concurrent open connections.
static constexpr unsigned long DEFAULT_WRITE_TIMEOUT
TelnetService(std::shared_ptr< uuid::console::Commands > commands, unsigned int context=0, unsigned int flags=0)
Create a new telnet service listening on the default port.
shell_factory_function shell_factory_
unsigned long default_write_timeout() const
Get the default socket write timeout for new connections.
unsigned long write_timeout_
void loop()
Accept new connections.
size_t maximum_connections_
static constexpr size_t MAX_CONNECTIONS
void start()
Start listening for connections on the configured port.
unsigned long initial_idle_timeout_
std::function< std::shared_ptr< uuid::console::Shell >(Stream &stream, const IPAddress &addr, uint16_t port)> shell_factory_function
Function to handle the creation of a shell.
Stream wrapper that performs telnet protocol handling, option negotiation and output buffering.
static constexpr const unsigned char OPT_ECHO
static constexpr const unsigned char FF
unsigned char previous_in_
static constexpr const unsigned char DO
static constexpr const unsigned char BS
static constexpr const unsigned char DONT
void start()
Perform initial negotiation.
void buffer_flush()
Flush output stream buffer.
static constexpr const unsigned char BRK
static constexpr const unsigned char NUL
static constexpr const unsigned char AO
size_t write(uint8_t data) override
Write one byte to the output stream.
int raw_available()
Directly check for available input.
static constexpr const unsigned char AYT
static constexpr const unsigned char SB
void flush() override
Does nothing.
static constexpr const unsigned char SE
int read() override
Read one byte from the available input.
static constexpr const unsigned char VT
static constexpr const unsigned char WONT
static constexpr const unsigned char OPT_BINARY
static constexpr const unsigned char EC
int available() override
Check for available input.
static constexpr const unsigned char DM
static constexpr const unsigned char NOP
std::vector< char > output_buffer_
static constexpr const unsigned char WILL
unsigned char previous_raw_in_
static constexpr const unsigned char GA
static constexpr const size_t BUFFER_SIZE
static constexpr const unsigned char BEL
unsigned char previous_out_
static constexpr const unsigned char LF
int raw_read()
Read one byte directly from the available input.
static constexpr const unsigned char OPT_SGA
static constexpr const unsigned char IP
static constexpr const unsigned char EL
TelnetStream(WiFiClient &client)
Create a new telnet stream wrapper.
static constexpr const unsigned char HT
int peek() override
Read one byte from the available input without advancing to the next one.
static constexpr const unsigned char IAC
size_t raw_write(unsigned char data)
Write one byte directly to the output stream.
static constexpr const unsigned char CR