11/*
2- * uuid-telnetd - Telnet service
2+ * uuid-telnet - Telnet service
33 * Copyright 2019 Simon Arlott
44 *
55 * This program is free software: you can redistribute it and/or modify
1616 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19- #include " uuid/telnetd .h"
19+ #include " uuid/telnet .h"
2020
2121#include < Arduino.h>
2222#ifdef ARDUINO_ARCH_ESP8266
3434#include < uuid/common.h>
3535#include < uuid/log.h>
3636
37- #ifndef UUID_TELNETD_HAVE_WIFICLIENT_REMOTE
37+ #ifndef UUID_TELNET_HAVE_WIFICLIENT_REMOTE
3838# if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
39- # define UUID_TELNETD_HAVE_WIFICLIENT_REMOTE 1
39+ # define UUID_TELNET_HAVE_WIFICLIENT_REMOTE 1
4040# else
41- # define UUID_TELNETD_HAVE_WIFICLIENT_REMOTE 0
41+ # define UUID_TELNET_HAVE_WIFICLIENT_REMOTE 0
4242# endif
4343#endif
4444
45- #ifndef UUID_TELNETD_HAVE_WIFICLIENT_NODELAY
45+ #ifndef UUID_TELNET_HAVE_WIFICLIENT_NODELAY
4646# if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
47- # define UUID_TELNETD_HAVE_WIFICLIENT_NODELAY 1
47+ # define UUID_TELNET_HAVE_WIFICLIENT_NODELAY 1
4848# else
49- # define UUID_TELNETD_HAVE_WIFICLIENT_NODELAY 0
49+ # define UUID_TELNET_HAVE_WIFICLIENT_NODELAY 0
5050# endif
5151#endif
5252
53- #ifndef UUID_TELNETD_HAVE_WIFICLIENT_KEEPALIVE
53+ #ifndef UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE
5454# if defined(ARDUINO_ARCH_ESP8266)
55- # define UUID_TELNETD_HAVE_WIFICLIENT_KEEPALIVE 1
55+ # define UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE 1
5656# else
57- # define UUID_TELNETD_HAVE_WIFICLIENT_KEEPALIVE 0
57+ # define UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE 0
5858# endif
5959#endif
6060
61- static const char __pstr__logger_name[] __attribute__((__aligned__(sizeof (int )))) PROGMEM = " telnetd " ;
61+ static const char __pstr__logger_name[] __attribute__((__aligned__(sizeof (int )))) PROGMEM = " telnet " ;
6262
6363namespace uuid {
6464
65- namespace telnetd {
65+ namespace telnet {
6666
6767uuid::log::Logger TelnetService::logger_{FPSTR (__pstr__logger_name), uuid::log::Facility::DAEMON};
6868
@@ -152,19 +152,19 @@ void TelnetService::loop() {
152152 WiFiClient client = server_.available ();
153153 if (client) {
154154 if (connections_.size () >= maximum_connections_) {
155- #if UUID_TELNETD_HAVE_WIFICLIENT_REMOTE
155+ #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
156156 logger_.info (F (" New connection from [%s]:%u rejected (connection limit reached)" ), uuid::printable_to_string (client.remoteIP ()).c_str (), client.remotePort ());
157157#else
158158 logger_.info (F (" New connection rejected (connection limit reached)" ));
159159#endif
160160 client.println (F (" Maximum connection limit reached." ));
161161 client.stop ();
162162 } else {
163- #if UUID_TELNETD_HAVE_WIFICLIENT_REMOTE
163+ #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
164164 logger_.info (F (" New connection from [%s]:%u accepted" ), uuid::printable_to_string (client.remoteIP ()).c_str (), client.remotePort ());
165165#endif
166166 connections_.emplace_back (shell_factory_, std::move (client), initial_idle_timeout_, write_timeout_);
167- #if !(UUID_TELNETD_HAVE_WIFICLIENT_REMOTE )
167+ #if !(UUID_TELNET_HAVE_WIFICLIENT_REMOTE )
168168 logger_.info (F (" New connection %p accepted" ), &connections_.back ());
169169#endif
170170 }
@@ -173,19 +173,19 @@ void TelnetService::loop() {
173173
174174TelnetService::Connection::Connection (shell_factory_function &shell_factory, WiFiClient &&client, unsigned long idle_timeout, unsigned long write_timeout)
175175 : client_(std::move(client)), stream_(client_) {
176- #if UUID_TELNETD_HAVE_WIFICLIENT_REMOTE
176+ #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
177177 // These have to be copied because they're not accessible on closed connections
178178 addr_ = client_.remoteIP ();
179179 port_ = client_.remotePort ();
180180#else
181181 port_ = 0 ;
182182#endif
183183
184- #if UUID_TELNETD_HAVE_WIFICLIENT_NODELAY
184+ #if UUID_TELNET_HAVE_WIFICLIENT_NODELAY
185185 client_.setNoDelay (true );
186186#endif
187187
188- #if UUID_TELNETD_HAVE_WIFICLIENT_KEEPALIVE
188+ #if UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE
189189 // Disconnect after 30 seconds without a response
190190 client_.keepAlive (5 , 5 , 5 );
191191#endif
@@ -217,7 +217,7 @@ bool TelnetService::Connection::loop() {
217217 }
218218 return true ;
219219 } else {
220- #if UUID_TELNETD_HAVE_WIFICLIENT_REMOTE
220+ #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
221221 logger_.info (F (" Connection from [%s]:%u closed" ), uuid::printable_to_string (addr_).c_str (), port_);
222222#else
223223 logger_.info (F (" Connection %p closed" ), this );
@@ -232,6 +232,6 @@ void TelnetService::Connection::stop() {
232232 }
233233}
234234
235- } // namespace telnetd
235+ } // namespace telnet
236236
237237} // namespace fridge
0 commit comments