diff --git a/Debug/main.cpp.o b/Debug/main.cpp.o index 18c9f5e..41ff6db 100644 Binary files a/Debug/main.cpp.o and b/Debug/main.cpp.o differ diff --git a/Debug/main.cpp.o.d b/Debug/main.cpp.o.d index 2c79f2e..2223d3f 100644 --- a/Debug/main.cpp.o.d +++ b/Debug/main.cpp.o.d @@ -9,9 +9,9 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ ../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \ ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h \ HTTPSessions.h ../ServerCore/Header.h ../ServerCore/Response.h \ - PageList.h ../ServerCore/CommandList.h __index.h __setupadmin.h \ - __favicon_ico.h HTTPHandler.h ../ServerCore/Command.h \ - ../ServerCore/Session.h + PageList.h ../ServerCore/CommandList.h ../ServerCore/Session.h __index.h \ + HTTPPage.h HTTPSession.h __setupadmin.h __favicon_ico.h HTTPHandler.h \ + ../ServerCore/Command.h ../ServerCore/includes: @@ -71,8 +71,14 @@ PageList.h: ../ServerCore/CommandList.h: +../ServerCore/Session.h: + __index.h: +HTTPPage.h: + +HTTPSession.h: + __setupadmin.h: __favicon_ico.h: @@ -80,5 +86,3 @@ __favicon_ico.h: HTTPHandler.h: ../ServerCore/Command.h: - -../ServerCore/Session.h: diff --git a/HTTPHandler.cpp b/HTTPHandler.cpp index 8f09e79..75ae597 100644 --- a/HTTPHandler.cpp +++ b/HTTPHandler.cpp @@ -15,7 +15,7 @@ namespace http { HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(header, response); std::stringstream content; - if(((HTTPService &)session->service).pageList.processRequest(header.getPath() + " ", session, content)) { + if(((HTTPService &)session->service).pageList.processRequest(header.getPath() + " ", session, httpSession, content)) { response.setProtocol(header.requestProtocol()); response.setCode("200"); response.setText("OK"); diff --git a/HTTPPage.h b/HTTPPage.h new file mode 100644 index 0000000..d915524 --- /dev/null +++ b/HTTPPage.h @@ -0,0 +1,19 @@ +#ifndef __HTTPPage_h__ +#define __HTTPPage_h__ + +#include "HTTPSession.h" + +namespace http { + + class HTTPPage : public core::Object { + + public: + virtual int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) { + return false; + } + + }; + +} + +#endif diff --git a/HTTPPageList.cpp b/HTTPPageList.cpp new file mode 100644 index 0000000..fc3a778 --- /dev/null +++ b/HTTPPageList.cpp @@ -0,0 +1,25 @@ +#include "HTTPPageList.h" + +namespace http { + + bool HTTPPageList::processRequest(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) { + for(auto *page : pages) { + if(page->check(request)) { + page->processCommand(request, session, httpSession, data); + return true; + } + } + return false; + } + + void HTTPPageList::add(HTTPPage &page, std::string name) { + page.setName(name); + pages.push_back(&command); + + } + + void HTTPPageList::remove(HTTPPage &page) {} + +} + + diff --git a/HTTPPageList.h b/HTTPPageList.h new file mode 100644 index 0000000..5aceb2a --- /dev/null +++ b/HTTPPageList.h @@ -0,0 +1,38 @@ +#ifndef __HTTPPageList_h__ +#define __HTTPPageList_h__ + +#include "Session.h" +#include "__index.h" +#include "__setupadmin.h" +#include "__favicon_ico.h" + +namespace http { + + class HTTPPageList { + + public: + HTTPPageList() { + add(index, "/ "); + add(setupadmin, "/setupadmin "); + add(favicon_ico, "/favicon.ico"); + } + + bool processRequest(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data); + + void add(HTTPPage &page, std::string name = ""); + + void remove(HTTPPage &page); + + protected: + std::vector pages; + + private: + __index index; + __setupadmin setupadmin; + __favicon_ico favicon_ico; + + }; + +} + +#endif diff --git a/HTTPServer.mk b/HTTPServer.mk index 6ee1b92..3065547 100644 --- a/HTTPServer.mk +++ b/HTTPServer.mk @@ -5,16 +5,16 @@ ## Debug ProjectName :=HTTPServer ConfigurationName :=Debug -WorkspacePath :=/home/bradarant/barant -ProjectPath :=/home/bradarant/barant/HTTPServer +WorkspacePath :=/home/barant +ProjectPath :=/home/barant/barant/HTTPServer IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := -User :=Brad Arant -Date :=31/05/19 -CodeLitePath :=/home/bradarant/.codelite +User :=root +Date :=05/31/19 +CodeLitePath :=/home/barant/.codelite LinkerName :=/usr/bin/x86_64-linux-gnu-g++ SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC ObjectSuffix :=.o @@ -60,7 +60,7 @@ AS := /usr/bin/x86_64-linux-gnu-as ## User defined environment variables ## CodeLiteDir:=/usr/share/codelite -Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) +Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix) @@ -92,7 +92,7 @@ PreBuild: ## Objects ## $(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/HTTPServer/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp @@ -100,7 +100,7 @@ $(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix): HTTPSession.cpp $(IntermediateDirectory)/HTTPSession.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/HTTPServer/HTTPSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/HTTPSession.cpp$(DependSuffix): HTTPSession.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPSession.cpp$(DependSuffix) -MM HTTPSession.cpp @@ -108,7 +108,7 @@ $(IntermediateDirectory)/HTTPSession.cpp$(PreprocessSuffix): HTTPSession.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPSession.cpp$(PreprocessSuffix) HTTPSession.cpp $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix): HTTPSessions.cpp $(IntermediateDirectory)/HTTPSessions.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/HTTPServer/HTTPSessions.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPSessions.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/HTTPSessions.cpp$(DependSuffix): HTTPSessions.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPSessions.cpp$(DependSuffix) -MM HTTPSessions.cpp @@ -116,13 +116,21 @@ $(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix): HTTPSessions.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix) HTTPSessions.cpp $(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix): HTTPHandler.cpp $(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/HTTPServer/HTTPHandler.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPHandler.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix): HTTPHandler.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix) -MM HTTPHandler.cpp $(IntermediateDirectory)/HTTPHandler.cpp$(PreprocessSuffix): HTTPHandler.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPHandler.cpp$(PreprocessSuffix) HTTPHandler.cpp +$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix): HTTPPageList.cpp $(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPPageList.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix): HTTPPageList.cpp + @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix) -MM HTTPPageList.cpp + +$(IntermediateDirectory)/HTTPPageList.cpp$(PreprocessSuffix): HTTPPageList.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPPageList.cpp$(PreprocessSuffix) HTTPPageList.cpp + -include $(IntermediateDirectory)/*$(DependSuffix) ## diff --git a/HTTPServer.project b/HTTPServer.project index 2192b14..4d284f3 100644 --- a/HTTPServer.project +++ b/HTTPServer.project @@ -13,8 +13,10 @@ - + + + diff --git a/HTTPService.h b/HTTPService.h index 3ef48de..375ba21 100644 --- a/HTTPService.h +++ b/HTTPService.h @@ -3,7 +3,7 @@ #include "Service.h" #include "HTTPSessions.h" -#include "PageList.h" +#include "HTTPPageList.h" #include "Exception.h" #include "HTTPHandler.h" @@ -18,7 +18,7 @@ namespace http { } HTTPSessions httpSessions; - PageList pageList; + HTTPPageList pageList; private: HTTPHandler getHandler; diff --git a/HTTPSessions.cpp b/HTTPSessions.cpp index 695a148..197bb9a 100644 --- a/HTTPSessions.cpp +++ b/HTTPSessions.cpp @@ -12,7 +12,6 @@ namespace http { } HTTPSession * HTTPSessions::findSessionById(std::string sessionId, core::Response &response) { - core::Log(core::LOG_DEBUG_1) << "Session Id: " << sessionId << ":" << sessionId.length(); HTTPSession *httpSession; if(sessionId.length() > 0) { httpSession = (HTTPSession *)sessions.find(sessionId)->second; diff --git a/PageList.h b/PageList.h deleted file mode 100644 index 3dd5bf5..0000000 --- a/PageList.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __PageList_h__ -#define __PageList_h__ - -#include "CommandList.h" -#include "__index.h" -#include "__setupadmin.h" -#include "__favicon_ico.h" - -namespace http { - - class PageList : public core::CommandList { - - public: - PageList() { - add(index, "/ "); - add(setupadmin, "/setupadmin "); - add(favicon_ico, "/favicon.ico"); - } - - private: - __index index; - __setupadmin setupadmin; - __favicon_ico favicon_ico; - - }; - -} - -#endif diff --git a/__favicon_ico.h b/__favicon_ico.h index fe92f04..b9fa891 100644 --- a/__favicon_ico.h +++ b/__favicon_ico.h @@ -1,11 +1,13 @@ #ifndef ____favicon_ico_h__ #define ____favicon_ico_h__ +#include "HTTPPage.h" + namespace http { - class __favicon_ico : public core::Command { + class __favicon_ico : public HTTPPage { - int processCommand(std::string request, core::Session *session, std::stringstream &data) override { + int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override { data << std::string(header_data); @@ -76,8 +78,7 @@ namespace http { "````````````````````````````````[`,^I]@W.JXR)*HQ)*HQ)*HQ)*HQ)*HQ" ")*HQ)*HQ)*HQ)*HQ)*HQ2[(RLMXX]P@_````````````````````````````````" "````````````````````````````````````````^PH_U/,[J-@W@<8T3[4R+*TQ" - "+ZTQ6;@SA\\@UK=LWV_<\\_@P_````````````````````````````````````````" - ""; + "+ZTQ6;@SA\\@UK=LWV_<\\_@P_````````````````````````````````````````"; }; } diff --git a/__index.h b/__index.h index a865c6f..34af489 100644 --- a/__index.h +++ b/__index.h @@ -1,15 +1,17 @@ #ifndef ____index_h__ #define ____index_h__ +#include "HTTPPage.h" + namespace http { - class __index : public core::Command { + class __index : public HTTPPage { - int processCommand(std::string request, core::Session *session, std::stringstream &data) override { + int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override { data << "\

You have successfully set up a JETServer.\ -
Session Id: \ +
Session Id: " << httpSession->getSessionId() << "\
The configuration has not yet been established for this web site.

\ \
"; diff --git a/__setupadmin.h b/__setupadmin.h index 17e0146..0db3c8f 100644 --- a/__setupadmin.h +++ b/__setupadmin.h @@ -3,14 +3,14 @@ namespace http { - class __setupadmin : public core::Command { + class __setupadmin : public HTTPPage { - int processCommand(std::string request, core::Session *session, std::stringstream &data) override { + int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override { data << "\

Please enter credential information\ for the security officer.
\ -
Session Id: \ +
Session Id: " << httpSession->getSessionId() << "\
The configuration has not yet been established for this web site.

\ \
";