More development.

This commit is contained in:
Brad Arant 2019-09-13 10:30:20 -07:00
parent a064615843
commit ed39ea0b7b
11 changed files with 91 additions and 51 deletions

Binary file not shown.

View File

@ -1,39 +1,46 @@
Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../ServerCore/Log.h ../ServerCore/includes ../ServerCore/File.h \ ../CoreUtils/Log.h ../CoreUtils/includes ../CoreUtils/File.h \
../ServerCore/Object.h ../ServerCore/Socket.h ../ServerCore/Thread.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/Session.h ../ServerCore/TCPSocket.h \
../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \ ../ServerCore/IPAddress.h ../ServerCore/SessionFilter.h \
../ServerCore/Command.h ../ServerCore/ConsoleServer.h \ ../ServerCore/Command.h ../ServerCore/ConsoleService.h \
../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ ../ServerCore/Service.h ../ServerCore/CommandList.h \
../ServerCore/CommandList.h ../ServerCore/IPAddressList.h \ ../ServerCore/ConsoleSession.h ../ServerCore/TerminalSession.h \
../ServerCore/EPoll.h ../ServerCore/Exception.h ../ServerCore/File.h \ ../ServerCore/TCPServerSocket.h ../ServerCore/IPAddressList.h \
../ServerCore/Log.h ../ServerCore/IPAddress.h HTTPService.h \ ../CoreUtils/Exception.h ../CoreUtils/File.h ../ServerCore/IPAddress.h \
../ServerCore/Service.h HTTPSessions.h HTTPRequest.h \ HTTPService.h ../ServerCore/Service.h HTTPSessions.h HTTPRequest.h \
../CoreUtils/PString.h ../CoreUtils/includes ../CoreUtils/IMFMessage.h \ ../CoreUtils/PString.h ../CoreUtils/IMFMessage.h ../CoreUtils/PString.h \
../CoreUtils/PString.h ../CoreUtils/IMFHeader.h \ ../CoreUtils/IMFHeader.h ../CoreUtils/IMFRequest.h \
../CoreUtils/IMFRequest.h ../CoreUtils/IMFBody.h \ ../CoreUtils/IMFBody.h ../CoreUtils/IMFRequest.h \
../CoreUtils/IMFRequest.h ../CoreUtils/IMFResponse.h \ ../CoreUtils/IMFResponse.h ../CoreUtils/IMFMessage.h \
../CoreUtils/IMFMessage.h HTTPPageList.h ../ServerCore/Session.h \ ../ServerCore/Command.h ../ServerCore/Session.h HTTPPageList.h __index.h \
__index.h HTTPPage.h HTTPSession.h ../JET/Variables.h __script.h \ HTTPPage.h HTTPSession.h ../JET/Variables.h __script.h __editview.h \
__editview.h __style.h __setupadmin.h __favicon_ico.h __welcome.h \ __style.h __setupadmin.h __favicon_ico.h __welcome.h \
../BMAMySQL/BMAMySQL.h __mainmenu.h __newview.h __configure.h \ ../BMAMySQL/BMAMySQL.h __mainmenu.h __newview.h __configure.h \
__viewlist.h ../CoreUtils/Directory.h ../CoreUtils/DirectoryEntry.h \ __viewlist.h ../CoreUtils/Directory.h ../CoreUtils/DirectoryEntry.h \
HTTPHandler.h ../ServerCore/Command.h HTTPHandler.h
../ServerCore/includes: ../ServerCore/includes:
../ServerCore/EPoll.h: ../ServerCore/EPoll.h:
../ServerCore/Log.h: ../CoreUtils/Log.h:
../ServerCore/includes: ../CoreUtils/includes:
../ServerCore/File.h: ../CoreUtils/File.h:
../ServerCore/Object.h: ../ServerCore/Object.h:
../ServerCore/includes:
../CoreUtils/LogListener.h:
../ServerCore/Socket.h: ../ServerCore/Socket.h:
../ServerCore/Object.h:
../ServerCore/Thread.h: ../ServerCore/Thread.h:
../ServerCore/Session.h: ../ServerCore/Session.h:
@ -46,23 +53,23 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \
../ServerCore/Command.h: ../ServerCore/Command.h:
../ServerCore/ConsoleServer.h: ../ServerCore/ConsoleService.h:
../ServerCore/TCPServerSocket.h:
../ServerCore/Service.h: ../ServerCore/Service.h:
../ServerCore/CommandList.h: ../ServerCore/CommandList.h:
../ServerCore/ConsoleSession.h:
../ServerCore/TerminalSession.h:
../ServerCore/TCPServerSocket.h:
../ServerCore/IPAddressList.h: ../ServerCore/IPAddressList.h:
../ServerCore/EPoll.h: ../CoreUtils/Exception.h:
../ServerCore/Exception.h: ../CoreUtils/File.h:
../ServerCore/File.h:
../ServerCore/Log.h:
../ServerCore/IPAddress.h: ../ServerCore/IPAddress.h:
@ -76,8 +83,6 @@ HTTPRequest.h:
../CoreUtils/PString.h: ../CoreUtils/PString.h:
../CoreUtils/includes:
../CoreUtils/IMFMessage.h: ../CoreUtils/IMFMessage.h:
../CoreUtils/PString.h: ../CoreUtils/PString.h:
@ -94,10 +99,12 @@ HTTPRequest.h:
../CoreUtils/IMFMessage.h: ../CoreUtils/IMFMessage.h:
HTTPPageList.h: ../ServerCore/Command.h:
../ServerCore/Session.h: ../ServerCore/Session.h:
HTTPPageList.h:
__index.h: __index.h:
HTTPPage.h: HTTPPage.h:
@ -133,5 +140,3 @@ __viewlist.h:
../CoreUtils/DirectoryEntry.h: ../CoreUtils/DirectoryEntry.h:
HTTPHandler.h: HTTPHandler.h:
../ServerCore/Command.h:

View File

@ -10,19 +10,18 @@ namespace http {
int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) { int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) {
core::Log(core::LOG_DEBUG_1) << request;
coreutils::PString request1(request); coreutils::PString request1(request);
HTTPRequest httpRequest(request1); HTTPRequest httpRequest(request1);
HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(httpRequest); HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(httpRequest);
std::stringstream content; std::stringstream content;
if(((HTTPService &)session->service).pageList.processRequest(httpRequest, session, httpSession, content)) { if(((HTTPService &)session->service).pageList.processRequest(httpRequest, session, httpSession, content)) {
std::string contentType = httpRequest.getHeader("Content-Type"); std::string contentType = httpRequest.getHeader("Content-Type");
if(contentType == "multipart/form-data") { if(contentType == "multipart/form-data") {
coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest.getBody(); coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest.getBody();
core::Log(core::LOG_DEBUG_2) << "username is " << formdata->getByName("username") << std::endl; coreutils::Log(coreutils::LOG_DEBUG_2) << "username is '" << formdata->getByName("username") << "'";
} }
httpRequest.response.setCode("200"); httpRequest.response.setCode("200");

17
HTTPPageCache.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef __HTTPPageCache_h__
#define __HTTPPageCache_h__
namespace http {
class HTTPPageCache {
public:
std::string
};
}
#endif

View File

@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
CurrentFileFullPath := CurrentFileFullPath :=
User :=Brad Arant User :=Brad Arant
Date :=16/08/19 Date :=12/09/19
CodeLitePath :=/home/bradarant/.codelite CodeLitePath :=/home/bradarant/.codelite
LinkerName :=/usr/bin/x86_64-linux-gnu-g++ LinkerName :=/usr/bin/x86_64-linux-gnu-g++
SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC

View File

@ -26,6 +26,7 @@
<File Name="HTTPRequest.h"/> <File Name="HTTPRequest.h"/>
<File Name="__configure.h"/> <File Name="__configure.h"/>
<File Name="__viewlist.h"/> <File Name="__viewlist.h"/>
<File Name="HTTPPageCache.h"/>
</VirtualDirectory> </VirtualDirectory>
<Dependencies Name="Debug"/> <Dependencies Name="Debug"/>
<Dependencies Name="Release"/> <Dependencies Name="Release"/>

View File

@ -21,7 +21,7 @@ namespace http {
httpSession = createHTTPSession(); httpSession = createHTTPSession();
httpRequest.response.setCookie("sessionId", httpSession->getSessionId()); httpRequest.response.setCookie("sessionId", httpSession->getSessionId());
} }
core::Log(core::LOG_DEBUG_1) << "http session: " << "(" << sessionId << ") " << httpSession; coreutils::Log(coreutils::LOG_DEBUG_1) << "http session: " << "(" << sessionId << ") " << httpSession;
} else { } else {
httpSession = createHTTPSession(); httpSession = createHTTPSession();
@ -44,4 +44,16 @@ namespace http {
return uuid_s; return uuid_s;
} }
int HTTPSessions::processCommand(std::string command, core::Session *session, std::stringstream &data) {
if(sessions.size() > 0) {
int seq = 0;
for(auto httpSession: sessions)
data << "|" << ++seq << "|" << httpSession.second->getSessionId() << "|" << std::endl;
}
else
data << "There are no sessions active." << std::endl;
return 1;
}
} }

View File

@ -2,17 +2,21 @@
#define __HTTPSessions_h__ #define __HTTPSessions_h__
#include "HTTPRequest.h" #include "HTTPRequest.h"
#include "Command.h"
#include "Session.h"
namespace http { namespace http {
class HTTPSession; class HTTPSession;
class HTTPSessions { class HTTPSessions : public core::Command {
public: public:
HTTPSession * findSessionByHeader(HTTPRequest &httpRequest); HTTPSession * findSessionByHeader(HTTPRequest &httpRequest);
HTTPSession * findSessionById(std::string sessionId, HTTPRequest &httpRequest); HTTPSession * findSessionById(std::string sessionId, HTTPRequest &httpRequest);
int processCommand(std::string request, core::Session *session, std::stringstream &data);
private: private:
HTTPSession * createHTTPSession(); HTTPSession * createHTTPSession();
std::string generateSessionId(); std::string generateSessionId();

View File

@ -1,6 +1,6 @@
#include "includes" #include "includes"
#include "EPoll.h" #include "EPoll.h"
#include "ConsoleServer.h" #include "ConsoleService.h"
#include "Exception.h" #include "Exception.h"
#include "File.h" #include "File.h"
#include "Log.h" #include "Log.h"
@ -11,8 +11,8 @@ int main(int argc, char **argv) {
try { try {
core::Log(new core::File("/tmp/http.log", O_WRONLY | O_APPEND | O_CREAT, 0644)); coreutils::Log(new coreutils::File("/tmp/http.log", O_WRONLY | O_APPEND | O_CREAT, 0644));
core::Log(core::LOG_INFO) << "HTTP Server starting. Build " << __DATE__ << " " << __TIME__; coreutils::Log(coreutils::LOG_INFO) << "HTTP Server starting. Build " << __DATE__ << " " << __TIME__;
std::string ipAddress = "0.0.0.0"; std::string ipAddress = "0.0.0.0";
@ -21,12 +21,14 @@ int main(int argc, char **argv) {
http::HTTPService httpService; http::HTTPService httpService;
core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8080)); core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8080));
core::Service consoleService; core::ConsoleService consoleService;
core::ConsoleServer console(ePoll, consoleService, core::IPAddress(ipAddress, 1027)); core::TCPServerSocket console(ePoll, consoleService, core::IPAddress(ipAddress, 1027));
consoleService.commands.add(ePoll);
consoleService.commands.add(http); consoleService.commands.add(ePoll, "threads");
consoleService.commands.add(console); consoleService.commands.add(httpService.httpSessions, "sessions");
ePoll.start(4, 1000); consoleService.commands.add(console, "consoles");
consoleService.commands.add(consoleService.commands, "help");
ePoll.start(16, 1000);
while(true) while(true)
sleep(300); sleep(300);
@ -35,7 +37,7 @@ int main(int argc, char **argv) {
} }
catch(core::Exception exception) { catch(coreutils::Exception exception) {
std::cout << exception.text << " Error reason is '" << strerror(exception.errorNumber) << "' in file " << exception.file << " at line " << exception.line << std::endl; std::cout << exception.text << " Error reason is '" << strerror(exception.errorNumber) << "' in file " << exception.file << " at line " << exception.line << std::endl;
sleep(10); sleep(10);
} }