Adaptation of the HttpServer by user yueee_yt. This version has improved handling of the HTTP headers (**NOTE**: There are limitations with this implementation and it is not fully functional. Use it only as a starting point.)
Dependents: DMSupport DMSupport DMSupport DMSupport
Fork of DM_HttpServer by
Diff: Handler/FSHandler.cpp
- Revision:
- 6:7b3320c34654
- Parent:
- 5:b8f6a11c70db
- Child:
- 7:ee7af5de4b95
--- a/Handler/FSHandler.cpp Sat Feb 22 05:51:59 2014 +0000 +++ b/Handler/FSHandler.cpp Tue Dec 02 15:04:43 2014 +0000 @@ -20,6 +20,7 @@ //#define _DEBUG_FS_HANDLER #include "FSHandler.h" +#include "DMBoard.h" #define CHUNK_SIZE 128 @@ -32,20 +33,20 @@ FSHandler::~FSHandler() { #ifdef _DEBUG_FS_HANDLER - printf("\r\n+++FSHandler destroy\r\n"); + DMBoard::instance().logger()-> printf("\r\n+++FSHandler destroy\r\n"); #endif if(m_fp){ #ifdef _DEBUG_FS_HANDLER - printf("\r\n+++FSHandler fclose start\r\n"); + DMBoard::instance().logger()->printf("\r\n+++FSHandler fclose start\r\n"); #endif fclose(m_fp); #ifdef _DEBUG_FS_HANDLER - printf("\r\n+++FSHandler fclose end\r\n"); + DMBoard::instance().logger()->printf("\r\n+++FSHandler fclose end\r\n"); #endif } #ifdef _DEBUG_FS_HANDLER - printf("\r\nHandler destroyed\r\n"); + DMBoard::instance().logger()->printf("\r\nHandler destroyed\r\n"); #endif } @@ -60,7 +61,7 @@ void FSHandler::doGet() { #ifdef _DEBUG_FS_HANDLER - printf("\r\nIn FSHandler::doGet() - rootPath=%s, path=%s\r\n", rootPath().c_str(), path().c_str()); + DMBoard::instance().logger()->printf("\r\nIn FSHandler::doGet() - rootPath=%s, path=%s\r\n", rootPath().c_str(), path().c_str()); #endif //FIXME: Translate path to local/path string checkedRootPath = rootPath(); @@ -73,7 +74,7 @@ filePath += DEFAULT_PAGE; } #ifdef _DEBUG_FS_HANDLER - printf("Trying to open %s\n", filePath.c_str()); + DMBoard::instance().logger()->printf("Trying to open %s\n", filePath.c_str()); #endif m_fp = fopen(filePath.c_str(), "r"); //FIXME: if null, error 404 @@ -85,7 +86,7 @@ respHeaders()["Content-Type"] = "text/html"; respHeaders()["Connection"] = "close"; writeData(msg,strlen(msg)); //Only send header - printf("\r\nExit FSHandler::doGet() w Error 404\r\n"); + DMBoard::instance().logger()->printf("\r\nExit FSHandler::doGet() w Error 404\r\n"); return; } @@ -97,7 +98,7 @@ respHeaders()["Connection"] = "close"; onWriteable(); #ifdef _DEBUG_FS_HANDLER - printf("\r\nExit SimpleHandler::doGet()\r\n"); + DMBoard::instance().logger()->printf("\r\nExit SimpleHandler::doGet()\r\n"); #endif } @@ -119,7 +120,7 @@ void FSHandler::onWriteable() //Data has been written & buf is free { #ifdef _DEBUG_FS_HANDLER - printf("\r\nFSHandler::onWriteable() event\r\n"); + DMBoard::instance().logger()->printf("\r\nFSHandler::onWriteable() event\r\n"); #endif if(m_err404) { //Error has been served, now exit @@ -134,7 +135,7 @@ int writtenLen = writeData(rBuf, len); if(writtenLen < 0) { //Socket error #ifdef _DEBUG_FS_HANDLER - printf("FSHandler: Socket error %d\n", writtenLen); + DMBoard::instance().logger()->printf("FSHandler: Socket error %d\n", writtenLen); #endif /** Not Work if(writtenLen == TCPSOCKET_MEM) { @@ -161,6 +162,7 @@ void FSHandler::onClose() //Connection is closing { + DMBoard::instance().logger()->printf("FSHandler: onClose() event\r\n"); /** #ifdef _DEBUG_FS_HANDLER printf("FSHandler: onClose start \r\n");