More stuff on HTTPPage structure.

This commit is contained in:
root 2019-05-31 14:25:19 -07:00
parent 2e67e9ed4a
commit 2a7c27dac5
14 changed files with 128 additions and 59 deletions

Binary file not shown.

View File

@ -9,9 +9,9 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../ServerCore/Exception.h ../ServerCore/File.h ../ServerCore/Log.h \
../ServerCore/IPAddress.h HTTPService.h ../ServerCore/Service.h \
HTTPSessions.h ../ServerCore/Header.h ../ServerCore/Response.h \
PageList.h ../ServerCore/CommandList.h __index.h __setupadmin.h \
__favicon_ico.h HTTPHandler.h ../ServerCore/Command.h \
../ServerCore/Session.h
PageList.h ../ServerCore/CommandList.h ../ServerCore/Session.h __index.h \
HTTPPage.h HTTPSession.h __setupadmin.h __favicon_ico.h HTTPHandler.h \
../ServerCore/Command.h
../ServerCore/includes:
@ -71,8 +71,14 @@ PageList.h:
../ServerCore/CommandList.h:
../ServerCore/Session.h:
__index.h:
HTTPPage.h:
HTTPSession.h:
__setupadmin.h:
__favicon_ico.h:
@ -80,5 +86,3 @@ __favicon_ico.h:
HTTPHandler.h:
../ServerCore/Command.h:
../ServerCore/Session.h:

View File

@ -15,7 +15,7 @@ namespace http {
HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(header, response);
std::stringstream content;
if(((HTTPService &)session->service).pageList.processRequest(header.getPath() + " ", session, content)) {
if(((HTTPService &)session->service).pageList.processRequest(header.getPath() + " ", session, httpSession, content)) {
response.setProtocol(header.requestProtocol());
response.setCode("200");
response.setText("OK");

19
HTTPPage.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef __HTTPPage_h__
#define __HTTPPage_h__
#include "HTTPSession.h"
namespace http {
class HTTPPage : public core::Object {
public:
virtual int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) {
return false;
}
};
}
#endif

25
HTTPPageList.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "HTTPPageList.h"
namespace http {
bool HTTPPageList::processRequest(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) {
for(auto *page : pages) {
if(page->check(request)) {
page->processCommand(request, session, httpSession, data);
return true;
}
}
return false;
}
void HTTPPageList::add(HTTPPage &page, std::string name) {
page.setName(name);
pages.push_back(&command);
}
void HTTPPageList::remove(HTTPPage &page) {}
}

38
HTTPPageList.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef __HTTPPageList_h__
#define __HTTPPageList_h__
#include "Session.h"
#include "__index.h"
#include "__setupadmin.h"
#include "__favicon_ico.h"
namespace http {
class HTTPPageList {
public:
HTTPPageList() {
add(index, "/ ");
add(setupadmin, "/setupadmin ");
add(favicon_ico, "/favicon.ico");
}
bool processRequest(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data);
void add(HTTPPage &page, std::string name = "");
void remove(HTTPPage &page);
protected:
std::vector<HTTPPage *> pages;
private:
__index index;
__setupadmin setupadmin;
__favicon_ico favicon_ico;
};
}
#endif

View File

@ -5,16 +5,16 @@
## Debug
ProjectName :=HTTPServer
ConfigurationName :=Debug
WorkspacePath :=/home/bradarant/barant
ProjectPath :=/home/bradarant/barant/HTTPServer
WorkspacePath :=/home/barant
ProjectPath :=/home/barant/barant/HTTPServer
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Brad Arant
Date :=31/05/19
CodeLitePath :=/home/bradarant/.codelite
User :=root
Date :=05/31/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
@ -60,7 +60,7 @@ AS := /usr/bin/x86_64-linux-gnu-as
## User defined environment variables
##
CodeLiteDir:=/usr/share/codelite
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix)
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix)
@ -92,7 +92,7 @@ PreBuild:
## Objects
##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/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
@ -100,7 +100,7 @@ $(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/bradarant/barant/HTTPServer/HTTPSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSession.cpp$(ObjectSuffix) $(IncludePath)
$(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
@ -108,7 +108,7 @@ $(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/bradarant/barant/HTTPServer/HTTPSessions.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPSessions.cpp$(ObjectSuffix) $(IncludePath)
$(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
@ -116,13 +116,21 @@ $(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix): HTTPSessions.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPSessions.cpp$(PreprocessSuffix) HTTPSessions.cpp
$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix): HTTPHandler.cpp $(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/HTTPServer/HTTPHandler.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IncludePath)
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPHandler.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix): HTTPHandler.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPHandler.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPHandler.cpp$(DependSuffix) -MM HTTPHandler.cpp
$(IntermediateDirectory)/HTTPHandler.cpp$(PreprocessSuffix): HTTPHandler.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPHandler.cpp$(PreprocessSuffix) HTTPHandler.cpp
$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix): HTTPPageList.cpp $(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/barant/HTTPServer/HTTPPageList.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix): HTTPPageList.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/HTTPPageList.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/HTTPPageList.cpp$(DependSuffix) -MM HTTPPageList.cpp
$(IntermediateDirectory)/HTTPPageList.cpp$(PreprocessSuffix): HTTPPageList.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/HTTPPageList.cpp$(PreprocessSuffix) HTTPPageList.cpp
-include $(IntermediateDirectory)/*$(DependSuffix)
##

View File

@ -13,8 +13,10 @@
<File Name="HTTPHandler.h"/>
<File Name="__setupadmin.h"/>
<File Name="__index.h"/>
<File Name="PageList.h"/>
<File Name="__favicon_ico.h"/>
<File Name="HTTPPage.h"/>
<File Name="HTTPPageList.h"/>
<File Name="HTTPPageList.cpp"/>
</VirtualDirectory>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>

View File

@ -3,7 +3,7 @@
#include "Service.h"
#include "HTTPSessions.h"
#include "PageList.h"
#include "HTTPPageList.h"
#include "Exception.h"
#include "HTTPHandler.h"
@ -18,7 +18,7 @@ namespace http {
}
HTTPSessions httpSessions;
PageList pageList;
HTTPPageList pageList;
private:
HTTPHandler getHandler;

View File

@ -12,7 +12,6 @@ namespace http {
}
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;

View File

@ -1,29 +0,0 @@
#ifndef __PageList_h__
#define __PageList_h__
#include "CommandList.h"
#include "__index.h"
#include "__setupadmin.h"
#include "__favicon_ico.h"
namespace http {
class PageList : public core::CommandList {
public:
PageList() {
add(index, "/ ");
add(setupadmin, "/setupadmin ");
add(favicon_ico, "/favicon.ico");
}
private:
__index index;
__setupadmin setupadmin;
__favicon_ico favicon_ico;
};
}
#endif

View File

@ -1,11 +1,13 @@
#ifndef ____favicon_ico_h__
#define ____favicon_ico_h__
#include "HTTPPage.h"
namespace http {
class __favicon_ico : public core::Command {
class __favicon_ico : public HTTPPage {
int processCommand(std::string request, core::Session *session, std::stringstream &data) override {
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override {
data << std::string(header_data);
@ -76,8 +78,7 @@ namespace http {
"````````````````````````````````[`,^I]@W.JXR)*HQ)*HQ)*HQ)*HQ)*HQ"
")*HQ)*HQ)*HQ)*HQ)*HQ2[(RLMXX]P@_````````````````````````````````"
"````````````````````````````````````````^PH_U/,[J-@W@<8T3[4R+*TQ"
"+ZTQ6;@SA\\@UK=LWV_<\\_@P_````````````````````````````````````````"
"";
"+ZTQ6;@SA\\@UK=LWV_<\\_@P_````````````````````````````````````````";
};
}

View File

@ -1,15 +1,17 @@
#ifndef ____index_h__
#define ____index_h__
#include "HTTPPage.h"
namespace http {
class __index : public core::Command {
class __index : public HTTPPage {
int processCommand(std::string request, core::Session *session, std::stringstream &data) override {
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override {
data << "<http><head></head><body style=\"background: #006; color: #fff;\">\
<form action=\"setupadmin\" method=\"POST\"><div style=\"background: #44C; text: #888; padding: 20px;\"><p>You have successfully set up a JETServer.\
<br>Session Id: \
<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>";

View File

@ -3,14 +3,14 @@
namespace http {
class __setupadmin : public core::Command {
class __setupadmin : public HTTPPage {
int processCommand(std::string request, core::Session *session, std::stringstream &data) override {
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, std::stringstream &data) override {
data << "<http><head></head><body style=\"background: #006; color: #fff;\">\
<form action=\"setupadmin\" method=\"POST\"><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: \
<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>";