The lib with which to make LPC1768 a simple HTTP server. This have not yet implemented. fopen() DOESN'T WORK after EthernetInterface::connect() is called as using mbed-os 5.4~. See also https://os.mbed.com/questions/80658/HardFault-occurs-when-fopen-is-called-af/ or https://github.com/ARMmbed/mbed-os/issues/6578 and https://github.com/ARMmbed/mbed-os/issues/6624
Fork of HTTP_SERVER by
Diff: handlers/Filehandler.cpp
- Revision:
- 16:c3920b5b8572
- Parent:
- 11:0ee7d100db24
- Child:
- 17:ce5845164001
--- a/handlers/Filehandler.cpp Fri Mar 16 23:17:28 2018 +0000 +++ b/handlers/Filehandler.cpp Mon Mar 19 09:25:32 2018 +0000 @@ -1,7 +1,46 @@ #include "FileHandler.h" -#ifndef DEBUG -//#define DEBUG +//#ifndef DEBUG +#define FILE_HANDLER_DEBUG +//#endif + +namespace FILE_HANDLER +{ +void DEBUG_PRINT_NAME() +{ +#ifdef FILE_HANDLER_DEBUG + printf("(DEBUG LINE: FILE_HANDLER) "); +#endif +} + +void DEBUG_PRINT_LINE(const char* arg_line) +{ +#ifdef FILE_HANDLER_DEBUG + DEBUG_PRINT_NAME(); + printf(arg_line); + printf("\r\n"); #endif +} +template<typename T> +void DEBUG_PRINT_LINE(const char* arg_line, T arg_t) +{ +#ifdef FILE_HANDLER_DEBUG + DEBUG_PRINT_NAME(); + printf(arg_line, arg_t); + printf("\r\n"); +#endif +} +template<typename T1, typename T2> +void DEBUG_PRINT_LINE(const char* arg_line, T1 arg_t1, T2 arg_t2) +{ +#ifdef FILE_HANDLER_DEBUG + DEBUG_PRINT_NAME(); + printf(arg_line, arg_t1, arg_t2); + printf("\r\n"); +#endif +} +} +using namespace FILE_HANDLER; + LocalFileSystem local("local"); FileHandler::FileHandler() @@ -25,11 +64,11 @@ { FILE *tmp; - //////printf("\r\n" - // "fp: %d@FileHandler::open\r\n", fp); + DEBUG_PRINT_LINE("\r\n" + "fp: %d@FileHandler::open\r\n", fp); if (fullpath != NULL) free(fullpath); fullpath = (char*)malloc(sizeof(char) * (strlen("/local/") + strlen(arg_filepath) + strlen("index.htm") + 1)); - //////printf("fp: %d@FileHandler::open\r\n", fp); + DEBUG_PRINT_LINE("fp: %d@FileHandler::open\r\n", fp); // Path formatting if (arg_filepath[0] == '/') { @@ -37,10 +76,11 @@ } else { sprintf(fullpath, "/local/%s", arg_filepath); } + DEBUG_PRINT_LINE("full-file-path: %s", fullpath); // if the argument has no file name but directory, defalt settiing. if (fullpath[strlen(fullpath) - 1] == '/') strcat(fullpath, "index.htm"); - // store the file name part to a pointer + // store the file name part into a pointer filename = strrchr(fullpath, '/'); if(filename != NULL) filename++; // remove '/' and just get only the file name. // store the suffix part to a pointer