Remove non-functional maintenance link check.
[pub/USBasp.git] / Projects / Webserver / Lib / HTTPServerApp.c
index 3ab3003..9ee514d 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2012.
 
   dean [at] fourwalledcubicle [dot] com
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -47,7 +47,7 @@ const char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"
                                      "Content-Type: ";
 
 /** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given
                                      "Content-Type: ";
 
 /** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given
- *  given URL is invalid, and gives extra error information.
+ *  URL is invalid, and gives extra error information.
  */
 const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
                                      "Server: LUFA " LUFA_VERSION_STRING "\r\n"
  */
 const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
                                      "Server: LUFA " LUFA_VERSION_STRING "\r\n"
@@ -181,22 +181,16 @@ static void HTTPServerApp_OpenRequestedFile(void)
        }
 
        /* Copy over the requested filename */
        }
 
        /* Copy over the requested filename */
-       strncpy(AppState->HTTPServer.FileName, &RequestedFileName[1], (sizeof(AppState->HTTPServer.FileName) - 1));
-
-       /* Ensure filename is null-terminated */
-       AppState->HTTPServer.FileName[sizeof(AppState->HTTPServer.FileName) - 1] = 0x00;
+       strlcpy(AppState->HTTPServer.FileName, &RequestedFileName[1], sizeof(AppState->HTTPServer.FileName));
 
        /* Determine the length of the URI so that it can be checked to see if it is a directory */
        uint8_t FileNameLen = strlen(AppState->HTTPServer.FileName);
 
        /* If the URI is a directory, append the default filename */
 
        /* Determine the length of the URI so that it can be checked to see if it is a directory */
        uint8_t FileNameLen = strlen(AppState->HTTPServer.FileName);
 
        /* If the URI is a directory, append the default filename */
-       if (AppState->HTTPServer.FileName[FileNameLen - 1] == '/')
+       if ((AppState->HTTPServer.FileName[FileNameLen - 1] == '/') || !(FileNameLen))
        {
        {
-               strncpy_P(&AppState->HTTPServer.FileName[FileNameLen], DefaultDirFileName,
+               strlcpy_P(&AppState->HTTPServer.FileName[FileNameLen], DefaultDirFileName,
                          (sizeof(AppState->HTTPServer.FileName) - FileNameLen));
                          (sizeof(AppState->HTTPServer.FileName) - FileNameLen));
-
-               /* Ensure altered filename is still null-terminated */
-               AppState->HTTPServer.FileName[sizeof(AppState->HTTPServer.FileName) - 1] = 0x00;
        }
 
        /* Try to open the file from the Dataflash disk */
        }
 
        /* Try to open the file from the Dataflash disk */
@@ -224,7 +218,7 @@ static void HTTPServerApp_SendResponseHeader(void)
        {
                /* Copy over the HTTP 404 response header and send it to the receiving client */
                strcpy_P(AppData, HTTP404Header);
        {
                /* Copy over the HTTP 404 response header and send it to the receiving client */
                strcpy_P(AppData, HTTP404Header);
-               strcpy(&AppData[strlen(AppData)], AppState->HTTPServer.FileName);
+               strcat(AppData, AppState->HTTPServer.FileName);
                uip_send(AppData, strlen(AppData));
 
                AppState->HTTPServer.NextState = WEBSERVER_STATE_Closing;
                uip_send(AppData, strlen(AppData));
 
                AppState->HTTPServer.NextState = WEBSERVER_STATE_Closing;
@@ -242,7 +236,7 @@ static void HTTPServerApp_SendResponseHeader(void)
                {
                        if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0)
                        {
                {
                        if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0)
                        {
-                               strcpy(&AppData[strlen(AppData)], MIMETypes[i].MIMEType);
+                               strcat(AppData, MIMETypes[i].MIMEType);
                                FoundMIMEType = true;
                                break;
                        }
                                FoundMIMEType = true;
                                break;
                        }
@@ -253,11 +247,11 @@ static void HTTPServerApp_SendResponseHeader(void)
        if (!(FoundMIMEType))
        {
                /* MIME type not found - copy over the default MIME type */
        if (!(FoundMIMEType))
        {
                /* MIME type not found - copy over the default MIME type */
-               strcpy_P(&AppData[strlen(AppData)], DefaultMIMEType);
+               strcat_P(AppData, DefaultMIMEType);
        }
 
        /* Add the end-of-line terminator and end-of-headers terminator after the MIME type */
        }
 
        /* Add the end-of-line terminator and end-of-headers terminator after the MIME type */
-       strcpy_P(&AppData[strlen(AppData)], PSTR("\r\n\r\n"));
+       strcat_P(AppData, PSTR("\r\n\r\n"));
 
        /* Send the MIME header to the receiving client */
        uip_send(AppData, strlen(AppData));
 
        /* Send the MIME header to the receiving client */
        uip_send(AppData, strlen(AppData));