Added incomplete MIDIToneGenerator project.
[pub/USBasp.git] / Projects / Webserver / Lib / TELNETServerApp.c
index 7d8c907..2855f8d 100644 (file)
   this software.\r
 */\r
 \r
+#if defined(ENABLE_TELNET_SERVER) || defined(__DOXYGEN__)\r
+\r
 /** \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
@@ -44,9 +46,13 @@ const char PROGMEM WelcomeHeader[] = "******************************************
 \r
 /** Main TELNET menu, giving the user the list of available commands they may issue */\r
 const char PROGMEM TELNETMenu[] = "\r\n"\r
-                                  "   Available Commands:\r\n"\r
+                                  "  == Available Commands: ==\r\n"\r
                                   "     c) List Active TCP Connections\r\n"\r
-                                                     "\r\nCommand>";\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 +71,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
@@ -108,7 +116,7 @@ void TELNETServerApp_Callback(void)
                                                TELNETServerApp_DisplayTCPConnections();\r
                                                break;\r
                                        default:\r
-                                               strcpy(AppData, "Invalid Command.\r\n");\r
+                                               strcpy_P(AppData, PSTR("Invalid Command.\r\n"));\r
                                                uip_send(AppData, strlen(AppData));\r
                                                break;\r
                                }\r
@@ -124,7 +132,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
@@ -138,14 +146,17 @@ static void TELNETServerApp_DisplayTCPConnections(void)
                if (CurrConnection->tcpstateflags != UIP_CLOSED)\r
                {\r
                        /* Add the current connection's details to the out buffer */\r
-                       ResponseLen += sprintf(&AppData[ResponseLen], "%u) %02d.%02d.%02d.%02d (Local %u, Remote %u)\r\n",\r
-                                                                  ++ActiveConnCount, CurrConnection->ripaddr.u8[0],\r
-                                                                                                         CurrConnection->ripaddr.u8[1],\r
-                                                                                                         CurrConnection->ripaddr.u8[2],\r
-                                                                                                         CurrConnection->ripaddr.u8[3],\r
-                                                                  HTONS(CurrConnection->lport), HTONS(CurrConnection->rport));\r
+                       ResponseLen += sprintf_P(&AppData[ResponseLen], PSTR("%u) %02d.%02d.%02d.%02d (Local %u, Remote %u)\r\n"),\r
+                                                ++ActiveConnCount,\r
+                                                CurrConnection->ripaddr.u8[0],\r
+                                                CurrConnection->ripaddr.u8[1],\r
+                                                CurrConnection->ripaddr.u8[2],\r
+                                                CurrConnection->ripaddr.u8[3],\r
+                                                HTONS(CurrConnection->lport), HTONS(CurrConnection->rport));\r
                }\r
        }\r
 \r
        uip_send(AppData, ResponseLen);\r
-}
\ No newline at end of file
+}\r
+\r
+#endif\r