Added ENABLE_TELNET_SERVER compile time option to the Webserver project to disable...
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 10 Mar 2010 12:48:20 +0000 (12:48 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 10 Mar 2010 12:48:20 +0000 (12:48 +0000)
Change over static strings in the Webserver project to use PROGMEM where possible.

LUFA/ManPages/ChangeLog.txt
Projects/Webserver/Lib/DHCPClientApp.c
Projects/Webserver/Lib/DHCPClientApp.h
Projects/Webserver/Lib/HTTPServerApp.c
Projects/Webserver/Lib/TELNETServerApp.c
Projects/Webserver/Lib/uIPManagement.c
Projects/Webserver/Webserver.txt
Projects/Webserver/makefile

index cdffd3c..e32cdab 100644 (file)
@@ -17,6 +17,7 @@
   *  - Increased the speed of both software and hardware TPI/PDI programming modes of the AVRISP project\r
   *  - Added a timeout value to the TWI_StartTransmission() function, within which the addressed device must respond\r
   *  - Webserver project now uses the board LEDs to indicate the current IP configuration state\r
+  *  - Added ENABLE_TELNET_SERVER compile time option to the Webserver project to disable the TELNET server if desired\r
   *\r
   *  <b>Fixed:</b>\r
   *  - Fixed software PDI/TPI programming mode in the AVRISP project not correctly toggling just the clock pin\r
index 01cbb7e..1af90ad 100644 (file)
   this software.\r
 */\r
 \r
+#if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__)\r
+\r
 /** \file\r
  *\r
  *  DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the\r
  *  DHCP server on the network.\r
  */\r
 \r
+#define  INCLUDE_FROM_DHCPCLIENTAPP_C\r
 #include "DHCPClientApp.h"\r
 \r
-#if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__)\r
-\r
 /** Initialization function for the DHCP client. */\r
 void DHCPClientApp_Init(void)\r
 {\r
@@ -175,7 +176,7 @@ void DHCPClientApp_Callback(void)
  *\r
  *  \return Size in bytes of the created DHCP packet\r
  */\r
-uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState)\r
+static uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState)\r
 {\r
        /* Erase existing packet data so that we start will all 0x00 DHCP header data */\r
        memset(DHCPHeader, 0, sizeof(DHCP_Header_t));\r
@@ -214,7 +215,7 @@ uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMes
  *\r
  *  \return Number of bytes added to the DHCP packet\r
  */\r
-uint8_t DHCPClientApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData)\r
+static uint8_t DHCPClientApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData)\r
 {\r
        /* Skip through the DHCP options list until the terminator option is found */\r
        while (*DHCPOptionList != DHCP_OPTION_END)\r
@@ -238,7 +239,7 @@ uint8_t DHCPClientApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t
  *\r
  *  \return Boolean true if the option was found in the DHCP packet's options list, false otherwise\r
  */\r
-bool DHCPClientApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination)\r
+static bool DHCPClientApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination)\r
 {\r
        /* Look through the incoming DHCP packet's options list for the requested option */\r
        while (*DHCPOptionList != DHCP_OPTION_END)\r
index 947151d..702f797 100644 (file)
                void DHCPClientApp_Init(void);\r
                void DHCPClientApp_Callback(void);\r
                \r
-               uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState);\r
-               uint8_t  DHCPClientApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData);\r
-               bool     DHCPClientApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination);\r
-               \r
+               #if defined(INCLUDE_FROM_DHCPCLIENTAPP_C)\r
+                       static uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType,\r
+                                                                    uip_udp_appstate_t* AppState);\r
+                       static uint8_t  DHCPClientApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen,\r
+                                                               void* OptionData);\r
+                       static bool     DHCPClientApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination);\r
+               #endif\r
 #endif\r
index 1a1d2c4..08d8494 100644 (file)
@@ -56,12 +56,12 @@ const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
                                      "Content-Type: text/plain\r\n\r\n"\r
                                      "Error 404: File Not Found: /";\r
 \r
-/** Default MIME type sent if no other MIME type can be determined. */\r
-const char PROGMEM DefaultMIMEType[] = "text/plain";\r
-\r
 /** Default filename to fetch when a directory is requested */\r
 const char PROGMEM DefaultDirFileName[] = "index.htm";\r
 \r
+/** Default MIME type sent if no other MIME type can be determined. */\r
+const char PROGMEM DefaultMIMEType[] = "text/plain";\r
+\r
 /** List of MIME types for each supported file extension. */\r
 const MIME_Type_t MIMETypes[] =\r
        {\r
@@ -174,7 +174,7 @@ static void HTTPServerApp_OpenRequestedFile(void)
        char* RequestedFileName = strtok(NULL, " ");\r
                        \r
        /* Must be a GET request, abort otherwise */\r
-       if (strcmp(RequestToken, "GET") != 0)\r
+       if (strcmp_P(RequestToken, PSTR("GET")) != 0)\r
        {\r
                uip_abort();\r
                return;\r
@@ -257,7 +257,7 @@ static void HTTPServerApp_SendResponseHeader(void)
        }\r
        \r
        /* Add the end-of-line terminator and end-of-headers terminator after the MIME type */\r
-       strcpy(&AppData[strlen(AppData)], "\r\n\r\n");\r
+       strcpy_P(&AppData[strlen(AppData)], PSTR("\r\n\r\n"));\r
        \r
        /* Send the MIME header to the receiving client */\r
        uip_send(AppData, strlen(AppData));\r
index d1f1d7f..2855f8d 100644 (file)
@@ -28,6 +28,8 @@
   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
@@ -114,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
@@ -144,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
index d5ad515..45f8a6a 100644 (file)
@@ -80,7 +80,9 @@ void uIPManagement_Init(void)
        HTTPServerApp_Init();\r
        \r
        /* TELNET Server Initialization */\r
+       #if defined(ENABLE_TELNET_SERVER)\r
        TELNETServerApp_Init();\r
+       #endif\r
 }\r
 \r
 /** uIP Management function. This function manages the uIP stack when called while an RNDIS device has been\r
@@ -106,9 +108,11 @@ void uIPManagement_TCPCallback(void)
                case HTONS(HTTP_SERVER_PORT):\r
                        HTTPServerApp_Callback();\r
                        break;\r
+               #if defined(ENABLE_TELNET_SERVER)\r
                case HTONS(TELNET_SERVER_PORT):\r
                        TELNETServerApp_Callback();\r
                        break;\r
+               #endif\r
        }\r
 }\r
 \r
index 05d0b1f..3c0c48e 100644 (file)
  *    <td><b>Description:</b></td>\r
  *   </tr>\r
  *   <tr>\r
+ *    <td>ENABLE_TELNET_SERVER</td>\r
+ *    <td>Makefile CDEFS</td>\r
+ *    <td>When defined, this enables the TELNET server in addition to the HTTP webserver, which listens for incomming connections\r
+ *        and processes user commands.</td>\r
+ *   </tr>\r
+ *   <tr>\r
  *    <td>ENABLE_DHCP_CLIENT</td>\r
  *    <td>Makefile CDEFS</td>\r
  *    <td>When defined, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.</td>\r
index edd2824..36adb1d 100644 (file)
@@ -201,6 +201,7 @@ CSTANDARD = -std=gnu99
 # Place -D or -U options here for C sources\r
 CDEFS  = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) $(LUFA_OPTS)\r
 CDEFS += -DENABLE_DHCP_CLIENT\r
+CDEFS += -DENABLE_TELNET_SERVER\r
 CDEFS += -DMAX_URI_LENGTH=50\r
 \r
 CDEFS += -DUIP_CONF_UDP="defined(ENABLE_DHCP_CLIENT)" -DUIP_CONF_TCP=1 -DUIP_CONF_UDP_CONNS=1 -DUIP_CONF_MAX_CONNECTIONS=3\r