Compiling initial version.

This commit is contained in:
Brad Arant 2019-03-03 20:41:41 -08:00
parent cf08375d32
commit a0aa6fb0d8
19 changed files with 408 additions and 147 deletions

1
Debug/.d Normal file
View File

@ -0,0 +1 @@

BIN
Debug/HTTPServer Executable file

Binary file not shown.

BIN
Debug/main.cpp.o Normal file

Binary file not shown.

77
Debug/main.cpp.o.d Normal file
View File

@ -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:

View File

@ -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

110
HTTPServer.mk Normal file
View File

@ -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/

112
HTTPServer.project Normal file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="HTTPServer" Version="10.0.0" InternalType="Console">
<Description/>
<Dependencies/>
<VirtualDirectory Name="src">
<File Name="HTTPServer.h"/>
<File Name="HTTPService.h"/>
<File Name="_GET.h"/>
<File Name="_POST.h"/>
<File Name="main.cpp"/>
</VirtualDirectory>
<Settings Type="Executable">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
<IncludePath Value="."/>
</Compiler>
<Linker Options="">
<LibraryPath Value="."/>
</Linker>
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g;-O0;-Wall" C_Options="-g;-O0;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
<IncludePath Value="../ServerCore/"/>
</Compiler>
<Linker Options="" Required="yes">
<LibraryPath Value="../ServerCore/Debug/"/>
<Library Value="ServerCore"/>
<Library Value="pthread"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="no">
<RebuildCommand/>
<CleanCommand/>
<BuildCommand/>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory/>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
<Configuration Name="Release" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-O2;-Wall" C_Options="-O2;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
<IncludePath Value="../ServerCore"/>
<Preprocessor Value="NDEBUG"/>
</Compiler>
<Linker Options="" Required="yes">
<LibraryPath Value="../ServerCore/Debug"/>
<Library Value="ServerCore"/>
<Library Value="pthread"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="no">
<RebuildCommand/>
<CleanCommand/>
<BuildCommand/>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory/>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
</Settings>
</CodeLite_Project>

1
HTTPServer.txt Normal file
View File

@ -0,0 +1 @@
./Release/main.cpp.o

View File

@ -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:

1
Release/.d Normal file
View File

@ -0,0 +1 @@

BIN
Release/HTTPServer Executable file

Binary file not shown.

BIN
Release/main.cpp.o Normal file

Binary file not shown.

77
Release/main.cpp.o.d Normal file
View File

@ -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:

19
_GET.h
View File

@ -12,15 +12,16 @@ namespace http {
public:
int processCommand(std::string request, core::Session *session) override {
core::Header header(request);
std::string data = "<html><head></head><body><h1>This Is A Test</h1></body></html>";
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 = "<html><head></head><body><h1>This Is A Test</h1></body></html>";
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;
}
};

28
_GET.h~
View File

@ -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 = "<html><head></head><body><h1>This Is A Test</h1></body></html>";
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

17
_POST.h
View File

@ -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 = "<html><head></head><body><h1>This Is A Test</h1></body></html>";
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 = "<html><head></head><body><h1>This Is A Test</h1></body></html>";
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;
}
};

View File

@ -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 *~

View File

@ -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);

View File

@ -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);
}
}