diff --git a/Debug/main.cpp.o b/Debug/main.cpp.o index a3ba963..04f4bb1 100644 Binary files a/Debug/main.cpp.o and b/Debug/main.cpp.o differ diff --git a/Debug/main.cpp.o.d b/Debug/main.cpp.o.d index 536a531..487d2a0 100644 --- a/Debug/main.cpp.o.d +++ b/Debug/main.cpp.o.d @@ -1,39 +1,46 @@ 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 \ + ../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/IPAddress.h ../ServerCore/SessionFilter.h \ - ../ServerCore/Command.h ../ServerCore/ConsoleServer.h \ - ../ServerCore/TCPServerSocket.h ../ServerCore/Service.h \ - ../ServerCore/CommandList.h ../ServerCore/IPAddressList.h \ - ../ServerCore/EPoll.h ../ServerCore/Exception.h ../ServerCore/File.h \ - ../ServerCore/Log.h ../ServerCore/IPAddress.h HTTPService.h \ - ../ServerCore/Service.h HTTPSessions.h HTTPRequest.h \ - ../CoreUtils/PString.h ../CoreUtils/includes ../CoreUtils/IMFMessage.h \ - ../CoreUtils/PString.h ../CoreUtils/IMFHeader.h \ - ../CoreUtils/IMFRequest.h ../CoreUtils/IMFBody.h \ - ../CoreUtils/IMFRequest.h ../CoreUtils/IMFResponse.h \ - ../CoreUtils/IMFMessage.h HTTPPageList.h ../ServerCore/Session.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/ConsoleService.h \ + ../ServerCore/Service.h ../ServerCore/CommandList.h \ + ../ServerCore/ConsoleSession.h ../ServerCore/TerminalSession.h \ + ../ServerCore/TCPServerSocket.h ../ServerCore/IPAddressList.h \ + ../CoreUtils/Exception.h ../CoreUtils/File.h ../ServerCore/IPAddress.h \ + HTTPService.h ../ServerCore/Service.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 \ ../BMAMySQL/BMAMySQL.h __mainmenu.h __newview.h __configure.h \ __viewlist.h ../CoreUtils/Directory.h ../CoreUtils/DirectoryEntry.h \ - HTTPHandler.h ../ServerCore/Command.h + HTTPHandler.h ../ServerCore/includes: ../ServerCore/EPoll.h: -../ServerCore/Log.h: +../CoreUtils/Log.h: -../ServerCore/includes: +../CoreUtils/includes: -../ServerCore/File.h: +../CoreUtils/File.h: ../ServerCore/Object.h: +../ServerCore/includes: + +../CoreUtils/LogListener.h: + ../ServerCore/Socket.h: +../ServerCore/Object.h: + ../ServerCore/Thread.h: ../ServerCore/Session.h: @@ -46,23 +53,23 @@ Debug/main.cpp.o: main.cpp ../ServerCore/includes ../ServerCore/EPoll.h \ ../ServerCore/Command.h: -../ServerCore/ConsoleServer.h: - -../ServerCore/TCPServerSocket.h: +../ServerCore/ConsoleService.h: ../ServerCore/Service.h: ../ServerCore/CommandList.h: +../ServerCore/ConsoleSession.h: + +../ServerCore/TerminalSession.h: + +../ServerCore/TCPServerSocket.h: + ../ServerCore/IPAddressList.h: -../ServerCore/EPoll.h: +../CoreUtils/Exception.h: -../ServerCore/Exception.h: - -../ServerCore/File.h: - -../ServerCore/Log.h: +../CoreUtils/File.h: ../ServerCore/IPAddress.h: @@ -76,8 +83,6 @@ HTTPRequest.h: ../CoreUtils/PString.h: -../CoreUtils/includes: - ../CoreUtils/IMFMessage.h: ../CoreUtils/PString.h: @@ -94,10 +99,12 @@ HTTPRequest.h: ../CoreUtils/IMFMessage.h: -HTTPPageList.h: +../ServerCore/Command.h: ../ServerCore/Session.h: +HTTPPageList.h: + __index.h: HTTPPage.h: @@ -133,5 +140,3 @@ __viewlist.h: ../CoreUtils/DirectoryEntry.h: HTTPHandler.h: - -../ServerCore/Command.h: diff --git a/HTTPHandler.cpp b/HTTPHandler.cpp index 2e9cfc7..33415e7 100644 --- a/HTTPHandler.cpp +++ b/HTTPHandler.cpp @@ -10,19 +10,18 @@ namespace http { int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) { - core::Log(core::LOG_DEBUG_1) << request; - coreutils::PString request1(request); HTTPRequest httpRequest(request1); HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(httpRequest); std::stringstream content; + if(((HTTPService &)session->service).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(); - 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"); diff --git a/HTTPPageCache.h b/HTTPPageCache.h new file mode 100644 index 0000000..d31a922 --- /dev/null +++ b/HTTPPageCache.h @@ -0,0 +1,17 @@ +#ifndef __HTTPPageCache_h__ +#define __HTTPPageCache_h__ + +namespace http { + + class HTTPPageCache { + + public: + std::string + + + + }; + +} + +#endif diff --git a/HTTPServer.mk b/HTTPServer.mk index 69562ee..51715dc 100644 --- a/HTTPServer.mk +++ b/HTTPServer.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Brad Arant -Date :=16/08/19 +Date :=12/09/19 CodeLitePath :=/home/bradarant/.codelite LinkerName :=/usr/bin/x86_64-linux-gnu-g++ SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC diff --git a/HTTPServer.project b/HTTPServer.project index ca56cff..32454eb 100644 --- a/HTTPServer.project +++ b/HTTPServer.project @@ -26,6 +26,7 @@ + diff --git a/HTTPService.h b/HTTPService.h index 375ba21..4627821 100644 --- a/HTTPService.h +++ b/HTTPService.h @@ -19,7 +19,7 @@ namespace http { HTTPSessions httpSessions; HTTPPageList pageList; - + private: HTTPHandler getHandler; HTTPHandler postHandler; diff --git a/HTTPSessions.cpp b/HTTPSessions.cpp index 0b37319..99746b7 100644 --- a/HTTPSessions.cpp +++ b/HTTPSessions.cpp @@ -21,7 +21,7 @@ namespace http { httpSession = createHTTPSession(); 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 { httpSession = createHTTPSession(); @@ -44,4 +44,16 @@ namespace http { 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; + } + } diff --git a/HTTPSessions.h b/HTTPSessions.h index 3e904a2..c7a49e8 100644 --- a/HTTPSessions.h +++ b/HTTPSessions.h @@ -2,16 +2,20 @@ #define __HTTPSessions_h__ #include "HTTPRequest.h" +#include "Command.h" +#include "Session.h" namespace http { class HTTPSession; - class HTTPSessions { + class HTTPSessions : public core::Command { public: HTTPSession * findSessionByHeader(HTTPRequest &httpRequest); HTTPSession * findSessionById(std::string sessionId, HTTPRequest &httpRequest); + + int processCommand(std::string request, core::Session *session, std::stringstream &data); private: HTTPSession * createHTTPSession(); diff --git a/__editview.h b/__editview.h index 4101331..b59530b 100644 --- a/__editview.h +++ b/__editview.h @@ -9,7 +9,7 @@ namespace http { int processCommand(std::string request, core::Session *session, HTTPSession *httpSession, HTTPRequest &httpRequest, std::stringstream &data) override { - data << "
" << std::endl; + data << "
" << std::endl; data << "" << std::endl; data << "
" << std::endl; data << "" << std::endl; diff --git a/main.cpp b/main.cpp index 7887e26..cb9769a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,6 @@ #include "includes" #include "EPoll.h" -#include "ConsoleServer.h" +#include "ConsoleService.h" #include "Exception.h" #include "File.h" #include "Log.h" @@ -11,8 +11,8 @@ 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__; + coreutils::Log(new coreutils::File("/tmp/http.log", O_WRONLY | O_APPEND | O_CREAT, 0644)); + coreutils::Log(coreutils::LOG_INFO) << "HTTP Server starting. Build " << __DATE__ << " " << __TIME__; std::string ipAddress = "0.0.0.0"; @@ -21,12 +21,14 @@ int main(int argc, char **argv) { http::HTTPService httpService; core::TCPServerSocket http(ePoll, httpService, core::IPAddress(ipAddress, 8080)); - core::Service consoleService; - core::ConsoleServer console(ePoll, consoleService, core::IPAddress(ipAddress, 1027)); - consoleService.commands.add(ePoll); - consoleService.commands.add(http); - consoleService.commands.add(console); - ePoll.start(4, 1000); + core::ConsoleService consoleService; + core::TCPServerSocket console(ePoll, consoleService, 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); while(true) 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; sleep(10); }