diff --git a/Debug/.d b/Debug/.d deleted file mode 100644 index 8b13789..0000000 --- a/Debug/.d +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Debug/HTTPServer b/Debug/HTTPServer deleted file mode 100755 index 3d84f9f..0000000 Binary files a/Debug/HTTPServer and /dev/null differ diff --git a/Debug/main.cpp.o b/Debug/main.cpp.o index 1f889a6..8203f02 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 2ad6da9..be1d57c 100644 --- a/Debug/main.cpp.o.d +++ b/Debug/main.cpp.o.d @@ -7,9 +7,9 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ ../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ ../ServerCore/CommandList.h ../ServerCore/EPoll.h \ ../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \ - ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h _GET.h \ - ../ServerCore/Command.h ../ServerCore/Session.h ../ServerCore/Header.h \ - ../ServerCore/Response.h _POST.h + ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h \ + HTTPSessions.h ../ServerCore/Header.h ../ServerCore/Response.h _GET.h \ + ../ServerCore/Command.h ../ServerCore/Session.h _POST.h ../ServerCore/includes: @@ -59,14 +59,16 @@ HTTPService.h: ../ServerCore/Service.h: +HTTPSessions.h: + +../ServerCore/Header.h: + +../ServerCore/Response.h: + _GET.h: ../ServerCore/Command.h: ../ServerCore/Session.h: -../ServerCore/Header.h: - -../ServerCore/Response.h: - _POST.h: diff --git a/HTTPServer.mk b/HTTPServer.mk index 61505a6..510fc7e 100644 --- a/HTTPServer.mk +++ b/HTTPServer.mk @@ -5,22 +5,22 @@ ## Debug ProjectName :=HTTPServer ConfigurationName :=Debug -WorkspacePath :=/home/barant/Development/BMA/server_core -ProjectPath :=/home/barant/Development/BMA/server_core/HTTPServer +WorkspacePath :=/home/barant/barant +ProjectPath :=/home/barant/barant/HTTPServer IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := -User :=Brad Arant -Date :=12/03/19 +User := +Date :=05/18/19 CodeLitePath :=/home/barant/.codelite -LinkerName :=g++ -SharedObjectLinkerName :=g++ -shared -fPIC +LinkerName :=/usr/bin/x86_64-linux-gnu-g++ +SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC ObjectSuffix :=.o DependSuffix :=.o.d -PreprocessSuffix :=.o.i -DebugSwitch :=-gstab +PreprocessSuffix :=.i +DebugSwitch :=-g IncludeSwitch :=-I LibrarySwitch :=-l OutputSwitch :=-o @@ -31,7 +31,7 @@ OutputFile :=$(IntermediateDirectory)/$(ProjectName) Preprocessors := ObjectSwitch :=-o ArchiveOutputSwitch := -PreprocessOnlySwitch :=-E +PreprocessOnlySwitch :=-E ObjectsFileList :="HTTPServer.txt" PCHCompileFlags := MakeDirCommand :=mkdir -p @@ -39,28 +39,28 @@ LinkOptions := IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)../ServerCore/ IncludePCH := RcIncludePath := -Libs := $(LibrarySwitch)ServerCore $(LibrarySwitch)pthread -ArLibs := "ServerCore" "pthread" +Libs := $(LibrarySwitch)ServerCore $(LibrarySwitch)pthread $(LibrarySwitch)uuid +ArLibs := "ServerCore" "pthread" "uuid" LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)../ServerCore/Debug/ ## ## Common variables ## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables ## -AR := ar rcus -CXX := g++ -CC := gcc +AR := /usr/bin/x86_64-linux-gnu-ar rcu +CXX := /usr/bin/x86_64-linux-gnu-g++ +CC := /usr/bin/x86_64-linux-gnu-gcc CXXFLAGS := -g -O0 -Wall $(Preprocessors) CFLAGS := -g -O0 -Wall $(Preprocessors) ASFLAGS := -AS := as +AS := /usr/bin/x86_64-linux-gnu-as ## ## User defined environment variables ## CodeLiteDir:=/usr/share/codelite -Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) +Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IntermediateDirectory)/_GET.cpp$(ObjectSuffix) $(IntermediateDirectory)/src__POST.cpp$(ObjectSuffix) @@ -92,13 +92,45 @@ PreBuild: ## Objects ## $(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/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 $(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/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 + +$(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/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 + +$(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix): HTTPSessions.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix) HTTPSessions.cpp + +$(IntermediateDirectory)/_GET.cpp$(ObjectSuffix): _GET.cpp $(IntermediateDirectory)/_GET.cpp$(DependSuffix) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/_GET.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/_GET.cpp$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/_GET.cpp$(DependSuffix): _GET.cpp + @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/_GET.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/_GET.cpp$(DependSuffix) -MM _GET.cpp + +$(IntermediateDirectory)/_GET.cpp$(PreprocessSuffix): _GET.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/_GET.cpp$(PreprocessSuffix) _GET.cpp + +$(IntermediateDirectory)/src__POST.cpp$(ObjectSuffix): src/_POST.cpp $(IntermediateDirectory)/src__POST.cpp$(DependSuffix) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/src/_POST.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/src__POST.cpp$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src__POST.cpp$(DependSuffix): src/_POST.cpp + @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src__POST.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/src__POST.cpp$(DependSuffix) -MM src/_POST.cpp + +$(IntermediateDirectory)/src__POST.cpp$(PreprocessSuffix): src/_POST.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src__POST.cpp$(PreprocessSuffix) src/_POST.cpp + -include $(IntermediateDirectory)/*$(DependSuffix) ## diff --git a/HTTPServer.project b/HTTPServer.project index 42b0f89..340c058 100644 --- a/HTTPServer.project +++ b/HTTPServer.project @@ -7,7 +7,18 @@ + + + + + + + + + + + @@ -27,6 +38,7 @@ + @@ -34,7 +46,7 @@ - + @@ -108,6 +120,4 @@ - - diff --git a/HTTPServer.txt b/HTTPServer.txt index 6716386..013258e 100644 --- a/HTTPServer.txt +++ b/HTTPServer.txt @@ -1 +1 @@ -./Debug/main.cpp.o +./Debug/main.cpp.o ./Debug/HTTPSession.cpp.o ./Debug/HTTPSessions.cpp.o ./Debug/_GET.cpp.o ./Debug/src__POST.cpp.o diff --git a/HTTPService.h b/HTTPService.h index a03e224..942350e 100644 --- a/HTTPService.h +++ b/HTTPService.h @@ -2,6 +2,8 @@ #define __HTTPService_h__ #include "Service.h" +#include "HTTPSessions.h" +#include "Exception.h" #include "_GET.h" #include "_POST.h" @@ -14,6 +16,9 @@ namespace http { commands.add(get, "GET "); commands.add(post, "POST "); } + + HTTPSessions httpSessions; +// PageService pageService; private: _GET get; diff --git a/HTTPSession.cpp b/HTTPSession.cpp new file mode 100644 index 0000000..54984b4 --- /dev/null +++ b/HTTPSession.cpp @@ -0,0 +1,14 @@ +#include "HTTPSession.h" + +namespace http { + + HTTPSession::HTTPSession(std::string sessionId) { + this->sessionId = sessionId; + } + + std::string HTTPSession::getSessionId() { + return sessionId; + } + +} + diff --git a/HTTPSession.h b/HTTPSession.h new file mode 100644 index 0000000..0820860 --- /dev/null +++ b/HTTPSession.h @@ -0,0 +1,22 @@ +#ifndef __HTTPSession_h__ +#define __HTTPSession_h__ + +#include "Response.h" + +namespace http { + + class HTTPSession { + + public: + HTTPSession(std::string sessionId); + std::string getSessionId(); + + private: + std::string sessionId; + + + }; + +} + +#endif diff --git a/HTTPSessions.cpp b/HTTPSessions.cpp new file mode 100644 index 0000000..695a148 --- /dev/null +++ b/HTTPSessions.cpp @@ -0,0 +1,40 @@ +#include "HTTPSessions.h" +#include "HTTPSession.h" +#include "Log.h" +#include + +namespace http { + + HTTPSession * HTTPSessions::findSessionByHeader(core::Header &header, core::Response &response) { + std::string sessionId = header.getCookie("sessionId"); + HTTPSession *session = findSessionById(sessionId, response); + return session; + } + + 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; + } else { + httpSession = createHTTPSession(); + response.setCookie("sessionId", httpSession->getSessionId()); + } + return httpSession; + } + + HTTPSession * HTTPSessions::createHTTPSession() { + HTTPSession *httpSession = new HTTPSession(generateSessionId()); + sessions.insert(std::make_pair(httpSession->getSessionId(), httpSession)); + return httpSession; + } + + std::string HTTPSessions::generateSessionId() { + uuid_t uuid; + uuid_generate_random(uuid); + char uuid_s[37]; + uuid_unparse(uuid, uuid_s); + return uuid_s; + } + +} diff --git a/HTTPSessions.h b/HTTPSessions.h new file mode 100644 index 0000000..7645fa9 --- /dev/null +++ b/HTTPSessions.h @@ -0,0 +1,27 @@ +#ifndef __HTTPSessions_h__ +#define __HTTPSessions_h__ + +#include "Header.h" +#include "Response.h" + +namespace http { + + class HTTPSession; + + class HTTPSessions { + + public: + HTTPSession * findSessionByHeader(core::Header &header, core::Response &response); + HTTPSession * findSessionById(std::string sessionId, core::Response &response); + + private: + HTTPSession * createHTTPSession(); + std::string generateSessionId(); + + std::map sessions; + + }; + +} + +#endif diff --git a/Release/HTTPServer b/Release/HTTPServer deleted file mode 100755 index 048195c..0000000 Binary files a/Release/HTTPServer and /dev/null differ diff --git a/Release/main.cpp.o b/Release/main.cpp.o index c963a71..24af4fa 100644 Binary files a/Release/main.cpp.o and b/Release/main.cpp.o differ diff --git a/Release/main.cpp.o.d b/Release/main.cpp.o.d index 750973c..626f018 100644 --- a/Release/main.cpp.o.d +++ b/Release/main.cpp.o.d @@ -5,12 +5,11 @@ Release/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ ../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \ ../ServerCore/Command.h ../ServerCore/ConsoleServer.h \ ../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ - ../ServerCore/CommandList.h ../ServerCore/EPoll.h HTTPServer.h \ - ../ServerCore/TCPServerSocket.h ../ServerCore/Session.h \ + ../ServerCore/CommandList.h ../ServerCore/EPoll.h \ + ../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \ ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h _GET.h \ - ../ServerCore/Command.h ../ServerCore/Header.h ../ServerCore/Response.h \ - _POST.h ../ServerCore/Exception.h ../ServerCore/File.h \ - ../ServerCore/Log.h + ../ServerCore/Command.h ../ServerCore/Session.h ../ServerCore/Header.h \ + ../ServerCore/Response.h _POST.h ../ServerCore/includes: @@ -48,11 +47,11 @@ Release/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ ../ServerCore/EPoll.h: -HTTPServer.h: +../ServerCore/Exception.h: -../ServerCore/TCPServerSocket.h: +../ServerCore/File.h: -../ServerCore/Session.h: +../ServerCore/Log.h: ../ServerCore/IPAddress.h: @@ -64,14 +63,10 @@ _GET.h: ../ServerCore/Command.h: +../ServerCore/Session.h: + ../ServerCore/Header.h: ../ServerCore/Response.h: _POST.h: - -../ServerCore/Exception.h: - -../ServerCore/File.h: - -../ServerCore/Log.h: diff --git a/_GET.cpp b/_GET.cpp new file mode 100644 index 0000000..707148a --- /dev/null +++ b/_GET.cpp @@ -0,0 +1,28 @@ +#include "_GET.h" +#include "HTTPSession.h" +#include "HTTPService.h" +#include "Log.h" + +namespace http { + + int _GET::processCommand(std::string request, core::Session *session, std::stringstream &data) { + + core::Header header(request); + core::Response response; + + core::Log(core::LOG_DEBUG_1) << header.getPath() << " " << header.getCGIData(); + + HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(header, response); + + std::stringstream content; + ((HTTPService &)session->service).pageService.processRequest(header.getPath(), content); + + response.setProtocol(header.requestProtocol()); + response.setCode("200"); + response.setText("OK"); + response.setMimeType("text/html"); + data << response.getResponse(content.str()); + return 0; + } + +} diff --git a/_GET.h b/_GET.h index 78dd42c..970d14b 100644 --- a/_GET.h +++ b/_GET.h @@ -5,24 +5,14 @@ #include "Session.h" #include "Header.h" #include "Response.h" +#include "Log.h" namespace http { class _GET : public core::Command { public: - int processCommand(std::string request, core::Session *session) override { - core::Header header(request); - std::string data = "This Is A Test"; - core::Response response; - response.setProtocol(header.requestProtocol()); - response.setCode("200"); - response.setText("OK"); - response.setMimeType("text/html"); - session->out << response.getResponse(data); - session->send(); - return 0; - } + int processCommand(std::string request, core::Session *session, std::stringstream &data) override; }; diff --git a/_POST.h b/_POST.h index ec79d44..2630f5c 100644 --- a/_POST.h +++ b/_POST.h @@ -3,24 +3,15 @@ #include "Command.h" #include "Session.h" +#include "Header.h" +#include "Response.h" namespace http { class _POST : public core::Command { public: - int processCommand(std::string request, core::Session *session) override { - core::Header header(request); - std::string data = "This Is A Test"; - core::Response response; - response.setProtocol(header.requestProtocol()); - response.setCode("200"); - response.setText("OK"); - response.setMimeType("text/html"); - session->out << response.getResponse(data); - session->send(); - return 0; - } + int processCommand(std::string request, core::Session *session, std::stringstream &data) override; }; diff --git a/main.cpp b/main.cpp index b164d9b..41faa5e 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) { core::EPoll ePoll; http::HTTPService httpService; - core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8090)); + core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8080)); core::Service consoleService; core::ConsoleServer console(ePoll, consoleService, core::IPAddress(ipAddress, 1027)); diff --git a/src/PageService.h b/src/PageService.h new file mode 100644 index 0000000..cc877cc --- /dev/null +++ b/src/PageService.h @@ -0,0 +1,27 @@ +#ifndef __PageService_h__ +#define __PageService_h__ + +#include "Service.h" +#include "Exception.h" +#include "__index.h" +#include "__setupadmin.h" + +namespace http { + + class PageService : public core::Service { + + public: + PageService() { + commands.add(index, "/"); + commands.add(setupadmin, "/setupadmin "); + } + + private: + __index index; + __setupadmin setupadmin; + + }; + +} + +#endif diff --git a/src/_POST.cpp b/src/_POST.cpp new file mode 100644 index 0000000..efc1d53 --- /dev/null +++ b/src/_POST.cpp @@ -0,0 +1,28 @@ +#include "_POST.h" +#include "HTTPSession.h" +#include "HTTPService.h" +#include "Log.h" + +namespace http { + + int _POST::processCommand(std::string request, core::Session *session, std::stringstream &data) { + + core::Header header(request); + core::Response response; + + core::Log(core::LOG_DEBUG_1) << header.getPath() << " " << header.getCGIData(); + + HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(header, response); + + std::stringstream content; +// ((HTTPService &)session->service).pageService.processRequest(header.getPath(), content); + + response.setProtocol(header.requestProtocol()); + response.setCode("200"); + response.setText("OK"); + response.setMimeType("text/html"); + data << response.getResponse(content.str()); + return 0; + } + +} diff --git a/src/__index.h b/src/__index.h new file mode 100644 index 0000000..43ce187 --- /dev/null +++ b/src/__index.h @@ -0,0 +1,17 @@ +#ifndef ____index_h__ +#define ____index_h__ + +namespace http { + + class __index : core::Command { + + int processCommand(std::string request, core::Session *session) override { + session.out << "\ + You have successfully set up a JETServer.\ + Session Id: " + httpSession->getSessionId() + "\ + The configuration has not yet been established for this web site.\ + Configure\ +
You have successfully set up a JETServer.\ + Session Id: " + httpSession->getSessionId() + "\ + The configuration has not yet been established for this web site.