X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/b9cf4815e5445db2d805117c90adaa1755c853cf..e55f33866334615e705ff68c0f3bea8e5b1b9b8b:/Projects/Webserver/Lib/TELNETServerApp.c diff --git a/Projects/Webserver/Lib/TELNETServerApp.c b/Projects/Webserver/Lib/TELNETServerApp.c index 720f7d14c..2855f8d76 100644 --- a/Projects/Webserver/Lib/TELNETServerApp.c +++ b/Projects/Webserver/Lib/TELNETServerApp.c @@ -28,25 +28,31 @@ this software. */ +#if defined(ENABLE_TELNET_SERVER) || defined(__DOXYGEN__) + /** \file * * TELNET Webserver Application. When connected to the uIP stack, - * this will serve out connection information to the client. + * this will serve out raw TELNET to the client on port 23. */ #define INCLUDE_FROM_TELNETSERVERAPP_C #include "TELNETServerApp.h" /** Welcome message to send to a TELNET client when a connection is first made. */ -char PROGMEM WelcomeHeader[] = "********************************************\r\n" - "* LUFA uIP Webserver (TELNET) *\r\n" - "********************************************\r\n"; +const char PROGMEM WelcomeHeader[] = "********************************************\r\n" + "* LUFA uIP Webserver (TELNET) *\r\n" + "********************************************\r\n"; /** Main TELNET menu, giving the user the list of available commands they may issue */ -char PROGMEM TELNETMenu[] = "\r\n" - " Available Commands:\r\n" - " c) List Active TCP Connections\r\n" - "\r\nCommand>"; +const char PROGMEM TELNETMenu[] = "\r\n" + " == Available Commands: ==\r\n" + " c) List Active TCP Connections\r\n" + " =========================\r\n" + "\r\n>"; + +/** Header to print before the current connections are printed to the client */ +const char PROGMEM CurrentConnectionsHeader[] = "\r\n* Current TCP Connections: *\r\n"; /** Initialization function for the simple HTTP webserver. */ void TELNETServerApp_Init(void) @@ -65,11 +71,13 @@ void TELNETServerApp_Callback(void) if (uip_connected()) { + /* New connection - initialize connection state values */ AppState->TELNETServer.CurrentState = TELNET_STATE_SendHeader; } if (uip_acked()) { + /* Progress to the next state once the current state's data has been ACKed */ AppState->TELNETServer.CurrentState = AppState->TELNETServer.NextState; } @@ -106,7 +114,11 @@ void TELNETServerApp_Callback(void) { case 'c': TELNETServerApp_DisplayTCPConnections(); - break; + break; + default: + strcpy_P(AppData, PSTR("Invalid Command.\r\n")); + uip_send(AppData, strlen(AppData)); + break; } AppState->TELNETServer.NextState = TELNET_STATE_SendMenu; @@ -120,7 +132,7 @@ static void TELNETServerApp_DisplayTCPConnections(void) { char* const AppData = (char*)uip_appdata; - strcpy(AppData, "\r\n* Current TCP Connections: *\r\n"); + strcpy_P(AppData, CurrentConnectionsHeader); uint16_t ResponseLen = strlen(AppData); uint8_t ActiveConnCount = 0; @@ -134,14 +146,17 @@ static void TELNETServerApp_DisplayTCPConnections(void) if (CurrConnection->tcpstateflags != UIP_CLOSED) { /* Add the current connection's details to the out buffer */ - ResponseLen += sprintf(&AppData[ResponseLen], "%u) %02d.%02d.%02d.%02d (Local %u, Remote %u)\r\n", - ++ActiveConnCount, CurrConnection->ripaddr.u8[0], - CurrConnection->ripaddr.u8[1], - CurrConnection->ripaddr.u8[2], - CurrConnection->ripaddr.u8[3], - HTONS(CurrConnection->lport), HTONS(CurrConnection->rport)); + ResponseLen += sprintf_P(&AppData[ResponseLen], PSTR("%u) %02d.%02d.%02d.%02d (Local %u, Remote %u)\r\n"), + ++ActiveConnCount, + CurrConnection->ripaddr.u8[0], + CurrConnection->ripaddr.u8[1], + CurrConnection->ripaddr.u8[2], + CurrConnection->ripaddr.u8[3], + HTONS(CurrConnection->lport), HTONS(CurrConnection->rport)); } } uip_send(AppData, ResponseLen); -} \ No newline at end of file +} + +#endif