Breaking away from pure HTML towards JETServer.

This commit is contained in:
Brad Arant 2019-05-21 16:39:42 -07:00
parent c89c36c49a
commit f4938937d1
23 changed files with 313 additions and 68 deletions

View File

@ -1 +0,0 @@

Binary file not shown.

Binary file not shown.

View File

@ -7,9 +7,9 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ ../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \
../ServerCore/CommandList.h ../ServerCore/EPoll.h \ ../ServerCore/CommandList.h ../ServerCore/EPoll.h \
../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \ ../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \
../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h _GET.h \ ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h \
../ServerCore/Command.h ../ServerCore/Session.h ../ServerCore/Header.h \ HTTPSessions.h ../ServerCore/Header.h ../ServerCore/Response.h _GET.h \
../ServerCore/Response.h _POST.h ../ServerCore/Command.h ../ServerCore/Session.h _POST.h
../ServerCore/includes: ../ServerCore/includes:
@ -59,14 +59,16 @@ HTTPService.h:
../ServerCore/Service.h: ../ServerCore/Service.h:
HTTPSessions.h:
../ServerCore/Header.h:
../ServerCore/Response.h:
_GET.h: _GET.h:
../ServerCore/Command.h: ../ServerCore/Command.h:
../ServerCore/Session.h: ../ServerCore/Session.h:
../ServerCore/Header.h:
../ServerCore/Response.h:
_POST.h: _POST.h:

View File

@ -5,22 +5,22 @@
## Debug ## Debug
ProjectName :=HTTPServer ProjectName :=HTTPServer
ConfigurationName :=Debug ConfigurationName :=Debug
WorkspacePath :=/home/barant/Development/BMA/server_core WorkspacePath :=/home/barant/barant
ProjectPath :=/home/barant/Development/BMA/server_core/HTTPServer ProjectPath :=/home/barant/barant/HTTPServer
IntermediateDirectory :=./Debug IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory) OutDir := $(IntermediateDirectory)
CurrentFileName := CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
CurrentFileFullPath := CurrentFileFullPath :=
User :=Brad Arant User :=
Date :=12/03/19 Date :=05/18/19
CodeLitePath :=/home/barant/.codelite CodeLitePath :=/home/barant/.codelite
LinkerName :=g++ LinkerName :=/usr/bin/x86_64-linux-gnu-g++
SharedObjectLinkerName :=g++ -shared -fPIC SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC
ObjectSuffix :=.o ObjectSuffix :=.o
DependSuffix :=.o.d DependSuffix :=.o.d
PreprocessSuffix :=.o.i PreprocessSuffix :=.i
DebugSwitch :=-gstab DebugSwitch :=-g
IncludeSwitch :=-I IncludeSwitch :=-I
LibrarySwitch :=-l LibrarySwitch :=-l
OutputSwitch :=-o OutputSwitch :=-o
@ -31,7 +31,7 @@ OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors := Preprocessors :=
ObjectSwitch :=-o ObjectSwitch :=-o
ArchiveOutputSwitch := ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E PreprocessOnlySwitch :=-E
ObjectsFileList :="HTTPServer.txt" ObjectsFileList :="HTTPServer.txt"
PCHCompileFlags := PCHCompileFlags :=
MakeDirCommand :=mkdir -p MakeDirCommand :=mkdir -p
@ -39,28 +39,28 @@ LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)../ServerCore/ IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)../ServerCore/
IncludePCH := IncludePCH :=
RcIncludePath := RcIncludePath :=
Libs := $(LibrarySwitch)ServerCore $(LibrarySwitch)pthread Libs := $(LibrarySwitch)ServerCore $(LibrarySwitch)pthread $(LibrarySwitch)uuid
ArLibs := "ServerCore" "pthread" ArLibs := "ServerCore" "pthread" "uuid"
LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)../ServerCore/Debug/ LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)../ServerCore/Debug/
## ##
## Common variables ## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables ## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
## ##
AR := ar rcus AR := /usr/bin/x86_64-linux-gnu-ar rcu
CXX := g++ CXX := /usr/bin/x86_64-linux-gnu-g++
CC := gcc CC := /usr/bin/x86_64-linux-gnu-gcc
CXXFLAGS := -g -O0 -Wall $(Preprocessors) CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors) CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS := ASFLAGS :=
AS := as AS := /usr/bin/x86_64-linux-gnu-as
## ##
## User defined environment variables ## User defined environment variables
## ##
CodeLiteDir:=/usr/share/codelite 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 ## Objects
## ##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix) $(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 $(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 @$(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 $(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(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) -include $(IntermediateDirectory)/*$(DependSuffix)
## ##

View File

@ -7,7 +7,18 @@
<File Name="_GET.h"/> <File Name="_GET.h"/>
<File Name="_POST.h"/> <File Name="_POST.h"/>
<File Name="main.cpp"/> <File Name="main.cpp"/>
<File Name="HTTPSession.h"/>
<File Name="HTTPSession.cpp"/>
<File Name="HTTPSessions.h"/>
<File Name="HTTPSessions.cpp"/>
<File Name="_GET.cpp"/>
<File Name="src/__index.h"/>
<File Name="src/__setupadmin.h"/>
<File Name="src/PageService.h" ExcludeProjConfig=""/>
<File Name="src/_POST.cpp"/>
</VirtualDirectory> </VirtualDirectory>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
<Settings Type="Executable"> <Settings Type="Executable">
<GlobalSettings> <GlobalSettings>
<Compiler Options="" C_Options="" Assembler=""> <Compiler Options="" C_Options="" Assembler="">
@ -27,6 +38,7 @@
<LibraryPath Value="../ServerCore/Debug/"/> <LibraryPath Value="../ServerCore/Debug/"/>
<Library Value="ServerCore"/> <Library Value="ServerCore"/>
<Library Value="pthread"/> <Library Value="pthread"/>
<Library Value="uuid"/>
</Linker> </Linker>
<ResourceCompiler Options="" Required="no"/> <ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
@ -34,7 +46,7 @@
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;"> <Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]> <![CDATA[]]>
</Environment> </Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no"> <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="../../../../usr/bin/gdb" IsExtended="no">
<DebuggerSearchPaths/> <DebuggerSearchPaths/>
<PostConnectCommands/> <PostConnectCommands/>
<StartupCommands/> <StartupCommands/>
@ -108,6 +120,4 @@
</Completion> </Completion>
</Configuration> </Configuration>
</Settings> </Settings>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
</CodeLite_Project> </CodeLite_Project>

View File

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

View File

@ -2,6 +2,8 @@
#define __HTTPService_h__ #define __HTTPService_h__
#include "Service.h" #include "Service.h"
#include "HTTPSessions.h"
#include "Exception.h"
#include "_GET.h" #include "_GET.h"
#include "_POST.h" #include "_POST.h"
@ -14,6 +16,9 @@ namespace http {
commands.add(get, "GET "); commands.add(get, "GET ");
commands.add(post, "POST "); commands.add(post, "POST ");
} }
HTTPSessions httpSessions;
// PageService pageService;
private: private:
_GET get; _GET get;

14
HTTPSession.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "HTTPSession.h"
namespace http {
HTTPSession::HTTPSession(std::string sessionId) {
this->sessionId = sessionId;
}
std::string HTTPSession::getSessionId() {
return sessionId;
}
}

22
HTTPSession.h Normal file
View File

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

40
HTTPSessions.cpp Normal file
View File

@ -0,0 +1,40 @@
#include "HTTPSessions.h"
#include "HTTPSession.h"
#include "Log.h"
#include <uuid/uuid.h>
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;
}
}

27
HTTPSessions.h Normal file
View File

@ -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<std::string, HTTPSession*> sessions;
};
}
#endif

Binary file not shown.

Binary file not shown.

View File

@ -5,12 +5,11 @@ Release/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \ ../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \
../ServerCore/Command.h ../ServerCore/ConsoleServer.h \ ../ServerCore/Command.h ../ServerCore/ConsoleServer.h \
../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ ../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \
../ServerCore/CommandList.h ../ServerCore/EPoll.h HTTPServer.h \ ../ServerCore/CommandList.h ../ServerCore/EPoll.h \
../ServerCore/TCPServerSocket.h ../ServerCore/Session.h \ ../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \
../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h _GET.h \ ../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h _GET.h \
../ServerCore/Command.h ../ServerCore/Header.h ../ServerCore/Response.h \ ../ServerCore/Command.h ../ServerCore/Session.h ../ServerCore/Header.h \
_POST.h ../ServerCore/Exception.h ../ServerCore/File.h \ ../ServerCore/Response.h _POST.h
../ServerCore/Log.h
../ServerCore/includes: ../ServerCore/includes:
@ -48,11 +47,11 @@ Release/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../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: ../ServerCore/IPAddress.h:
@ -64,14 +63,10 @@ _GET.h:
../ServerCore/Command.h: ../ServerCore/Command.h:
../ServerCore/Session.h:
../ServerCore/Header.h: ../ServerCore/Header.h:
../ServerCore/Response.h: ../ServerCore/Response.h:
_POST.h: _POST.h:
../ServerCore/Exception.h:
../ServerCore/File.h:
../ServerCore/Log.h:

28
_GET.cpp Normal file
View File

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

14
_GET.h
View File

@ -5,24 +5,14 @@
#include "Session.h" #include "Session.h"
#include "Header.h" #include "Header.h"
#include "Response.h" #include "Response.h"
#include "Log.h"
namespace http { namespace http {
class _GET : public core::Command { class _GET : public core::Command {
public: public:
int processCommand(std::string request, core::Session *session) override { int processCommand(std::string request, core::Session *session, std::stringstream &data) 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;
}
}; };

15
_POST.h
View File

@ -3,24 +3,15 @@
#include "Command.h" #include "Command.h"
#include "Session.h" #include "Session.h"
#include "Header.h"
#include "Response.h"
namespace http { namespace http {
class _POST : public core::Command { class _POST : public core::Command {
public: public:
int processCommand(std::string request, core::Session *session) override { int processCommand(std::string request, core::Session *session, std::stringstream &data) 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

@ -19,7 +19,7 @@ int main(int argc, char **argv) {
core::EPoll ePoll; core::EPoll ePoll;
http::HTTPService httpService; 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::Service consoleService;
core::ConsoleServer console(ePoll, consoleService, core::IPAddress(ipAddress, 1027)); core::ConsoleServer console(ePoll, consoleService, core::IPAddress(ipAddress, 1027));

27
src/PageService.h Normal file
View File

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

28
src/_POST.cpp Normal file
View File

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

17
src/__index.h Normal file
View File

@ -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 << "<http><head></head><body style=\"background: #006; color: #fff;\">\
<form action=\"setupadmin\"><div style=\"background: #44C; text: #888; padding: 20px;\"><p>You have successfully set up a JETServer.\
<br>Session Id: " + httpSession->getSessionId() + "\
<br>The configuration has not yet been established for this web site.</p>\
<button>Configure</button>\
</div></form></body></html>";
session.send();
}
}

18
src/__setupadmin.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef ____setupadmin_h__
#define ____setupadmin_h__
namespace http {
class __setupadmin : core::Command {
int processCommand(std::string request, core::Session *session) override {
session.out << "<http><head></head><body style=\"background: #006; color: #fff;\">\
<form action=\"setupadmin\"><div style=\"background: #44C; text: #888; padding: 20px;\"><p>Please enter credential information\
for the security officer.<br><input type=\"text\" name=\"username\" size=\"50\">\
<br>Session Id: " + httpSession->getSessionId() + "\
<br>The configuration has not yet been established for this web site.</p>\
<button>Configure</button>\
</div></form></body></html>";
session.send();
}
}