Adjustments to ServerCore changes.
This commit is contained in:
parent
ed39ea0b7b
commit
e7b4ae818f
BIN
Debug/main.cpp.o
BIN
Debug/main.cpp.o
Binary file not shown.
@ -2,24 +2,23 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
|
||||
../CoreUtils/Log.h ../CoreUtils/includes ../CoreUtils/File.h \
|
||||
../ServerCore/Object.h ../ServerCore/includes ../CoreUtils/LogListener.h \
|
||||
../ServerCore/Socket.h ../ServerCore/Object.h ../ServerCore/Thread.h \
|
||||
../ServerCore/Session.h ../ServerCore/TCPSocket.h \
|
||||
../ServerCore/TCPSession.h ../ServerCore/TCPSocket.h \
|
||||
../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \
|
||||
../ServerCore/Command.h ../ServerCore/ConsoleService.h \
|
||||
../ServerCore/Service.h ../ServerCore/CommandList.h \
|
||||
../ServerCore/ConsoleSession.h ../ServerCore/TerminalSession.h \
|
||||
../ServerCore/TCPServerSocket.h ../ServerCore/IPAddressList.h \
|
||||
../ServerCore/Command.h ../ServerCore/ConsoleServer.h \
|
||||
../ServerCore/TCPServer.h ../ServerCore/IPAddressList.h \
|
||||
../ServerCore/CommandList.h ../ServerCore/EPoll.h \
|
||||
../CoreUtils/Exception.h ../CoreUtils/File.h ../ServerCore/IPAddress.h \
|
||||
HTTPService.h ../ServerCore/Service.h HTTPSessions.h HTTPRequest.h \
|
||||
HTTPServer.h HTTPService.h HTTPSessions.h HTTPRequest.h \
|
||||
../CoreUtils/PString.h ../CoreUtils/IMFMessage.h ../CoreUtils/PString.h \
|
||||
../CoreUtils/IMFHeader.h ../CoreUtils/IMFRequest.h \
|
||||
../CoreUtils/IMFBody.h ../CoreUtils/IMFRequest.h \
|
||||
../CoreUtils/IMFResponse.h ../CoreUtils/IMFMessage.h \
|
||||
../ServerCore/Command.h ../ServerCore/Session.h HTTPPageList.h __index.h \
|
||||
HTTPPage.h HTTPSession.h ../JET/Variables.h __script.h __editview.h \
|
||||
__style.h __setupadmin.h __favicon_ico.h __welcome.h \
|
||||
../ServerCore/Command.h ../ServerCore/TCPSession.h HTTPPageList.h \
|
||||
__index.h HTTPPage.h HTTPSession.h ../JET/Variables.h __script.h \
|
||||
__editview.h __style.h __setupadmin.h __favicon_ico.h __welcome.h \
|
||||
../BMAMySQL/BMAMySQL.h __mainmenu.h __newview.h __configure.h \
|
||||
__viewlist.h ../CoreUtils/Directory.h ../CoreUtils/DirectoryEntry.h \
|
||||
HTTPHandler.h
|
||||
HTTPHandler.h ../ServerCore/TCPServer.h
|
||||
|
||||
../ServerCore/includes:
|
||||
|
||||
@ -43,7 +42,7 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
|
||||
|
||||
../ServerCore/Thread.h:
|
||||
|
||||
../ServerCore/Session.h:
|
||||
../ServerCore/TCPSession.h:
|
||||
|
||||
../ServerCore/TCPSocket.h:
|
||||
|
||||
@ -53,19 +52,15 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
|
||||
|
||||
../ServerCore/Command.h:
|
||||
|
||||
../ServerCore/ConsoleService.h:
|
||||
../ServerCore/ConsoleServer.h:
|
||||
|
||||
../ServerCore/Service.h:
|
||||
../ServerCore/TCPServer.h:
|
||||
|
||||
../ServerCore/IPAddressList.h:
|
||||
|
||||
../ServerCore/CommandList.h:
|
||||
|
||||
../ServerCore/ConsoleSession.h:
|
||||
|
||||
../ServerCore/TerminalSession.h:
|
||||
|
||||
../ServerCore/TCPServerSocket.h:
|
||||
|
||||
../ServerCore/IPAddressList.h:
|
||||
../ServerCore/EPoll.h:
|
||||
|
||||
../CoreUtils/Exception.h:
|
||||
|
||||
@ -73,9 +68,9 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
|
||||
|
||||
../ServerCore/IPAddress.h:
|
||||
|
||||
HTTPService.h:
|
||||
HTTPServer.h:
|
||||
|
||||
../ServerCore/Service.h:
|
||||
HTTPService.h:
|
||||
|
||||
HTTPSessions.h:
|
||||
|
||||
@ -101,7 +96,7 @@ HTTPRequest.h:
|
||||
|
||||
../ServerCore/Command.h:
|
||||
|
||||
../ServerCore/Session.h:
|
||||
../ServerCore/TCPSession.h:
|
||||
|
||||
HTTPPageList.h:
|
||||
|
||||
@ -140,3 +135,5 @@ __viewlist.h:
|
||||
../CoreUtils/DirectoryEntry.h:
|
||||
|
||||
HTTPHandler.h:
|
||||
|
||||
../ServerCore/TCPServer.h:
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "HTTPHandler.h"
|
||||
#include "HTTPSession.h"
|
||||
#include "HTTPService.h"
|
||||
#include "HTTPServer.h"
|
||||
#include "HTTPRequest.h"
|
||||
#include "PString.h"
|
||||
#include "IMFFormData.h"
|
||||
@ -8,16 +8,16 @@
|
||||
|
||||
namespace http {
|
||||
|
||||
int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) {
|
||||
int HTTPHandler::processCommand(std::string request, core::TCPSession *session, std::stringstream &data) {
|
||||
|
||||
coreutils::PString request1(request);
|
||||
HTTPRequest httpRequest(request1);
|
||||
|
||||
HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(httpRequest);
|
||||
HTTPSession *httpSession = static_cast<HTTPServer &>(session->server).httpSessions.findSessionByHeader(httpRequest);
|
||||
|
||||
std::stringstream content;
|
||||
|
||||
if(((HTTPService &)session->service).pageList.processRequest(httpRequest, session, httpSession, content)) {
|
||||
if(static_cast<HTTPServer &>(session->server).pageList.processRequest(httpRequest, session, httpSession, content)) {
|
||||
std::string contentType = httpRequest.getHeader("Content-Type");
|
||||
if(contentType == "multipart/form-data") {
|
||||
coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest.getBody();
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define __HTTPHandler_h__
|
||||
|
||||
#include "Command.h"
|
||||
#include "Session.h"
|
||||
#include "TCPSession.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace http {
|
||||
@ -10,7 +10,7 @@ namespace http {
|
||||
class HTTPHandler : public core::Command {
|
||||
|
||||
public:
|
||||
int processCommand(std::string request, core::Session *session, std::stringstream &data) override;
|
||||
int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "HTTPSession.h"
|
||||
#include "HTTPRequest.h"
|
||||
#include "Session.h"
|
||||
#include "TCPSession.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace http {
|
||||
@ -23,7 +23,7 @@ namespace http {
|
||||
}
|
||||
|
||||
virtual int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace http {
|
||||
|
||||
bool HTTPPageList::processRequest(HTTPRequest &httpRequest, core::Session *session, HTTPSession *httpSession, std::stringstream &data) {
|
||||
bool HTTPPageList::processRequest(HTTPRequest &httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data) {
|
||||
httpRequest.response.setProtocol(httpRequest.request.getProtocol());
|
||||
for(auto *page : pages) {
|
||||
if(page->check(httpRequest.request.getURI())) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __HTTPPageList_h__
|
||||
#define __HTTPPageList_h__
|
||||
|
||||
#include "Session.h"
|
||||
#include "TCPSession.h"
|
||||
#include "HTTPRequest.h"
|
||||
#include "__index.h"
|
||||
#include "__script.h"
|
||||
@ -34,7 +34,7 @@ namespace http {
|
||||
add(viewlist, "/viewlist");
|
||||
}
|
||||
|
||||
bool processRequest(HTTPRequest &httpRequest, core::Session *session, HTTPSession *httpSession, std::stringstream &data);
|
||||
bool processRequest(HTTPRequest &httpRequest, core::TCPSession *session, HTTPSession *httpSession, std::stringstream &data);
|
||||
|
||||
void add(HTTPPage &page, std::string name = "");
|
||||
|
||||
|
@ -1,31 +1,31 @@
|
||||
#ifndef __HTTPService_h__
|
||||
#define __HTTPService_h__
|
||||
#ifndef __HTTPServer_h__
|
||||
#define __HTTPServer_h__
|
||||
|
||||
#include "Service.h"
|
||||
#include "TCPServer.h"
|
||||
#include "HTTPSessions.h"
|
||||
#include "HTTPPageList.h"
|
||||
#include "Exception.h"
|
||||
#include "HTTPHandler.h"
|
||||
|
||||
namespace http {
|
||||
|
||||
class HTTPService : public core::Service {
|
||||
|
||||
|
||||
class HTTPServer : public core::TCPServer {
|
||||
|
||||
public:
|
||||
HTTPService() {
|
||||
HTTPServer(core::EPoll &ePoll, core::IPAddress ipAddress, HTTPSessions &httpSessions)
|
||||
: TCPServer(ePoll, ipAddress), httpSessions(httpSessions) {
|
||||
commands.add(getHandler, "GET");
|
||||
commands.add(postHandler, "POST");
|
||||
}
|
||||
}
|
||||
|
||||
HTTPSessions httpSessions;
|
||||
HTTPSessions &httpSessions;
|
||||
HTTPPageList pageList;
|
||||
|
||||
private:
|
||||
HTTPHandler getHandler;
|
||||
HTTPHandler postHandler;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -13,7 +13,7 @@ CurrentFileName :=
|
||||
CurrentFilePath :=
|
||||
CurrentFileFullPath :=
|
||||
User :=Brad Arant
|
||||
Date :=12/09/19
|
||||
Date :=18/09/19
|
||||
CodeLitePath :=/home/bradarant/.codelite
|
||||
LinkerName :=/usr/bin/x86_64-linux-gnu-g++
|
||||
SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC
|
||||
|
@ -3,7 +3,6 @@
|
||||
<Description/>
|
||||
<Dependencies/>
|
||||
<VirtualDirectory Name="src">
|
||||
<File Name="HTTPService.h"/>
|
||||
<File Name="main.cpp"/>
|
||||
<File Name="HTTPSession.h"/>
|
||||
<File Name="HTTPSession.cpp"/>
|
||||
@ -27,6 +26,7 @@
|
||||
<File Name="__configure.h"/>
|
||||
<File Name="__viewlist.h"/>
|
||||
<File Name="HTTPPageCache.h"/>
|
||||
<File Name="HTTPServer.h"/>
|
||||
</VirtualDirectory>
|
||||
<Dependencies Name="Debug"/>
|
||||
<Dependencies Name="Release"/>
|
||||
|
@ -44,7 +44,7 @@ namespace http {
|
||||
return uuid_s;
|
||||
}
|
||||
|
||||
int HTTPSessions::processCommand(std::string command, core::Session *session, std::stringstream &data) {
|
||||
int HTTPSessions::processCommand(std::string command, core::TCPSession *session, std::stringstream &data) {
|
||||
if(sessions.size() > 0) {
|
||||
int seq = 0;
|
||||
for(auto httpSession: sessions)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "HTTPRequest.h"
|
||||
#include "Command.h"
|
||||
#include "Session.h"
|
||||
#include "TCPSession.h"
|
||||
|
||||
namespace http {
|
||||
|
||||
@ -15,7 +15,7 @@ namespace http {
|
||||
HTTPSession * findSessionByHeader(HTTPRequest &httpRequest);
|
||||
HTTPSession * findSessionById(std::string sessionId, HTTPRequest &httpRequest);
|
||||
|
||||
int processCommand(std::string request, core::Session *session, std::stringstream &data);
|
||||
int processCommand(std::string request, core::TCPSession *session, std::stringstream &data);
|
||||
|
||||
private:
|
||||
HTTPSession * createHTTPSession();
|
||||
|
@ -5,7 +5,7 @@ namespace http {
|
||||
|
||||
class __configure : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<form name=\"configure\" action=\"setupadmin\" method=\"POST\">" << std::endl;
|
||||
data << " <div class=\"window\"><h1>System Configuration</h1>" << std::endl;
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __editview : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << " <div style=\"position: relative;\">" << std::endl;
|
||||
data << "" << std::endl;
|
||||
|
@ -8,7 +8,7 @@ namespace http {
|
||||
class __favicon_ico : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
@ -8,7 +8,7 @@ namespace http {
|
||||
|
||||
class __index : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<html>" << std::endl;
|
||||
data << " <head>" << std::endl;
|
||||
|
@ -8,7 +8,7 @@ namespace http {
|
||||
class __mainmenu : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
@ -8,7 +8,7 @@ namespace http {
|
||||
class __newview : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __script : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "function serverSend(url, type, receiver, formData, callback) {" << std::endl;
|
||||
data << " var server = new XMLHttpRequest();" << std::endl;
|
||||
|
@ -5,7 +5,7 @@ namespace http {
|
||||
|
||||
class __setupadmin : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "<form name=\"setupadmin\" action=\"setupadmin\" method=\"POST\">" << std::endl;
|
||||
data << " <div class=\"window\"><p>Please enter credential information" << std::endl;
|
||||
|
@ -7,7 +7,7 @@ namespace http {
|
||||
|
||||
class __style : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
int processCommand(std::string request, core::TCPSession *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override {
|
||||
|
||||
data << "body {background: #006;" << std::endl;
|
||||
data << " color: #fff;" << std::endl;
|
||||
|
@ -9,7 +9,7 @@ namespace http {
|
||||
class __viewlist : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
@ -9,7 +9,7 @@ namespace http {
|
||||
class __welcome : public HTTPPage {
|
||||
|
||||
int processCommand(std::string request,
|
||||
core::Session *session,
|
||||
core::TCPSession *session,
|
||||
HTTPSession *httpSession,
|
||||
HTTPRequest &httpRequest,
|
||||
std::stringstream &data) override {
|
||||
|
22
main.cpp
22
main.cpp
@ -1,11 +1,11 @@
|
||||
#include "includes"
|
||||
#include "EPoll.h"
|
||||
#include "ConsoleService.h"
|
||||
#include "ConsoleServer.h"
|
||||
#include "Exception.h"
|
||||
#include "File.h"
|
||||
#include "Log.h"
|
||||
#include "IPAddress.h"
|
||||
#include "HTTPService.h"
|
||||
#include "HTTPServer.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@ -18,17 +18,17 @@ int main(int argc, char **argv) {
|
||||
|
||||
core::EPoll ePoll;
|
||||
|
||||
http::HTTPService httpService;
|
||||
core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8080));
|
||||
http::HTTPSessions httpSessions;
|
||||
http::HTTPServer http(ePoll, core::IPAddress(ipAddress, 8080), httpSessions);
|
||||
// http::HTTPSServer http(ePoll, core::IPAddress(ipAddress, 8143));
|
||||
|
||||
core::ConsoleService consoleService;
|
||||
core::TCPServerSocket console(ePoll, consoleService, core::IPAddress(ipAddress, 1027));
|
||||
core::ConsoleServer console(ePoll, core::IPAddress(ipAddress, 1027));
|
||||
|
||||
consoleService.commands.add(ePoll, "threads");
|
||||
consoleService.commands.add(httpService.httpSessions, "sessions");
|
||||
consoleService.commands.add(console, "consoles");
|
||||
consoleService.commands.add(consoleService.commands, "help");
|
||||
ePoll.start(16, 1000);
|
||||
console.commands.add(ePoll, "threads");
|
||||
console.commands.add(httpSessions, "sessions");
|
||||
console.commands.add(console, "consoles");
|
||||
console.commands.add(console.commands, "help");
|
||||
ePoll.start(2, 1000);
|
||||
|
||||
while(true)
|
||||
sleep(300);
|
||||
|
Loading…
x
Reference in New Issue
Block a user