diff --git a/Debug/.d b/Debug/.d new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Debug/.d @@ -0,0 +1 @@ + diff --git a/Debug/HTTPServer b/Debug/HTTPServer new file mode 100755 index 0000000..106f548 Binary files /dev/null and b/Debug/HTTPServer differ diff --git a/Debug/main.cpp.o b/Debug/main.cpp.o new file mode 100644 index 0000000..931d340 Binary files /dev/null and b/Debug/main.cpp.o differ diff --git a/Debug/main.cpp.o.d b/Debug/main.cpp.o.d new file mode 100644 index 0000000..0748a3b --- /dev/null +++ b/Debug/main.cpp.o.d @@ -0,0 +1,77 @@ +Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ + ../ServerCore/Log.h ../ServerCore/includes ../ServerCore/File.h \ + ../ServerCore/Object.h ../ServerCore/Socket.h ../ServerCore/Thread.h \ + ../ServerCore/Session.h ../ServerCore/TCPSocket.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/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/includes: + +../ServerCore/EPoll.h: + +../ServerCore/Log.h: + +../ServerCore/includes: + +../ServerCore/File.h: + +../ServerCore/Object.h: + +../ServerCore/Socket.h: + +../ServerCore/Thread.h: + +../ServerCore/Session.h: + +../ServerCore/TCPSocket.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/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: diff --git a/HTTPServer.h~ b/HTTPServer.h~ deleted file mode 100644 index 2a9ce08..0000000 --- a/HTTPServer.h~ +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __HTTPServer_h__ -#define __HTTPServer_h__ - -#include "includes" -#include "EPoll.h" -#include "TCPServerSocket.h" -#include "Session.h" -#include "IPAddress.h" - -namespace http { - - class HTTPServer : public core::TCPServerSocket { - - public: - HTTPServer(core::EPoll &ePoll, core::IPAddress address) : core::TCPServerSocket(ePoll, address) {} - - protected: - core::Service * getService() override { - return new HTTPService(*this); - } - - }; - -} - -#endif diff --git a/HTTPServer.mk b/HTTPServer.mk new file mode 100644 index 0000000..2db7714 --- /dev/null +++ b/HTTPServer.mk @@ -0,0 +1,110 @@ +## +## Auto Generated makefile by CodeLite IDE +## any manual changes will be erased +## +## Release +ProjectName :=HTTPServer +ConfigurationName :=Release +WorkspacePath :=/home/barant/barant +ProjectPath :=/home/barant/barant/HTTPServer +IntermediateDirectory :=./Release +OutDir := $(IntermediateDirectory) +CurrentFileName := +CurrentFilePath := +CurrentFileFullPath := +User := +Date :=03/03/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 +DependSuffix :=.o.d +PreprocessSuffix :=.i +DebugSwitch :=-g +IncludeSwitch :=-I +LibrarySwitch :=-l +OutputSwitch :=-o +LibraryPathSwitch :=-L +PreprocessorSwitch :=-D +SourceSwitch :=-c +OutputFile :=$(IntermediateDirectory)/$(ProjectName) +Preprocessors :=$(PreprocessorSwitch)NDEBUG +ObjectSwitch :=-o +ArchiveOutputSwitch := +PreprocessOnlySwitch :=-E +ObjectsFileList :="HTTPServer.txt" +PCHCompileFlags := +MakeDirCommand :=mkdir -p +LinkOptions := +IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)../ServerCore +IncludePCH := +RcIncludePath := +Libs := $(LibrarySwitch)ServerCore $(LibrarySwitch)pthread +ArLibs := "ServerCore" "pthread" +LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)../ServerCore/Debug + +## +## Common variables +## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables +## +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 := -O2 -Wall $(Preprocessors) +CFLAGS := -O2 -Wall $(Preprocessors) +ASFLAGS := +AS := /usr/bin/x86_64-linux-gnu-as + + +## +## User defined environment variables +## +CodeLiteDir:=/usr/share/codelite +Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) + + + +Objects=$(Objects0) + +## +## Main Build Targets +## +.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs +all: $(OutputFile) + +$(OutputFile): $(IntermediateDirectory)/.d $(Objects) + @$(MakeDirCommand) $(@D) + @echo "" > $(IntermediateDirectory)/.d + @echo $(Objects0) > $(ObjectsFileList) + $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) + +MakeIntermediateDirs: + @test -d ./Release || $(MakeDirCommand) ./Release + + +$(IntermediateDirectory)/.d: + @test -d ./Release || $(MakeDirCommand) ./Release + +PreBuild: + + +## +## Objects +## +$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix) + $(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 + + +-include $(IntermediateDirectory)/*$(DependSuffix) +## +## Clean +## +clean: + $(RM) -r ./Release/ + + diff --git a/HTTPServer.project b/HTTPServer.project new file mode 100644 index 0000000..ea0ba7f --- /dev/null +++ b/HTTPServer.project @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + + + + + diff --git a/HTTPServer.txt b/HTTPServer.txt new file mode 100644 index 0000000..65da2a2 --- /dev/null +++ b/HTTPServer.txt @@ -0,0 +1 @@ +./Release/main.cpp.o diff --git a/HTTPService.h b/HTTPService.h index 26d420a..7d1492b 100644 --- a/HTTPService.h +++ b/HTTPService.h @@ -2,18 +2,20 @@ #define __HTTPService_h__ #include "Service.h" -#include "HTTPServer.h" +//#include "HTTPServer.h" #include "_GET.h" #include "_POST.h" namespace http { + + class HTTPServer; class HTTPService : public core::Service { public: - HTTPService::HTTPService(HTTPServer &server) : core::Service(server) { - commands.add(get, "GET "); - commands.add(post, "POST "); + HTTPService(HTTPServer &server) : core::Service((core::TCPServerSocket &)server) { + commands.add(get, "GET "); + commands.add(post, "POST "); } private: diff --git a/Release/.d b/Release/.d new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Release/.d @@ -0,0 +1 @@ + diff --git a/Release/HTTPServer b/Release/HTTPServer new file mode 100755 index 0000000..048195c Binary files /dev/null and b/Release/HTTPServer differ diff --git a/Release/main.cpp.o b/Release/main.cpp.o new file mode 100644 index 0000000..c963a71 Binary files /dev/null and b/Release/main.cpp.o differ diff --git a/Release/main.cpp.o.d b/Release/main.cpp.o.d new file mode 100644 index 0000000..750973c --- /dev/null +++ b/Release/main.cpp.o.d @@ -0,0 +1,77 @@ +Release/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ + ../ServerCore/Log.h ../ServerCore/includes ../ServerCore/File.h \ + ../ServerCore/Object.h ../ServerCore/Socket.h ../ServerCore/Thread.h \ + ../ServerCore/Session.h ../ServerCore/TCPSocket.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/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/includes: + +../ServerCore/EPoll.h: + +../ServerCore/Log.h: + +../ServerCore/includes: + +../ServerCore/File.h: + +../ServerCore/Object.h: + +../ServerCore/Socket.h: + +../ServerCore/Thread.h: + +../ServerCore/Session.h: + +../ServerCore/TCPSocket.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/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: diff --git a/_GET.h b/_GET.h index 25c2354..78dd42c 100644 --- a/_GET.h +++ b/_GET.h @@ -12,15 +12,16 @@ namespace http { 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.getProtocol()); - response.setCode("200"); - response.setText("OK"); - response.setMimeType("text/html"); - session->out << response.getOutput(data); - session->send(); + 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; } }; diff --git a/_GET.h~ b/_GET.h~ deleted file mode 100644 index 13450b5..0000000 --- a/_GET.h~ +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ___GET_h__ -#define ___GET_h__ - -#include "Command.h" -#include "Session.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.getProtocol()); - response.setCode("200"); - response.setText("OK"); - response.setMimeType("text/html"); - session->out << response.getOutput(data); - session->send(); - } - - }; - -} - -#endif diff --git a/_POST.h b/_POST.h index 77291e9..ec79d44 100644 --- a/_POST.h +++ b/_POST.h @@ -9,12 +9,17 @@ 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(); - session.out << response.getOutput(data); - session.send(); + 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; } }; diff --git a/compile~ b/compile~ deleted file mode 100755 index ee4703f..0000000 --- a/compile~ +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -for file in *.cpp -do - filename="${file%.*}" - list="$list $filename.o" - echo -n "Compiling $filename..." - g++ -c $file -I../ServerCore - if [ $? = '0' ] - then - echo "OK" - else - echo "ERROR" - exit -1 - fi - -done - -wait -echo -n "Building static library libServerCore.a..." -ar rcs libServerCore.a $list -if [ $? = '0' ] -then - echo "OK" -else - echo "ERROR" - exit -1 -fi - -rm *.o -rm *~ diff --git a/main.cpp b/main.cpp index 9068abd..69dfef5 100644 --- a/main.cpp +++ b/main.cpp @@ -16,9 +16,9 @@ int main(int argc, char **argv) { std::string ipAddress = "0.0.0.0"; - EPoll ePoll; + core::EPoll ePoll; - core::HTTPServer http(ePoll, core::IPAddress(ipAddress, 8090), "http"); + http::HTTPServer http(ePoll, core::IPAddress(ipAddress, 8090)); core::ConsoleServer console(ePoll, core::IPAddress(ipAddress, 1027)); console.service->commands.add(ePoll); diff --git a/main.cpp~ b/main.cpp~ deleted file mode 100644 index 2d55c84..0000000 --- a/main.cpp~ +++ /dev/null @@ -1,41 +0,0 @@ -#include "includes" -#include "EPoll.h" -#include "ConsoleServer.h" -#include "HTTPServer.h" -#include "Exception.h" -#include "File.h" -#include "Log.h" -#include "IPAddress.h" - -int main(int argc, char **argv) { - - try { - - core::Log(new core::File("/tmp/http.log", O_WRONLY | O_APPEND | O_CREAT, 0644)); - core::Log(core::LOG_INFO) << "HTTP Server starting. Build " << __DATE__ << " " << __TIME__; - - std::string ipAddress = "0.0.0.0"; - - EPoll ePoll; - - core::HTTPServer http(ePoll, core::IPAddress(ipAddress, 8090), "http"); - - core::ConsoleServer console(ePoll, core::IPAddress(ipAddress, 1027)); - console.service.commands.add(ePoll); - console.service.commands.add(http); - console.service.commands.add(console); - ePoll.start(4, 1000); - - while(true) - sleep(300); - - ePoll.stop(); - - } - - catch(core::Exception exception) { - std::cout << exception.text << " Error reason is '" << strerror(exception.errorNumber) << "' in file " << exception.file << " at line " << exception.line << std::endl; - sleep(10); - } - -}