From 608f8a2b0c857d704bf129de5b46fe18953ef67e Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Sat, 14 Aug 2021 15:03:43 -0700 Subject: [PATCH] Update changes. --- CommandList.cpp | 24 +-- ConsoleServer.cpp | 2 +- Socket.cpp | 2 +- TCPServer.cpp | 83 +++++----- TCPSession.cpp | 76 +++++----- TCPSession.h | 12 +- html/CommandList_8h_source.html | 72 ++++----- html/Command_8h_source.html | 53 ++++--- html/ConsoleServer_8h_source.html | 18 +-- html/ConsoleSession_8h_source.html | 48 +++--- html/EPoll_8h_source.html | 28 ++-- html/INotify_8h_source.html | 2 +- html/Socket_8h_source.html | 37 +++-- html/TCPServer_8h_source.html | 64 ++++---- html/TCPSession_8h_source.html | 40 ++--- html/TCPSocket_8h_source.html | 2 +- html/TLSSession_8h_source.html | 10 +- html/TerminalSession_8h_source.html | 6 +- html/classcore_1_1Command-members.html | 7 +- html/classcore_1_1Command.html | 82 ++++------ html/classcore_1_1CommandList-members.html | 22 +-- html/classcore_1_1CommandList.html | 128 ++++++++++------ .../classcore_1_1CommandList__coll__graph.map | 5 +- .../classcore_1_1CommandList__coll__graph.md5 | 2 +- .../classcore_1_1CommandList__coll__graph.png | Bin 6202 -> 4228 bytes ...asscore_1_1CommandList__inherit__graph.map | 5 +- ...asscore_1_1CommandList__inherit__graph.md5 | 2 +- ...asscore_1_1CommandList__inherit__graph.png | Bin 6202 -> 4228 bytes html/classcore_1_1Command__inherit__graph.map | 15 +- html/classcore_1_1Command__inherit__graph.md5 | 2 +- html/classcore_1_1Command__inherit__graph.png | Bin 16220 -> 15794 bytes html/classcore_1_1ConsoleServer-members.html | 38 +++-- html/classcore_1_1ConsoleServer.html | 87 +++++------ ...lasscore_1_1ConsoleServer__coll__graph.map | 22 +-- ...lasscore_1_1ConsoleServer__coll__graph.md5 | 2 +- ...lasscore_1_1ConsoleServer__coll__graph.png | Bin 50318 -> 38947 bytes ...score_1_1ConsoleServer__inherit__graph.map | 13 +- ...score_1_1ConsoleServer__inherit__graph.md5 | 2 +- ...score_1_1ConsoleServer__inherit__graph.png | Bin 16741 -> 12037 bytes html/classcore_1_1ConsoleSession-members.html | 64 ++++---- html/classcore_1_1ConsoleSession.html | 76 +++++----- ...asscore_1_1ConsoleSession__coll__graph.map | 24 +-- ...asscore_1_1ConsoleSession__coll__graph.md5 | 2 +- ...asscore_1_1ConsoleSession__coll__graph.png | Bin 57998 -> 45662 bytes ...core_1_1ConsoleSession__inherit__graph.map | 11 +- ...core_1_1ConsoleSession__inherit__graph.md5 | 2 +- ...core_1_1ConsoleSession__inherit__graph.png | Bin 12628 -> 10583 bytes html/classcore_1_1EPoll-members.html | 11 +- html/classcore_1_1EPoll.html | 53 +++---- html/classcore_1_1EPoll__coll__graph.map | 5 +- html/classcore_1_1EPoll__coll__graph.md5 | 2 +- html/classcore_1_1EPoll__coll__graph.png | Bin 5211 -> 2926 bytes html/classcore_1_1EPoll__inherit__graph.map | 5 +- html/classcore_1_1EPoll__inherit__graph.md5 | 2 +- html/classcore_1_1EPoll__inherit__graph.png | Bin 5211 -> 2926 bytes html/classcore_1_1INotify-members.html | 2 +- html/classcore_1_1INotify.html | 20 ++- html/classcore_1_1INotify__coll__graph.map | 9 +- html/classcore_1_1INotify__coll__graph.md5 | 2 +- html/classcore_1_1INotify__coll__graph.png | Bin 12942 -> 7125 bytes html/classcore_1_1INotify__inherit__graph.map | 5 +- html/classcore_1_1INotify__inherit__graph.md5 | 2 +- html/classcore_1_1INotify__inherit__graph.png | Bin 5272 -> 3053 bytes html/classcore_1_1Object.html | 24 +-- html/classcore_1_1Object__inherit__graph.map | 24 +-- html/classcore_1_1Object__inherit__graph.md5 | 2 +- html/classcore_1_1Object__inherit__graph.png | Bin 51308 -> 7270 bytes html/classcore_1_1Socket-members.html | 32 ++-- html/classcore_1_1Socket.html | 62 ++++---- html/classcore_1_1Socket__coll__graph.map | 7 +- html/classcore_1_1Socket__coll__graph.md5 | 2 +- html/classcore_1_1Socket__coll__graph.png | Bin 10935 -> 5377 bytes html/classcore_1_1Socket__inherit__graph.map | 27 ++-- html/classcore_1_1Socket__inherit__graph.md5 | 2 +- html/classcore_1_1Socket__inherit__graph.png | Bin 26974 -> 23089 bytes html/classcore_1_1TCPServer-members.html | 38 +++-- html/classcore_1_1TCPServer.html | 143 ++++++++---------- html/classcore_1_1TCPServer__coll__graph.map | 18 +-- html/classcore_1_1TCPServer__coll__graph.md5 | 2 +- html/classcore_1_1TCPServer__coll__graph.png | Bin 44155 -> 32743 bytes ...classcore_1_1TCPServer__inherit__graph.map | 13 +- ...classcore_1_1TCPServer__inherit__graph.md5 | 2 +- ...classcore_1_1TCPServer__inherit__graph.png | Bin 16348 -> 11707 bytes html/classcore_1_1TCPSession-members.html | 46 +++--- html/classcore_1_1TCPSession.html | 90 +++++------ html/classcore_1_1TCPSession__coll__graph.map | 20 +-- html/classcore_1_1TCPSession__coll__graph.md5 | 2 +- html/classcore_1_1TCPSession__coll__graph.png | Bin 52824 -> 40563 bytes ...lasscore_1_1TCPSession__inherit__graph.map | 13 +- ...lasscore_1_1TCPSession__inherit__graph.md5 | 2 +- ...lasscore_1_1TCPSession__inherit__graph.png | Bin 15334 -> 11925 bytes html/classcore_1_1TCPSocket-members.html | 32 ++-- html/classcore_1_1TCPSocket.html | 50 +++--- html/classcore_1_1TCPSocket__coll__graph.map | 12 +- html/classcore_1_1TCPSocket__coll__graph.md5 | 2 +- html/classcore_1_1TCPSocket__coll__graph.png | Bin 18644 -> 12832 bytes ...classcore_1_1TCPSocket__inherit__graph.map | 19 ++- ...classcore_1_1TCPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1TCPSocket__inherit__graph.png | Bin 19946 -> 15754 bytes html/classcore_1_1TLSServer-members.html | 38 +++-- html/classcore_1_1TLSServer.html | 83 +++++----- html/classcore_1_1TLSServer__coll__graph.map | 20 +-- html/classcore_1_1TLSServer__coll__graph.md5 | 2 +- html/classcore_1_1TLSServer__coll__graph.png | Bin 46441 -> 35037 bytes ...classcore_1_1TLSServer__inherit__graph.map | 11 +- ...classcore_1_1TLSServer__inherit__graph.md5 | 2 +- ...classcore_1_1TLSServer__inherit__graph.png | Bin 14126 -> 9549 bytes html/classcore_1_1TLSSession-members.html | 46 +++--- html/classcore_1_1TLSSession.html | 78 +++++----- html/classcore_1_1TLSSession__coll__graph.map | 22 +-- html/classcore_1_1TLSSession__coll__graph.md5 | 2 +- html/classcore_1_1TLSSession__coll__graph.png | Bin 55218 -> 42907 bytes ...lasscore_1_1TLSSession__inherit__graph.map | 9 +- ...lasscore_1_1TLSSession__inherit__graph.md5 | 2 +- ...lasscore_1_1TLSSession__inherit__graph.png | Bin 7070 -> 5889 bytes .../classcore_1_1TerminalSession-members.html | 62 ++++---- html/classcore_1_1TerminalSession.html | 64 ++++---- ...sscore_1_1TerminalSession__coll__graph.map | 22 +-- ...sscore_1_1TerminalSession__coll__graph.md5 | 2 +- ...sscore_1_1TerminalSession__coll__graph.png | Bin 55539 -> 43224 bytes ...ore_1_1TerminalSession__inherit__graph.map | 11 +- ...ore_1_1TerminalSession__inherit__graph.md5 | 2 +- ...ore_1_1TerminalSession__inherit__graph.png | Bin 12634 -> 10590 bytes html/classcore_1_1Timer-members.html | 2 +- html/classcore_1_1Timer.html | 14 +- html/classcore_1_1Timer__coll__graph.map | 9 +- html/classcore_1_1Timer__coll__graph.md5 | 2 +- html/classcore_1_1Timer__coll__graph.png | Bin 12611 -> 6805 bytes html/classcore_1_1Timer__inherit__graph.map | 5 +- html/classcore_1_1Timer__inherit__graph.md5 | 2 +- html/classcore_1_1Timer__inherit__graph.png | Bin 4891 -> 2723 bytes .../classcore_1_1UDPServerSocket-members.html | 57 ++++--- html/classcore_1_1UDPServerSocket.html | 49 +++--- ...sscore_1_1UDPServerSocket__coll__graph.map | 11 +- ...sscore_1_1UDPServerSocket__coll__graph.md5 | 2 +- ...sscore_1_1UDPServerSocket__coll__graph.png | Bin 20027 -> 14992 bytes ...ore_1_1UDPServerSocket__inherit__graph.map | 9 +- ...ore_1_1UDPServerSocket__inherit__graph.md5 | 2 +- ...ore_1_1UDPServerSocket__inherit__graph.png | Bin 12365 -> 9068 bytes html/classcore_1_1UDPSocket-members.html | 32 ++-- html/classcore_1_1UDPSocket.html | 33 ++-- html/classcore_1_1UDPSocket__coll__graph.map | 9 +- html/classcore_1_1UDPSocket__coll__graph.md5 | 2 +- html/classcore_1_1UDPSocket__coll__graph.png | Bin 13472 -> 7546 bytes ...classcore_1_1UDPSocket__inherit__graph.map | 7 +- ...classcore_1_1UDPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1UDPSocket__inherit__graph.png | Bin 7564 -> 6423 bytes html/functions.html | 37 ++--- html/functions_func.html | 37 ++--- html/hierarchy.html | 52 +++---- html/inherit_graph_1.map | 25 +-- html/inherit_graph_1.md5 | 2 +- html/inherit_graph_1.png | Bin 56388 -> 7997 bytes html/inherit_graph_2.map | 19 +++ html/inherit_graph_2.md5 | 1 + html/inherit_graph_2.png | Bin 0 -> 33813 bytes html/inherits.html | 46 +++--- html/search/all_2.js | 2 +- html/search/all_4.js | 2 +- html/search/all_7.js | 8 +- html/search/all_8.js | 6 +- html/search/all_9.js | 2 +- html/search/all_a.js | 2 +- html/search/all_b.js | 2 +- html/search/functions_1.js | 2 +- html/search/functions_3.js | 2 +- html/search/functions_5.js | 8 +- html/search/functions_6.js | 6 +- html/search/functions_7.js | 2 +- html/search/functions_8.js | 2 +- html/search/functions_9.js | 2 +- latex/classcore_1_1Command.tex | 36 ++--- latex/classcore_1_1CommandList.tex | 50 ++++-- .../classcore_1_1CommandList__coll__graph.md5 | 2 +- .../classcore_1_1CommandList__coll__graph.pdf | Bin 7415 -> 6704 bytes ...asscore_1_1CommandList__inherit__graph.md5 | 2 +- ...asscore_1_1CommandList__inherit__graph.pdf | Bin 7415 -> 6704 bytes .../classcore_1_1Command__inherit__graph.md5 | 2 +- .../classcore_1_1Command__inherit__graph.pdf | Bin 10788 -> 10036 bytes ...lasscore_1_1ConsoleServer__coll__graph.md5 | 2 +- ...lasscore_1_1ConsoleServer__coll__graph.pdf | Bin 13146 -> 12968 bytes ...score_1_1ConsoleServer__inherit__graph.md5 | 2 +- ...score_1_1ConsoleServer__inherit__graph.pdf | Bin 10064 -> 9236 bytes latex/classcore_1_1ConsoleSession.tex | 10 +- ...asscore_1_1ConsoleSession__coll__graph.md5 | 2 +- ...asscore_1_1ConsoleSession__coll__graph.pdf | Bin 13960 -> 13737 bytes ...core_1_1ConsoleSession__inherit__graph.md5 | 2 +- ...core_1_1ConsoleSession__inherit__graph.pdf | Bin 9046 -> 8320 bytes latex/classcore_1_1EPoll.tex | 10 +- latex/classcore_1_1EPoll__coll__graph.md5 | 2 +- latex/classcore_1_1EPoll__coll__graph.pdf | Bin 7233 -> 6390 bytes latex/classcore_1_1EPoll__inherit__graph.md5 | 2 +- latex/classcore_1_1EPoll__inherit__graph.pdf | Bin 7233 -> 6390 bytes latex/classcore_1_1INotify.tex | 6 +- latex/classcore_1_1INotify__coll__graph.md5 | 2 +- latex/classcore_1_1INotify__coll__graph.pdf | Bin 9525 -> 8625 bytes .../classcore_1_1INotify__inherit__graph.md5 | 2 +- .../classcore_1_1INotify__inherit__graph.pdf | Bin 7507 -> 6755 bytes latex/classcore_1_1Object__inherit__graph.md5 | 2 +- latex/classcore_1_1Object__inherit__graph.pdf | Bin 17063 -> 8382 bytes latex/classcore_1_1Socket.tex | 17 +-- latex/classcore_1_1Socket__coll__graph.md5 | 2 +- latex/classcore_1_1Socket__coll__graph.pdf | Bin 8268 -> 7380 bytes latex/classcore_1_1Socket__inherit__graph.md5 | 2 +- latex/classcore_1_1Socket__inherit__graph.pdf | Bin 13728 -> 12960 bytes latex/classcore_1_1TCPServer.tex | 39 ++--- latex/classcore_1_1TCPServer__coll__graph.md5 | 2 +- latex/classcore_1_1TCPServer__coll__graph.pdf | Bin 12384 -> 12191 bytes ...classcore_1_1TCPServer__inherit__graph.md5 | 2 +- ...classcore_1_1TCPServer__inherit__graph.pdf | Bin 10033 -> 9185 bytes latex/classcore_1_1TCPSession.tex | 30 ++-- .../classcore_1_1TCPSession__coll__graph.md5 | 2 +- .../classcore_1_1TCPSession__coll__graph.pdf | Bin 13154 -> 12940 bytes ...lasscore_1_1TCPSession__inherit__graph.md5 | 2 +- ...lasscore_1_1TCPSession__inherit__graph.pdf | Bin 9592 -> 8856 bytes latex/classcore_1_1TCPSocket.tex | 4 +- latex/classcore_1_1TCPSocket__coll__graph.md5 | 2 +- latex/classcore_1_1TCPSocket__coll__graph.pdf | Bin 10153 -> 9749 bytes ...classcore_1_1TCPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1TCPSocket__inherit__graph.pdf | Bin 11040 -> 10292 bytes latex/classcore_1_1TLSServer__coll__graph.md5 | 2 +- latex/classcore_1_1TLSServer__coll__graph.pdf | Bin 12787 -> 12597 bytes ...classcore_1_1TLSServer__inherit__graph.md5 | 2 +- ...classcore_1_1TLSServer__inherit__graph.pdf | Bin 9305 -> 8465 bytes latex/classcore_1_1TLSSession.tex | 16 +- .../classcore_1_1TLSSession__coll__graph.md5 | 2 +- .../classcore_1_1TLSSession__coll__graph.pdf | Bin 13550 -> 13334 bytes ...lasscore_1_1TLSSession__inherit__graph.md5 | 2 +- ...lasscore_1_1TLSSession__inherit__graph.pdf | Bin 8244 -> 7512 bytes ...sscore_1_1TerminalSession__coll__graph.md5 | 2 +- ...sscore_1_1TerminalSession__coll__graph.pdf | Bin 13572 -> 13354 bytes ...ore_1_1TerminalSession__inherit__graph.md5 | 2 +- ...ore_1_1TerminalSession__inherit__graph.pdf | Bin 9053 -> 8334 bytes latex/classcore_1_1Timer.tex | 2 +- latex/classcore_1_1Timer__coll__graph.md5 | 2 +- latex/classcore_1_1Timer__coll__graph.pdf | Bin 8847 -> 7945 bytes latex/classcore_1_1Timer__inherit__graph.md5 | 2 +- latex/classcore_1_1Timer__inherit__graph.pdf | Bin 6996 -> 6234 bytes latex/classcore_1_1UDPServerSocket.tex | 2 +- ...sscore_1_1UDPServerSocket__coll__graph.md5 | 2 +- ...sscore_1_1UDPServerSocket__coll__graph.pdf | Bin 9695 -> 8863 bytes ...ore_1_1UDPServerSocket__inherit__graph.md5 | 2 +- ...ore_1_1UDPServerSocket__inherit__graph.pdf | Bin 8969 -> 8125 bytes latex/classcore_1_1UDPSocket.tex | 2 +- latex/classcore_1_1UDPSocket__coll__graph.md5 | 2 +- latex/classcore_1_1UDPSocket__coll__graph.pdf | Bin 8900 -> 8021 bytes ...classcore_1_1UDPSocket__inherit__graph.md5 | 2 +- ...classcore_1_1UDPSocket__inherit__graph.pdf | Bin 7633 -> 6880 bytes latex/hierarchy.tex | 16 +- 249 files changed, 1562 insertions(+), 1734 deletions(-) create mode 100644 html/inherit_graph_2.map create mode 100644 html/inherit_graph_2.md5 create mode 100644 html/inherit_graph_2.png diff --git a/CommandList.cpp b/CommandList.cpp index 750cf84..2ac92cc 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -4,41 +4,41 @@ namespace core { CommandList::CommandList(std::string delimiter) : delimiter(delimiter) {} - + void CommandList::add(Command &command, std::string name) { command.setName(name); commands.push_back(&command); } - + void CommandList::remove(Command &command) {} - + bool CommandList::processRequest(coreutils::ZString &request, TCPSession &session) { if(session.grab != NULL) - return session.grab->processCommand(request, session); + return session.grab->processCommand(request, session); else { request.split(delimiter); - for(auto *command : commands) - if(command->check(request)) - return command->processCommand(request, session); + for(auto *command : commands) + if(command->check(request)) + return command->processCommand(request, session); } return false; } - + bool CommandList::grabInput(TCPSession &session, Command &command) { session.grab = &command; return true; } - + void CommandList::clearGrab(TCPSession &session) { session.grab = NULL; } - + int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) { for(Command *command : commands) - session.out << command->getName() << std::endl; + session.out << command->getName() << std::endl; return true; } - + } diff --git a/ConsoleServer.cpp b/ConsoleServer.cpp index 16cdc4f..93a13dc 100644 --- a/ConsoleServer.cpp +++ b/ConsoleServer.cpp @@ -5,7 +5,7 @@ namespace core { - ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address, " ", "Console") { + ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address, " ", "Console Server") { coreutils::Log(this); } diff --git a/Socket.cpp b/Socket.cpp index 5dbd0b1..5173b7c 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -7,7 +7,7 @@ namespace core { Socket::Socket(EPoll &ePoll, std::string text) : ePoll(ePoll), text(text) { - coreutils::Log(coreutils::LOG_DEBUG_2) << "BMASocket object created [" << text << "]."; + coreutils::Log(coreutils::LOG_DEBUG_2) << "Socket object created [" << text << "]."; buffer = (char *)malloc(4096); length = 4096; } diff --git a/TCPServer.cpp b/TCPServer.cpp index cc89dd6..eeeb269 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -5,49 +5,48 @@ #include "Log.h" namespace core { - + TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, std::string text) : TCPSocket(ePoll, text), commands(delimiter) { - - setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); - int yes = 1; - setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) - throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); - if(listen(getDescriptor(), 20) < 0) - throw coreutils::Exception("Error on listen to socket"); - } - + + setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); + int yes = 1; + setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) + throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); + if(listen(getDescriptor(), 20) < 0) + throw coreutils::Exception("Error on listen to socket"); + } + TCPServer::~TCPServer() { coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << "."; close(getDescriptor()); } - + void TCPServer::onDataReceived(std::string data) { lock.lock(); TCPSession *session = accept(); if(session) - sessions.push_back(session); + sessions.push_back(session); lock.unlock(); } - + TCPSession * TCPServer::accept() { - + try { - + TCPSession *session = getSocketAccept(ePoll); session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength)); - // if(blackList && blackList->contains(session->ipAddress.getClientAddress())) { - // session->shutdown(); - // Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection."; - // return NULL; - // } - // if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) { - // session->shutdown(); - // Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection."; - // return NULL; - // } - coreutils::Log(coreutils::LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << "."; + // if(blackList && blackList->contains(session->ipAddress.getClientAddress())) { + // session->shutdown(); + // Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection."; + // return NULL; + // } + // if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) { + // session->shutdown(); + // Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection."; + // return NULL; + // } return session; } catch(coreutils::Exception e) { @@ -58,26 +57,26 @@ namespace core { } return NULL; } - + void TCPServer::removeFromSessionList(TCPSession *session) { std::vector::iterator cursor; for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor) if(*cursor == session) sessions.erase(cursor); } - + void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) { throw coreutils::Exception(errorString); } - + TCPSession * TCPServer::getSocketAccept(EPoll &ePoll) { return new TCPSession(ePoll, *this); } - + void TCPServer::output(std::stringstream &out) { out << "Use the 'help' command to list the commands for this server." << std::endl; } - + int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) { int sequence = 0; for(auto *sessionx : sessions) { @@ -87,26 +86,26 @@ namespace core { } return 1; } - + void TCPServer::sendToAll(std::stringstream &data) { for(auto session : sessions) - session->write(data.str()); + session->write(data.str()); data.str(""); } - + void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender) { for(auto session : sessions) - if(session != &sender) - session->write(data.str()); + if(session != &sender) + session->write(data.str()); data.str(""); } - + void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) { for(auto session : sessions) - if(filter.test(*session)) - if(session != &sender) - session->write(data.str()); + if(filter.test(*session)) + if(session != &sender) + session->write(data.str()); data.str(""); } - + } diff --git a/TCPSession.cpp b/TCPSession.cpp index 99e7c8d..be1be3c 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -1,5 +1,6 @@ #include "TCPSession.h" #include "TCPServer.h" +#include "Exception.h" #include "Log.h" namespace core { @@ -16,78 +17,77 @@ namespace core { void TCPSession::protocol(coreutils::ZString &data) { if(!server.commands.processRequest(data, *this)) - if(data.getLength() != 0) - server.sessionErrorHandler("Invalid data received.", out); + throw coreutils::Exception("Data received is not valid."); } - + void TCPSession::onRegistered() { onConnected(); coreutils::ZString blank(""); protocol(blank); send(); if(term) - shutdown("termination requested"); + shutdown("termination requested"); } - + void TCPSession::onConnected() {} - + void TCPSession::onDataReceived(coreutils::ZString &data) { if(data.getLength() > 0) { - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); - memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); - lineBufferSize += data.getLength(); - while(lineBufferSize > 0) { - if(blockSize == 0) { - lineLength = strcspn(lineBuffer, "\r\n"); - if(lineLength == lineBufferSize) - break; + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); + memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); + lineBufferSize += data.getLength(); + while(lineBufferSize > 0) { + if(blockSize == 0) { + lineLength = strcspn(lineBuffer, "\r\n"); + if(lineLength == lineBufferSize) + break; coreutils::ZString zLine(lineBuffer, lineLength); - onLineReceived(zLine); - if(lineBuffer[lineLength] == '\r') - ++lineLength; - if(lineBuffer[lineLength] == '\n') - ++lineLength; - lineBufferSize -= lineLength; - if(lineBufferSize > 0) - memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize); - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + onLineReceived(zLine); + if(lineBuffer[lineLength] == '\r') + ++lineLength; + if(lineBuffer[lineLength] == '\n') + ++lineLength; + lineBufferSize -= lineLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); } else if(lineBufferSize >= blockLength) { coreutils::ZString zBlock(lineBuffer, blockLength); - onBlockReceived(zBlock); - lineBufferSize -= blockLength; - if(lineBufferSize > 0) - memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); - } - } - } + onBlockReceived(zBlock); + lineBufferSize -= blockLength; + if(lineBufferSize > 0) + memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); + lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); + } + } + } } - + void TCPSession::setBlockSize(int blockSize) { this->blockSize = blockSize; } - + void TCPSession::onLineReceived(coreutils::ZString &line) { protocol(line); send(); if(term) shutdown("termination requested"); } - + void TCPSession::onBlockReceived(coreutils::ZString &block) { coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]"; if(term) shutdown("termination requested"); } - + void TCPSession::send() { if(out.tellp() > 0) - write(out.str()); + write(out.str()); out.str(""); } - + void TCPSession::terminate() { term = true; } - + } diff --git a/TCPSession.h b/TCPSession.h index aee1db8..e0a9edf 100644 --- a/TCPSession.h +++ b/TCPSession.h @@ -41,12 +41,6 @@ namespace core { virtual void output(std::stringstream &data); - /// - /// Use out to send data to the session socket or other session sockets. - /// - - std::stringstream out; - /// /// The send method is used to output the contents of the out stream /// to the session containing the stream. @@ -66,6 +60,12 @@ namespace core { TCPServer &server; + /// + /// Use out to send data to the session socket or other session sockets. + /// + + std::stringstream out; + protected: /// diff --git a/html/CommandList_8h_source.html b/html/CommandList_8h_source.html index a07a5b2..cbc3b9b 100644 --- a/html/CommandList_8h_source.html +++ b/html/CommandList_8h_source.html @@ -74,48 +74,52 @@ $(function() {
7 
8 namespace core {
9 
-
17 
+
17 
18  class CommandList : public Command {
-
19 
+
19 
20  public:
-
21 
-
25 
-
26  void add(Command &command, std::string name = "");
-
27 
-
31 
-
32  void remove(Command &command);
-
33 
-
40 
-
41  bool processRequest(coreutils::ZString request, TCPSession *session, std::stringstream &data);
+
21 
+
22  CommandList(std::string delimiter = "");
+
23 
+
27 
+
28  void add(Command &command, std::string name = "");
+
29 
+
33 
+
34  void remove(Command &command);
+
35 
42 
-
48 
-
49  bool grabInput(TCPSession *session, Command &command);
+
43  bool processRequest(coreutils::ZString &request, TCPSession &session);
+
44 
50 
-
54 
-
55  void clearGrab(TCPSession *session);
-
56 
-
60 
-
61  int processCommand(std::string request, TCPSession *session, std::stringstream &data);
-
62 
-
63  protected:
-
64 
-
68 
-
69  std::vector<Command *> commands;
-
70 
-
71  };
-
72 
-
73 }
-
74 
-
75 #endif
+
51  bool grabInput(TCPSession &session, Command &command);
+
52 
+
56 
+
57  void clearGrab(TCPSession &session);
+
58 
+
62 
+
63  int processCommand(coreutils::ZString &request, TCPSession &session);
+
64 
+
65  protected:
+
66 
+
70 
+
71  std::vector<Command *> commands;
+
72  std::string delimiter;
+
73 
+
74  };
+
75 
+
76 }
+
77 
+
78 #endif
-
bool grabInput(TCPSession *session, Command &command)
Definition: CommandList.cpp:27
-
bool processRequest(coreutils::ZString request, TCPSession *session, std::stringstream &data)
Definition: CommandList.cpp:15
Definition: TCPSession.h:24
-
std::vector< Command * > commands
Definition: CommandList.h:69
-
void add(Command &command, std::string name="")
Definition: CommandList.cpp:6
-
void remove(Command &command)
Definition: CommandList.cpp:11
+
std::vector< Command * > commands
Definition: CommandList.h:71
+
void add(Command &command, std::string name="")
Definition: CommandList.cpp:8
+
bool processRequest(coreutils::ZString &request, TCPSession &session)
Definition: CommandList.cpp:15
+
bool grabInput(TCPSession &session, Command &command)
Definition: CommandList.cpp:27
+
void remove(Command &command)
Definition: CommandList.cpp:13
Definition: Command.h:22
Definition: CommandList.h:18
+
int processCommand(coreutils::ZString &request, TCPSession &session)
Definition: CommandList.cpp:36