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:
- 17:ce5845164001
- Parent:
- 16:c3920b5b8572
diff -r c3920b5b8572 -r ce5845164001 handlers/Filehandler.cpp --- a/handlers/Filehandler.cpp Mon Mar 19 09:25:32 2018 +0000 +++ b/handlers/Filehandler.cpp Fri Mar 23 07:39:28 2018 +0000 @@ -2,6 +2,7 @@ //#ifndef DEBUG #define FILE_HANDLER_DEBUG //#endif +LocalFileSystem local("local"); namespace FILE_HANDLER { @@ -41,8 +42,6 @@ } using namespace FILE_HANDLER; -LocalFileSystem local("local"); - FileHandler::FileHandler() { fullpath = NULL; @@ -64,11 +63,11 @@ { FILE *tmp; - DEBUG_PRINT_LINE("\r\n" - "fp: %d@FileHandler::open\r\n", fp); + DEBUG_PRINT_LINE("fp: %d", fp); if (fullpath != NULL) free(fullpath); + // Allocating memory for fullpath; + // [[+ strlen("index.htm") + 1]] at the end of line is ONLY a MARGIN allowed for concatenating the string. fullpath = (char*)malloc(sizeof(char) * (strlen("/local/") + strlen(arg_filepath) + strlen("index.htm") + 1)); - DEBUG_PRINT_LINE("fp: %d@FileHandler::open\r\n", fp); // Path formatting if (arg_filepath[0] == '/') { @@ -76,23 +75,33 @@ } 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"); + DEBUG_PRINT_LINE("full-file-path: %s", fullpath); // store the file name part into a pointer filename = strrchr(fullpath, '/'); - if(filename != NULL) filename++; // remove '/' and just get only the file name. + // remove '/' and just get only the file name. + if(filename != NULL) filename++; // store the suffix part to a pointer suffix = strchr(filename, '.'); - if(suffix != NULL) suffix++; // remove '.' and just get only the suffix. -#ifdef DEBUG - //////printf("full path: %s\r\nfilename: %s\r\nsuffix: %s\r\n", getFullpath(), getFilename(), getSuffix()); -#endif + // remove '.' and just get only the suffix. + if(suffix != NULL) suffix++; + DEBUG_PRINT_LINE("!!Public function check..."); + DEBUG_PRINT_LINE(" full path: %s", getFullpath()); + DEBUG_PRINT_LINE(" filename : %s", getFilename()); + DEBUG_PRINT_LINE(" suffix : %s", getSuffix()); + DEBUG_PRINT_LINE("...DONE!!"); + DEBUG_PRINT_LINE("fopen(...)"); + DEBUG_PRINT_LINE(" path: %s", fullpath); + DEBUG_PRINT_LINE(" mode: %s", arg_mode); fp = fopen(fullpath, arg_mode); -#ifdef DEBUG - //////////printf("file opened@FileHandler::open\r\n"); -#endif + if(fp != NULL) { + DEBUG_PRINT_LINE("file opened"); + DEBUG_PRINT_LINE("fp: %d", fp); + } else { + DEBUG_PRINT_LINE("Something is wrong @fopen(...)"); + } // mesure file size file_size = 0; tmp = fp;