From 9c0ea8e5598d1de726e2b84f6ae5bcf129199602 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 21 May 2019 16:41:07 -0700 Subject: [PATCH] Alot of changes. --- Command.h | 2 +- CommandList.cpp | 14 +++--- CommandList.h | 4 +- ConsoleSession.cpp | 2 +- EPoll.cpp | 10 ++--- EPoll.h | 2 +- Header.cpp | 14 ++++++ Header.h | 3 ++ Release/.d | 1 + Release/Command.cpp.o.d | 18 ++++++++ Release/CommandList.cpp.o.d | 21 +++++++++ Release/ConsoleServer.cpp.o.d | 40 +++++++++++++++++ Release/ConsoleSession.cpp.o.d | 34 +++++++++++++++ Release/EPoll.cpp.o.d | 29 +++++++++++++ Release/Exception.cpp.o.d | 12 ++++++ Release/File.cpp.o.d | 7 +++ Release/Header.cpp.o.d | 11 +++++ Release/IPAddress.cpp.o.d | 7 +++ Release/Log.cpp.o.d | 40 +++++++++++++++++ Release/Response.cpp.o.d | 12 ++++++ Release/Service.cpp.o.d | 27 ++++++++++++ Release/Session.cpp.o.d | 27 ++++++++++++ Release/Socket.cpp.o.d | 29 +++++++++++++ Release/TCPServerSocket.cpp.o.d | 36 ++++++++++++++++ Release/TCPSocket.cpp.o.d | 29 +++++++++++++ Release/TLSServerSocket.cpp.o.d | 42 ++++++++++++++++++ Release/TLSSession.cpp.o.d | 42 ++++++++++++++++++ Release/TerminalSession.cpp.o.d | 27 ++++++++++++ Release/Thread.cpp.o.d | 27 ++++++++++++ Release/Timer.cpp.o.d | 29 +++++++++++++ Release/UDPServerSocket.cpp.o.d | 31 ++++++++++++++ Release/UDPSocket.cpp.o.d | 18 ++++++++ Response.cpp | 4 ++ Response.h | 2 + ServerCore.mk | 76 ++++++++++++++++----------------- Session.cpp | 12 +++--- Session.h | 2 +- TCPServerSocket.cpp | 9 ++-- TCPServerSocket.h | 2 +- Thread.cpp | 8 ++-- Thread.h | 2 +- UDPServerSocket.cpp | 10 ++--- UDPServerSocket.h | 2 +- 43 files changed, 697 insertions(+), 79 deletions(-) create mode 100644 Release/.d create mode 100644 Release/Command.cpp.o.d create mode 100644 Release/CommandList.cpp.o.d create mode 100644 Release/ConsoleServer.cpp.o.d create mode 100644 Release/ConsoleSession.cpp.o.d create mode 100644 Release/EPoll.cpp.o.d create mode 100644 Release/Exception.cpp.o.d create mode 100644 Release/File.cpp.o.d create mode 100644 Release/Header.cpp.o.d create mode 100644 Release/IPAddress.cpp.o.d create mode 100644 Release/Log.cpp.o.d create mode 100644 Release/Response.cpp.o.d create mode 100644 Release/Service.cpp.o.d create mode 100644 Release/Session.cpp.o.d create mode 100644 Release/Socket.cpp.o.d create mode 100644 Release/TCPServerSocket.cpp.o.d create mode 100644 Release/TCPSocket.cpp.o.d create mode 100644 Release/TLSServerSocket.cpp.o.d create mode 100644 Release/TLSSession.cpp.o.d create mode 100644 Release/TerminalSession.cpp.o.d create mode 100644 Release/Thread.cpp.o.d create mode 100644 Release/Timer.cpp.o.d create mode 100644 Release/UDPServerSocket.cpp.o.d create mode 100644 Release/UDPSocket.cpp.o.d diff --git a/Command.h b/Command.h index 8d42e1d..88658ad 100644 --- a/Command.h +++ b/Command.h @@ -46,7 +46,7 @@ namespace core { /// a non-zero value indicating an error condition. /// - virtual int processCommand(std::string request, Session *session) = 0; + virtual int processCommand(std::string request, Session *session, std::stringstream &data) = 0; /// /// Specify the output that will occur to the specified session. diff --git a/CommandList.cpp b/CommandList.cpp index e33dc0e..491a3f1 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -16,20 +16,20 @@ namespace core { } - bool CommandList::processRequest(std::string request, Session *session) { + bool CommandList::processRequest(std::string request, Session *session, std::stringstream &data) { for(auto *command : commands) { - if(command->check(request)) { - command->processCommand(request, session); - return true; - } + if(command->check(request)) { + command->processCommand(request, session, data); + return true; + } } return false; } - int CommandList::processCommand(std::string request, Session *session) { + int CommandList::processCommand(std::string request, Session *session, std::stringstream &data) { for(Command *command : commands) - session->out << command->getName() << std::endl; + data << command->getName() << std::endl; } } diff --git a/CommandList.h b/CommandList.h index 8fe2af1..39b383f 100644 --- a/CommandList.h +++ b/CommandList.h @@ -38,9 +38,9 @@ namespace core { void remove(Command &command); - bool processRequest(std::string request, Session *session); + bool processRequest(std::string request, Session *session, std::stringstream &data); - int processCommand(std::string request, Session *session) override; + int processCommand(std::string request, Session *session, std::stringstream &data) override; private: std::vector commands; diff --git a/ConsoleSession.cpp b/ConsoleSession.cpp index 0b565d3..595450f 100644 --- a/ConsoleSession.cpp +++ b/ConsoleSession.cpp @@ -105,7 +105,7 @@ namespace core { saveCursor(); setCursorLocation(16, 1); out << "--> " << request << std::endl; - service.commands.processRequest(request, this); + service.commands.processRequest(request, this, out); restoreCursor(); send(); } diff --git a/EPoll.cpp b/EPoll.cpp index 9930125..b1d9664 100644 --- a/EPoll.cpp +++ b/EPoll.cpp @@ -111,15 +111,15 @@ namespace core { return epfd; } - int EPoll::processCommand(std::string command, Session *session) { + int EPoll::processCommand(std::string command, Session *session, std::stringstream &data) { int sequence = 0; for(auto threadx : threads) { - session->out << "|" << ++sequence; - session->out << "|" ; - threadx.output(session); - session->out << "|" << std::endl; + data << "|" << ++sequence; + data << "|" ; + threadx.output(data); + data << "|" << std::endl; } } diff --git a/EPoll.h b/EPoll.h index c3ed27b..77a4c77 100644 --- a/EPoll.h +++ b/EPoll.h @@ -110,7 +110,7 @@ namespace core { /// @param session the session to write the requested data to. /// - int processCommand(std::string command, Session *session) override; ///(key, value)); } + + void Response::setCookie(std::string name, std::string value) { + // TODO: Need to format headers with Set-Cookie: + } } diff --git a/Response.h b/Response.h index 3db7f25..932c84e 100644 --- a/Response.h +++ b/Response.h @@ -91,6 +91,8 @@ namespace core { void addHeaderItem(std::string key, std::string value); + void setCookie(std::string name, std::string value); + private: std::string protocol; std::string code; diff --git a/ServerCore.mk b/ServerCore.mk index 60c5ae1..b142ddf 100644 --- a/ServerCore.mk +++ b/ServerCore.mk @@ -5,22 +5,22 @@ ## Debug ProjectName :=ServerCore ConfigurationName :=Debug -WorkspacePath :=/home/barant/Development/BMA/server_core -ProjectPath :=/home/barant/Development/BMA/server_core/ServerCore +WorkspacePath :=/home/barant/barant +ProjectPath :=/home/barant/barant/ServerCore IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := -User :=Brad Arant -Date :=04/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)/lib$(ProjectName).a Preprocessors := ObjectSwitch :=-o ArchiveOutputSwitch := -PreprocessOnlySwitch :=-E +PreprocessOnlySwitch :=-E ObjectsFileList :="ServerCore.txt" PCHCompileFlags := MakeDirCommand :=mkdir -p @@ -47,13 +47,13 @@ LibPath := $(LibraryPathSwitch). ## 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 $(Preprocessors) CFLAGS := -g $(Preprocessors) ASFLAGS := -AS := as +AS := /usr/bin/x86_64-linux-gnu-as ## @@ -79,8 +79,8 @@ $(OutputFile): $(Objects) @echo "" > $(IntermediateDirectory)/.d @echo $(Objects0) > $(ObjectsFileList) $(AR) $(ArchiveOutputSwitch)$(OutputFile) @$(ObjectsFileList) $(ArLibs) - @$(MakeDirCommand) "/home/barant/Development/BMA/server_core/.build-debug" - @echo rebuilt > "/home/barant/Development/BMA/server_core/.build-debug/ServerCore" + @$(MakeDirCommand) "/home/barant/barant/.build-debug" + @echo rebuilt > "/home/barant/barant/.build-debug/ServerCore" MakeIntermediateDirs: @test -d ./Debug || $(MakeDirCommand) ./Debug @@ -96,7 +96,7 @@ PreBuild: ## Objects ## $(IntermediateDirectory)/Command.cpp$(ObjectSuffix): Command.cpp $(IntermediateDirectory)/Command.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Command.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Command.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Command.cpp$(DependSuffix): Command.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Command.cpp$(DependSuffix) -MM Command.cpp @@ -104,7 +104,7 @@ $(IntermediateDirectory)/Command.cpp$(PreprocessSuffix): Command.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Command.cpp$(PreprocessSuffix) Command.cpp $(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix): ConsoleServer.cpp $(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/ConsoleServer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/ConsoleServer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix): ConsoleServer.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix) -MM ConsoleServer.cpp @@ -112,7 +112,7 @@ $(IntermediateDirectory)/ConsoleServer.cpp$(PreprocessSuffix): ConsoleServer.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/ConsoleServer.cpp$(PreprocessSuffix) ConsoleServer.cpp $(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix): ConsoleSession.cpp $(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/ConsoleSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/ConsoleSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix): ConsoleSession.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix) -MM ConsoleSession.cpp @@ -120,7 +120,7 @@ $(IntermediateDirectory)/ConsoleSession.cpp$(PreprocessSuffix): ConsoleSession.c $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/ConsoleSession.cpp$(PreprocessSuffix) ConsoleSession.cpp $(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix): EPoll.cpp $(IntermediateDirectory)/EPoll.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/EPoll.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/EPoll.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/EPoll.cpp$(DependSuffix): EPoll.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/EPoll.cpp$(DependSuffix) -MM EPoll.cpp @@ -128,7 +128,7 @@ $(IntermediateDirectory)/EPoll.cpp$(PreprocessSuffix): EPoll.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/EPoll.cpp$(PreprocessSuffix) EPoll.cpp $(IntermediateDirectory)/Exception.cpp$(ObjectSuffix): Exception.cpp $(IntermediateDirectory)/Exception.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Exception.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Exception.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Exception.cpp$(DependSuffix): Exception.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Exception.cpp$(DependSuffix) -MM Exception.cpp @@ -136,7 +136,7 @@ $(IntermediateDirectory)/Exception.cpp$(PreprocessSuffix): Exception.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Exception.cpp$(PreprocessSuffix) Exception.cpp $(IntermediateDirectory)/File.cpp$(ObjectSuffix): File.cpp $(IntermediateDirectory)/File.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/File.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/File.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/File.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/File.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/File.cpp$(DependSuffix): File.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/File.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/File.cpp$(DependSuffix) -MM File.cpp @@ -144,7 +144,7 @@ $(IntermediateDirectory)/File.cpp$(PreprocessSuffix): File.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/File.cpp$(PreprocessSuffix) File.cpp $(IntermediateDirectory)/Header.cpp$(ObjectSuffix): Header.cpp $(IntermediateDirectory)/Header.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Header.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Header.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Header.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Header.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Header.cpp$(DependSuffix): Header.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Header.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Header.cpp$(DependSuffix) -MM Header.cpp @@ -152,7 +152,7 @@ $(IntermediateDirectory)/Header.cpp$(PreprocessSuffix): Header.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Header.cpp$(PreprocessSuffix) Header.cpp $(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix): IPAddress.cpp $(IntermediateDirectory)/IPAddress.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/IPAddress.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/IPAddress.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IPAddress.cpp$(DependSuffix): IPAddress.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IPAddress.cpp$(DependSuffix) -MM IPAddress.cpp @@ -160,7 +160,7 @@ $(IntermediateDirectory)/IPAddress.cpp$(PreprocessSuffix): IPAddress.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IPAddress.cpp$(PreprocessSuffix) IPAddress.cpp $(IntermediateDirectory)/Log.cpp$(ObjectSuffix): Log.cpp $(IntermediateDirectory)/Log.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Log.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Log.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Log.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Log.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Log.cpp$(DependSuffix): Log.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Log.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Log.cpp$(DependSuffix) -MM Log.cpp @@ -168,7 +168,7 @@ $(IntermediateDirectory)/Log.cpp$(PreprocessSuffix): Log.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Log.cpp$(PreprocessSuffix) Log.cpp $(IntermediateDirectory)/Response.cpp$(ObjectSuffix): Response.cpp $(IntermediateDirectory)/Response.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Response.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Response.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Response.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Response.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Response.cpp$(DependSuffix): Response.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Response.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Response.cpp$(DependSuffix) -MM Response.cpp @@ -176,7 +176,7 @@ $(IntermediateDirectory)/Response.cpp$(PreprocessSuffix): Response.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Response.cpp$(PreprocessSuffix) Response.cpp $(IntermediateDirectory)/Session.cpp$(ObjectSuffix): Session.cpp $(IntermediateDirectory)/Session.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Session.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Session.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Session.cpp$(DependSuffix): Session.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Session.cpp$(DependSuffix) -MM Session.cpp @@ -184,7 +184,7 @@ $(IntermediateDirectory)/Session.cpp$(PreprocessSuffix): Session.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Session.cpp$(PreprocessSuffix) Session.cpp $(IntermediateDirectory)/Socket.cpp$(ObjectSuffix): Socket.cpp $(IntermediateDirectory)/Socket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Socket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Socket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Socket.cpp$(DependSuffix): Socket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Socket.cpp$(DependSuffix) -MM Socket.cpp @@ -192,7 +192,7 @@ $(IntermediateDirectory)/Socket.cpp$(PreprocessSuffix): Socket.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Socket.cpp$(PreprocessSuffix) Socket.cpp $(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix): TCPServerSocket.cpp $(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TCPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/TCPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix): TCPServerSocket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix) -MM TCPServerSocket.cpp @@ -200,7 +200,7 @@ $(IntermediateDirectory)/TCPServerSocket.cpp$(PreprocessSuffix): TCPServerSocket $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TCPServerSocket.cpp$(PreprocessSuffix) TCPServerSocket.cpp $(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix): TCPSocket.cpp $(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TCPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/TCPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix): TCPSocket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix) -MM TCPSocket.cpp @@ -208,7 +208,7 @@ $(IntermediateDirectory)/TCPSocket.cpp$(PreprocessSuffix): TCPSocket.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TCPSocket.cpp$(PreprocessSuffix) TCPSocket.cpp $(IntermediateDirectory)/Thread.cpp$(ObjectSuffix): Thread.cpp $(IntermediateDirectory)/Thread.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Thread.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Thread.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Thread.cpp$(DependSuffix): Thread.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Thread.cpp$(DependSuffix) -MM Thread.cpp @@ -216,7 +216,7 @@ $(IntermediateDirectory)/Thread.cpp$(PreprocessSuffix): Thread.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Thread.cpp$(PreprocessSuffix) Thread.cpp $(IntermediateDirectory)/Timer.cpp$(ObjectSuffix): Timer.cpp $(IntermediateDirectory)/Timer.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Timer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Timer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Timer.cpp$(DependSuffix): Timer.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Timer.cpp$(DependSuffix) -MM Timer.cpp @@ -224,7 +224,7 @@ $(IntermediateDirectory)/Timer.cpp$(PreprocessSuffix): Timer.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Timer.cpp$(PreprocessSuffix) Timer.cpp $(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix): TLSServerSocket.cpp $(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TLSServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/TLSServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix): TLSServerSocket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix) -MM TLSServerSocket.cpp @@ -232,7 +232,7 @@ $(IntermediateDirectory)/TLSServerSocket.cpp$(PreprocessSuffix): TLSServerSocket $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TLSServerSocket.cpp$(PreprocessSuffix) TLSServerSocket.cpp $(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix): TLSSession.cpp $(IntermediateDirectory)/TLSSession.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TLSSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/TLSSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/TLSSession.cpp$(DependSuffix): TLSSession.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TLSSession.cpp$(DependSuffix) -MM TLSSession.cpp @@ -240,7 +240,7 @@ $(IntermediateDirectory)/TLSSession.cpp$(PreprocessSuffix): TLSSession.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TLSSession.cpp$(PreprocessSuffix) TLSSession.cpp $(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix): UDPServerSocket.cpp $(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/UDPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/UDPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix): UDPServerSocket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix) -MM UDPServerSocket.cpp @@ -248,7 +248,7 @@ $(IntermediateDirectory)/UDPServerSocket.cpp$(PreprocessSuffix): UDPServerSocket $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/UDPServerSocket.cpp$(PreprocessSuffix) UDPServerSocket.cpp $(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix): UDPSocket.cpp $(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/UDPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/UDPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix): UDPSocket.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix) -MM UDPSocket.cpp @@ -256,7 +256,7 @@ $(IntermediateDirectory)/UDPSocket.cpp$(PreprocessSuffix): UDPSocket.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/UDPSocket.cpp$(PreprocessSuffix) UDPSocket.cpp $(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix): CommandList.cpp $(IntermediateDirectory)/CommandList.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/CommandList.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/CommandList.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/CommandList.cpp$(DependSuffix): CommandList.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/CommandList.cpp$(DependSuffix) -MM CommandList.cpp @@ -264,7 +264,7 @@ $(IntermediateDirectory)/CommandList.cpp$(PreprocessSuffix): CommandList.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/CommandList.cpp$(PreprocessSuffix) CommandList.cpp $(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix): TerminalSession.cpp $(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TerminalSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/TerminalSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix): TerminalSession.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix) -MM TerminalSession.cpp @@ -272,7 +272,7 @@ $(IntermediateDirectory)/TerminalSession.cpp$(PreprocessSuffix): TerminalSession $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TerminalSession.cpp$(PreprocessSuffix) TerminalSession.cpp $(IntermediateDirectory)/Service.cpp$(ObjectSuffix): Service.cpp $(IntermediateDirectory)/Service.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Service.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Service.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/ServerCore/Service.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Service.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/Service.cpp$(DependSuffix): Service.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Service.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Service.cpp$(DependSuffix) -MM Service.cpp diff --git a/Session.cpp b/Session.cpp index 21663d1..61edb81 100644 --- a/Session.cpp +++ b/Session.cpp @@ -12,14 +12,16 @@ namespace core { void Session::init() {} - void Session::output(Session *session) { - session->out << "|" << ipAddress.getClientAddressAndPort(); + void Session::output(std::stringstream &data) { + data << "|" << ipAddress.getClientAddressAndPort(); } void Session::protocol(std::string data = "") { - if(data.length() > 0) - if(!service.commands.processRequest(data, this)) - service.sessionErrorHandler("Invalid data received.", this); + if(data.length() > 0) { + if(!service.commands.processRequest(data, this, out)) + service.sessionErrorHandler("Invalid data received.", this); + send(); + } } void Session::onConnected() { diff --git a/Session.h b/Session.h index a2b9a90..6699dcd 100644 --- a/Session.h +++ b/Session.h @@ -27,7 +27,7 @@ namespace core { virtual void init(); - virtual void output(Session *session); + virtual void output(std::stringstream &data); /// /// The send method is used to output the contents of the out stream diff --git a/TCPServerSocket.cpp b/TCPServerSocket.cpp index d10f07a..a0e987e 100644 --- a/TCPServerSocket.cpp +++ b/TCPServerSocket.cpp @@ -39,14 +39,13 @@ namespace core { return new Session(ePoll, service); } - int TCPServerSocket::processCommand(std::string command, Session *session) { + int TCPServerSocket::processCommand(std::string command, Session *session, std::stringstream &data) { int sequence = 0; for(auto *sessionx : service.sessions) { - session->out << "|" << ++sequence; - sessionx->output(session); - session->out << "|" << std::endl; + data << "|" << ++sequence; + sessionx->output(data); + data << "|" << std::endl; } - session->send(); } } diff --git a/TCPServerSocket.h b/TCPServerSocket.h index 79a7879..c604d7e 100644 --- a/TCPServerSocket.h +++ b/TCPServerSocket.h @@ -75,7 +75,7 @@ namespace core { /// @param the session object to write the output to. /// - int processCommand(std::string command, Session *session) override; + int processCommand(std::string command, Session *session, std::stringstream &data) override; private: diff --git a/Thread.cpp b/Thread.cpp index a60322c..d414887 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -27,10 +27,10 @@ namespace core { return count; } - void Thread::output(Session *session) { - session->out << "|" << getThreadId(); - session->out << "|" << getStatus(); - session->out << "|" << getCount(); + void Thread::output(std::stringstream &data) { + data << "|" << getThreadId(); + data << "|" << getStatus(); + data << "|" << getCount(); } diff --git a/Thread.h b/Thread.h index cd9157f..62e1c63 100644 --- a/Thread.h +++ b/Thread.h @@ -33,7 +33,7 @@ namespace core { std::string getStatus(); pid_t getThreadId(); int getCount(); - void output(Session *session); + void output(std::stringstream &data); private: EPoll &ePoll; // The EPoll control object. diff --git a/UDPServerSocket.cpp b/UDPServerSocket.cpp index f7c1f9b..e8700c4 100644 --- a/UDPServerSocket.cpp +++ b/UDPServerSocket.cpp @@ -44,18 +44,16 @@ namespace core { // } - int UDPServerSocket::processCommand(Session *session) { + int UDPServerSocket::processCommand(std::string request, std::stringstream &data) { - std::stringstream out; int sequence = 0; for(auto *session : sessions) { - out << "|" << ++sequence; - session->output(session); - out << "|" << std::endl; + data << "|" << ++sequence; + session->output(data); + data << "|" << std::endl; } - session->write(out.str()); } } diff --git a/UDPServerSocket.h b/UDPServerSocket.h index 2b087aa..cbc1a8e 100644 --- a/UDPServerSocket.h +++ b/UDPServerSocket.h @@ -30,7 +30,7 @@ namespace core { void onDataReceived(std::string data) override; - int processCommand(Session *session); + int processCommand(std::string request, std::stringstream &data); //------------------------------------------------------------------------------------ // The retrieved socket connections are placed into the client vector list.