Add a TELNET server to the webserver project, which currently can list active TCP...
[pub/USBasp.git] / Projects / Webserver / Lib / HTTPServerApp.c
index 1836688..9a70dad 100644 (file)
@@ -98,36 +98,36 @@ void HTTPServerApp_Callback(void)
        if (uip_aborted() || uip_timedout() || uip_closed())\r
        {\r
                /* Connection is being terminated for some reason - close file handle */\r
        if (uip_aborted() || uip_timedout() || uip_closed())\r
        {\r
                /* Connection is being terminated for some reason - close file handle */\r
-               f_close(&AppState->FileHandle);\r
-               AppState->FileOpen = false;\r
+               f_close(&AppState->HTTPServer.FileHandle);\r
+               AppState->HTTPServer.FileOpen = false;\r
                \r
                /* Lock to the closed state so that no further processing will occur on the connection */\r
                \r
                /* Lock to the closed state so that no further processing will occur on the connection */\r
-               AppState->CurrentState  = WEBSERVER_STATE_Closed;\r
-               AppState->NextState     = WEBSERVER_STATE_Closed;\r
+               AppState->HTTPServer.CurrentState  = WEBSERVER_STATE_Closed;\r
+               AppState->HTTPServer.NextState     = WEBSERVER_STATE_Closed;\r
        }\r
 \r
        if (uip_connected())\r
        {\r
                /* New connection - initialize connection state values */\r
        }\r
 \r
        if (uip_connected())\r
        {\r
                /* New connection - initialize connection state values */\r
-               AppState->CurrentState  = WEBSERVER_STATE_OpenRequestedFile;\r
-               AppState->NextState     = WEBSERVER_STATE_OpenRequestedFile;\r
-               AppState->FileOpen      = false;\r
-               AppState->ACKedFilePos  = 0;\r
-               AppState->SentChunkSize = 0;\r
+               AppState->HTTPServer.CurrentState  = WEBSERVER_STATE_OpenRequestedFile;\r
+               AppState->HTTPServer.NextState     = WEBSERVER_STATE_OpenRequestedFile;\r
+               AppState->HTTPServer.FileOpen      = false;\r
+               AppState->HTTPServer.ACKedFilePos  = 0;\r
+               AppState->HTTPServer.SentChunkSize = 0;\r
        }\r
 \r
        if (uip_acked())\r
        {\r
                /* Add the amount of ACKed file data to the total sent file bytes counter */\r
        }\r
 \r
        if (uip_acked())\r
        {\r
                /* Add the amount of ACKed file data to the total sent file bytes counter */\r
-               AppState->ACKedFilePos += AppState->SentChunkSize;\r
+               AppState->HTTPServer.ACKedFilePos += AppState->HTTPServer.SentChunkSize;\r
 \r
                /* Progress to the next state once the current state's data has been ACKed */\r
 \r
                /* Progress to the next state once the current state's data has been ACKed */\r
-               AppState->CurrentState = AppState->NextState;\r
+               AppState->HTTPServer.CurrentState = AppState->HTTPServer.NextState;\r
        }\r
 \r
        if (uip_rexmit() || uip_acked() || uip_newdata() || uip_connected() || uip_poll())\r
        {\r
        }\r
 \r
        if (uip_rexmit() || uip_acked() || uip_newdata() || uip_connected() || uip_poll())\r
        {\r
-               switch (AppState->CurrentState)\r
+               switch (AppState->HTTPServer.CurrentState)\r
                {\r
                        case WEBSERVER_STATE_OpenRequestedFile:\r
                                HTTPServerApp_OpenRequestedFile();\r
                {\r
                        case WEBSERVER_STATE_OpenRequestedFile:\r
                                HTTPServerApp_OpenRequestedFile();\r
@@ -144,7 +144,7 @@ void HTTPServerApp_Callback(void)
                        case WEBSERVER_STATE_Closing:\r
                                uip_close();\r
                                \r
                        case WEBSERVER_STATE_Closing:\r
                                uip_close();\r
                                \r
-                               AppState->NextState = WEBSERVER_STATE_Closed;\r
+                               AppState->HTTPServer.NextState = WEBSERVER_STATE_Closed;\r
                                break;\r
                }                 \r
        }               \r
                                break;\r
                }                 \r
        }               \r
@@ -175,19 +175,19 @@ static void HTTPServerApp_OpenRequestedFile(void)
        \r
        /* If the requested filename has more that just the leading '/' path in it, copy it over */\r
        if (strlen(RequestedFileName) > 1)\r
        \r
        /* If the requested filename has more that just the leading '/' path in it, copy it over */\r
        if (strlen(RequestedFileName) > 1)\r
-         strncpy(AppState->FileName, &RequestedFileName[1], (sizeof(AppState->FileName) - 1));\r
+         strncpy(AppState->HTTPServer.FileName, &RequestedFileName[1], (sizeof(AppState->HTTPServer.FileName) - 1));\r
        else\r
        else\r
-         strcpy(AppState->FileName, "index.htm");\r
+         strcpy(AppState->HTTPServer.FileName, "index.htm");\r
 \r
        /* Ensure filename is null-terminated */\r
 \r
        /* Ensure filename is null-terminated */\r
-       AppState->FileName[(sizeof(AppState->FileName) - 1)] = 0x00;\r
+       AppState->HTTPServer.FileName[(sizeof(AppState->HTTPServer.FileName) - 1)] = 0x00;\r
        \r
        /* Try to open the file from the Dataflash disk */\r
        \r
        /* Try to open the file from the Dataflash disk */\r
-       AppState->FileOpen     = (f_open(&AppState->FileHandle, AppState->FileName, FA_OPEN_EXISTING | FA_READ) == FR_OK);\r
+       AppState->HTTPServer.FileOpen     = (f_open(&AppState->HTTPServer.FileHandle, AppState->HTTPServer.FileName, FA_OPEN_EXISTING | FA_READ) == FR_OK);\r
 \r
        /* Lock to the SendResponseHeader state until connection terminated */\r
 \r
        /* Lock to the SendResponseHeader state until connection terminated */\r
-       AppState->CurrentState = WEBSERVER_STATE_SendResponseHeader;\r
-       AppState->NextState    = WEBSERVER_STATE_SendResponseHeader;\r
+       AppState->HTTPServer.CurrentState = WEBSERVER_STATE_SendResponseHeader;\r
+       AppState->HTTPServer.NextState    = WEBSERVER_STATE_SendResponseHeader;\r
 }\r
 \r
 /** HTTP Server State handler for the HTTP Response Header Send state. This state manages the transmission of\r
 }\r
 \r
 /** HTTP Server State handler for the HTTP Response Header Send state. This state manages the transmission of\r
@@ -202,15 +202,15 @@ static void HTTPServerApp_SendResponseHeader(void)
        uint16_t HeaderLength;\r
 \r
        /* Determine which HTTP header should be sent to the client */\r
        uint16_t HeaderLength;\r
 \r
        /* Determine which HTTP header should be sent to the client */\r
-       if (AppState->FileOpen)\r
+       if (AppState->HTTPServer.FileOpen)\r
        {\r
                HeaderToSend = HTTP200Header;\r
        {\r
                HeaderToSend = HTTP200Header;\r
-               AppState->NextState = WEBSERVER_STATE_SendMIMETypeHeader;\r
+               AppState->HTTPServer.NextState = WEBSERVER_STATE_SendMIMETypeHeader;\r
        }\r
        else\r
        {\r
                HeaderToSend = HTTP404Header;\r
        }\r
        else\r
        {\r
                HeaderToSend = HTTP404Header;\r
-               AppState->NextState = WEBSERVER_STATE_Closing;\r
+               AppState->HTTPServer.NextState = WEBSERVER_STATE_Closing;\r
        }\r
 \r
        /* Copy over the HTTP response header and send it to the receiving client */\r
        }\r
 \r
        /* Copy over the HTTP response header and send it to the receiving client */\r
@@ -227,7 +227,7 @@ static void HTTPServerApp_SendMIMETypeHeader(void)
        uip_tcp_appstate_t* const AppState    = &uip_conn->appstate;\r
        char*               const AppData     = (char*)uip_appdata;\r
 \r
        uip_tcp_appstate_t* const AppState    = &uip_conn->appstate;\r
        char*               const AppData     = (char*)uip_appdata;\r
 \r
-       char*    Extension        = strpbrk(AppState->FileName, ".");\r
+       char*    Extension        = strpbrk(AppState->HTTPServer.FileName, ".");\r
        uint16_t MIMEHeaderLength = 0;\r
 \r
        /* Check to see if a file extension was found for the requested filename */\r
        uint16_t MIMEHeaderLength = 0;\r
 \r
        /* Check to see if a file extension was found for the requested filename */\r
@@ -261,7 +261,7 @@ static void HTTPServerApp_SendMIMETypeHeader(void)
        uip_send(AppData, MIMEHeaderLength);\r
        \r
        /* When the MIME header is ACKed, progress to the data send stage */\r
        uip_send(AppData, MIMEHeaderLength);\r
        \r
        /* When the MIME header is ACKed, progress to the data send stage */\r
-       AppState->NextState = WEBSERVER_STATE_SendData;\r
+       AppState->HTTPServer.NextState = WEBSERVER_STATE_SendData;\r
 }\r
 \r
 /** HTTP Server State handler for the Data Send state. This state manages the transmission of file chunks\r
 }\r
 \r
 /** HTTP Server State handler for the Data Send state. This state manages the transmission of file chunks\r
@@ -276,14 +276,14 @@ static void HTTPServerApp_SendData(void)
        uint16_t MaxSegmentSize = uip_mss();\r
 \r
        /* Return file pointer to the last ACKed position */\r
        uint16_t MaxSegmentSize = uip_mss();\r
 \r
        /* Return file pointer to the last ACKed position */\r
-       f_lseek(&AppState->FileHandle, AppState->ACKedFilePos);\r
+       f_lseek(&AppState->HTTPServer.FileHandle, AppState->HTTPServer.ACKedFilePos);\r
        \r
        /* Read the next chunk of data from the open file */\r
        \r
        /* Read the next chunk of data from the open file */\r
-       f_read(&AppState->FileHandle, AppData, MaxSegmentSize, &AppState->SentChunkSize);\r
+       f_read(&AppState->HTTPServer.FileHandle, AppData, MaxSegmentSize, &AppState->HTTPServer.SentChunkSize);\r
        \r
        /* Send the next file chunk to the receiving client */\r
        \r
        /* Send the next file chunk to the receiving client */\r
-       uip_send(AppData, AppState->SentChunkSize);\r
+       uip_send(AppData, AppState->HTTPServer.SentChunkSize);\r
                        \r
        /* Check if we are at the last chunk of the file, if so next ACK should close the connection */\r
                        \r
        /* Check if we are at the last chunk of the file, if so next ACK should close the connection */\r
-       AppState->NextState = (MaxSegmentSize != AppState->SentChunkSize) ? WEBSERVER_STATE_Closing : WEBSERVER_STATE_SendData;\r
+       AppState->HTTPServer.NextState = (MaxSegmentSize != AppState->HTTPServer.SentChunkSize) ? WEBSERVER_STATE_Closing : WEBSERVER_STATE_SendData;\r
 }\r
 }\r