Commit for the 100219 release.
[pub/USBasp.git] / Projects / Webserver / Lib / TELNETServerApp.c
index cabf527..d1f1d7f 100644 (file)
 /** \file\r
  *\r
  *  TELNET Webserver Application. When connected to the uIP stack,\r
- *  this will serve out connection information to the client.\r
+ *  this will serve out raw TELNET to the client on port 23.\r
  */\r
  \r
 #define  INCLUDE_FROM_TELNETSERVERAPP_C\r
 #include "TELNETServerApp.h"\r
 \r
 /** Welcome message to send to a TELNET client when a connection is first made. */\r
-char PROGMEM WelcomeHeader[] = "********************************************\r\n"\r
-                               "*       LUFA uIP Webserver (TELNET)        *\r\n"\r
-                               "********************************************\r\n";\r
+const char PROGMEM WelcomeHeader[] = "********************************************\r\n"\r
+                                     "*       LUFA uIP Webserver (TELNET)        *\r\n"\r
+                                     "********************************************\r\n";\r
 \r
 /** Main TELNET menu, giving the user the list of available commands they may issue */\r
-char PROGMEM TELNETMenu[] = "\r\n"\r
-                            "   Available Commands:\r\n"\r
-                            "     c) List Active TCP Connections\r\n"\r
-                                               "\r\nCommand>";\r
+const char PROGMEM TELNETMenu[] = "\r\n"\r
+                                  "  == Available Commands: ==\r\n"\r
+                                  "     c) List Active TCP Connections\r\n"\r
+                                  "  =========================\r\n"\r
+                                  "\r\n>";\r
+                                                                 \r
+/** Header to print before the current connections are printed to the client */\r
+const char PROGMEM CurrentConnectionsHeader[] = "\r\n* Current TCP Connections: *\r\n";\r
 \r
 /** Initialization function for the simple HTTP webserver. */\r
 void TELNETServerApp_Init(void)\r
@@ -65,11 +69,13 @@ void TELNETServerApp_Callback(void)
 \r
        if (uip_connected())\r
        {\r
+               /* New connection - initialize connection state values */\r
                AppState->TELNETServer.CurrentState = TELNET_STATE_SendHeader;\r
        }\r
 \r
        if (uip_acked())\r
        {\r
+               /* Progress to the next state once the current state's data has been ACKed */\r
                AppState->TELNETServer.CurrentState = AppState->TELNETServer.NextState; \r
        }\r
 \r
@@ -79,15 +85,15 @@ void TELNETServerApp_Callback(void)
                {\r
                        case TELNET_STATE_SendHeader:\r
                                /* Copy over and send the TELNET welcome message upon first connection */\r
-                               strncpy_P(AppData, WelcomeHeader, strlen_P(WelcomeHeader));\r
-                               uip_send(AppData, strlen_P(WelcomeHeader));\r
+                               strcpy_P(AppData, WelcomeHeader);\r
+                               uip_send(AppData, strlen(AppData));\r
                                \r
                                AppState->TELNETServer.NextState = TELNET_STATE_SendMenu;\r
                                break;\r
                        case TELNET_STATE_SendMenu:\r
                                /* Copy over and send the TELNET menu to the client */\r
-                               strncpy_P(AppData, TELNETMenu, strlen_P(TELNETMenu));\r
-                               uip_send(AppData, strlen_P(TELNETMenu));\r
+                               strcpy_P(AppData, TELNETMenu);\r
+                               uip_send(AppData, strlen(AppData));\r
                                \r
                                AppState->TELNETServer.NextState = TELNET_STATE_GetCommand;\r
                                break;\r
@@ -106,7 +112,11 @@ void TELNETServerApp_Callback(void)
                                {\r
                                        case 'c':\r
                                                TELNETServerApp_DisplayTCPConnections();\r
-                                               break;                                  \r
+                                               break;\r
+                                       default:\r
+                                               strcpy(AppData, "Invalid Command.\r\n");\r
+                                               uip_send(AppData, strlen(AppData));\r
+                                               break;\r
                                }\r
 \r
                                AppState->TELNETServer.NextState = TELNET_STATE_SendMenu;\r
@@ -120,7 +130,7 @@ static void TELNETServerApp_DisplayTCPConnections(void)
 {\r
        char* const AppData    = (char*)uip_appdata;\r
 \r
-       strcpy(AppData, "\r\n* Current TCP Connections: *\r\n");\r
+       strcpy_P(AppData, CurrentConnectionsHeader);\r
                                                        \r
        uint16_t ResponseLen     = strlen(AppData);\r
        uint8_t  ActiveConnCount = 0;\r