From d445834af683ca831823709179cbecd6ca77dd46 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Fri, 23 Jul 2021 08:57:27 -0700 Subject: [PATCH] Many changes to ServerCore --- .vscode/c_cpp_properties.json | 11 +- Command.cpp | 13 +- Command.h | 6 +- CommandList.cpp | 13 +- CommandList.h | 2 +- ConsoleSession.cpp | 19 +- ConsoleSession.h | 6 +- EPoll.cpp | 2 +- EPoll.h | 2 +- INotify.cpp | 4 +- INotify.h | 2 +- Socket.cpp | 38 ++- Socket.h | 9 +- TCPServer.cpp | 28 ++- TCPServer.h | 56 +++-- TCPSession.cpp | 96 ++++---- TCPSession.h | 24 +- TCPSocket.cpp | 18 +- TLSSession.cpp | 8 +- TLSSession.h | 4 +- html/CommandList_8h_source.html | 9 +- html/Command_8h_source.html | 12 +- html/ConsoleSession_8h_source.html | 8 +- html/EPoll_8h_source.html | 6 +- html/INotify_8h_source.html | 4 +- html/Socket_8h_source.html | 222 +++++++++--------- html/TCPServer_8h_source.html | 4 +- html/TCPSession_8h_source.html | 30 +-- html/TCPSocket_8h_source.html | 2 +- html/TLSSession_8h_source.html | 8 +- html/Timer_8h_source.html | 2 +- html/UDPSocket_8h_source.html | 2 +- html/classcore_1_1Command-members.html | 4 +- html/classcore_1_1Command.html | 24 +- html/classcore_1_1CommandList-members.html | 13 +- html/classcore_1_1CommandList.html | 74 +----- html/classcore_1_1ConsoleServer-members.html | 8 +- html/classcore_1_1ConsoleServer.html | 18 +- html/classcore_1_1ConsoleSession-members.html | 10 +- html/classcore_1_1ConsoleSession.html | 32 +-- html/classcore_1_1EPoll-members.html | 4 +- html/classcore_1_1EPoll.html | 20 +- html/classcore_1_1INotify-members.html | 2 +- html/classcore_1_1INotify.html | 6 +- html/classcore_1_1Socket-members.html | 4 +- html/classcore_1_1Socket.html | 30 +-- html/classcore_1_1TCPServer-members.html | 8 +- html/classcore_1_1TCPServer.html | 26 +- html/classcore_1_1TCPSession-members.html | 10 +- html/classcore_1_1TCPSession.html | 60 ++--- html/classcore_1_1TCPSocket-members.html | 4 +- html/classcore_1_1TCPSocket.html | 10 +- html/classcore_1_1TLSServer-members.html | 8 +- html/classcore_1_1TLSServer.html | 18 +- html/classcore_1_1TLSSession-members.html | 10 +- html/classcore_1_1TLSSession.html | 48 ++-- .../classcore_1_1TerminalSession-members.html | 10 +- html/classcore_1_1TerminalSession.html | 20 +- html/classcore_1_1Timer-members.html | 2 +- .../classcore_1_1UDPServerSocket-members.html | 8 +- html/classcore_1_1UDPServerSocket.html | 18 +- html/classcore_1_1UDPSocket-members.html | 4 +- html/classcore_1_1UDPSocket.html | 10 +- html/functions.html | 27 +-- html/functions_func.html | 27 +-- html/search/all_2.js | 2 +- html/search/all_7.js | 6 +- html/search/all_8.js | 6 +- html/search/all_9.js | 2 +- html/search/functions_1.js | 2 +- html/search/functions_5.js | 6 +- html/search/functions_6.js | 6 +- html/search/functions_7.js | 2 +- latex/classcore_1_1Command.tex | 16 +- latex/classcore_1_1CommandList.tex | 33 +-- latex/classcore_1_1ConsoleSession.tex | 10 +- latex/classcore_1_1EPoll.tex | 10 +- latex/classcore_1_1INotify.tex | 4 +- latex/classcore_1_1Socket.tex | 12 +- latex/classcore_1_1TCPServer.tex | 8 +- latex/classcore_1_1TCPSession.tex | 26 +- latex/classcore_1_1TLSSession.tex | 16 +- servercore.code-workspace | 8 + 83 files changed, 666 insertions(+), 756 deletions(-) create mode 100644 servercore.code-workspace diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a426fd3..be23ad4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,13 +3,14 @@ { "name": "Linux", "includePath": [ - "${workspaceFolder}/**" + "${workspaceFolder}/**", + "${workspaceFolder}/../CoreUtils" ], "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/g++-9", + "cStandard": "c17", + "cppStandard": "gnu++20", + "intelliSenseMode": "windows-gcc-x64", "compileCommands": "./compile" }, { diff --git a/Command.cpp b/Command.cpp index e5fe0bf..5a349e7 100644 --- a/Command.cpp +++ b/Command.cpp @@ -4,17 +4,18 @@ namespace core { - int Command::processCommand(std::string request, TCPSession *session, std::stringstream &data) { + int Command::processCommand(coreutils::ZString request, TCPSession *session, std::stringstream &data) { return 0; } void Command::output(Session *session) {} - bool Command::check(std::string request) { - if(request.size() > 0) - if(request == name) - if(name.length() > 0) - return true; + bool Command::check(coreutils::ZString request) { + if(request.getLength() > 0) + if(request.getLength() == name.length()) + if(strncmp(request.getData(), name.c_str(), name.length()) == 0) + if(name.length() > 0) + return true; return false; } diff --git a/Command.h b/Command.h index e3c999a..3680c1f 100644 --- a/Command.h +++ b/Command.h @@ -4,7 +4,7 @@ #include "includes" #include "Object.h" #include "TCPSession.h" -#include "PString.h" +#include "ZString.h" namespace core { @@ -37,7 +37,7 @@ namespace core { /// on this command. /// - virtual bool check(std::string request); + virtual bool check(coreutils::ZString request); /// /// This method is used to implement the functionality of the requested command. @@ -50,7 +50,7 @@ namespace core { /// a non-zero value indicating an error condition. /// - virtual int processCommand(std::string request, TCPSession *session, std::stringstream &data); + virtual int processCommand(coreutils::ZString request, TCPSession *session, std::stringstream &data); /// /// Specify the output that will occur to the specified session. diff --git a/CommandList.cpp b/CommandList.cpp index 1474518..1a40c5f 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -12,15 +12,14 @@ namespace core { } - bool CommandList::processRequest(std::string request, TCPSession *session, std::stringstream &data) { + bool CommandList::processRequest(coreutils::ZString request, TCPSession *session, std::stringstream &data) { if(session->grab != NULL) - return session->grab->processCommand(request, session, data); + return session->grab->processCommand(request, session, data); else { - int pos = request.find(" "); - std::string function = pos == request.npos ? request: request.substr(0, pos); - for(auto *command : commands) - if(command->check(function)) - return command->processCommand(request, session, data); + coreutils::ZString function = request.getTokenExclude((char *)" "); + for(auto *command : commands) + if(command->check(function)) + return command->processCommand(request, session, data); } return false; } diff --git a/CommandList.h b/CommandList.h index 522911b..d57a09f 100644 --- a/CommandList.h +++ b/CommandList.h @@ -38,7 +38,7 @@ namespace core { /// then control is given to the process handler holding the grab on the input. /// - bool processRequest(std::string request, TCPSession *session, std::stringstream &data); + bool processRequest(coreutils::ZString request, TCPSession *session, std::stringstream &data); /// /// Use grabInput() within a Command object to force the requesting handler to receive diff --git a/ConsoleSession.cpp b/ConsoleSession.cpp index 4a9b869..1ec787e 100644 --- a/ConsoleSession.cpp +++ b/ConsoleSession.cpp @@ -9,7 +9,7 @@ namespace core { ConsoleSession::~ConsoleSession() {} - void ConsoleSession::protocol(std::string data = "") { + void ConsoleSession::protocol(coreutils::ZString data) { coreutils::Log(coreutils::LOG_DEBUG_1) << "ConsoleSession protocol " << status; switch (status) { @@ -24,7 +24,7 @@ namespace core { setCursorLocation(2, 1); setBackColor(BG_BLACK); status = LOGIN; - protocol(); + protocol((char*)""); break; case LOGIN: @@ -35,7 +35,7 @@ namespace core { case WAIT_USER_PROFILE: status = PASSWORD; - protocol(); + protocol((char*)""); break; case PASSWORD: @@ -55,7 +55,7 @@ namespace core { setBackColor(BG_BLACK); scrollArea(2, 16); status = PROMPT; - protocol(); + protocol((char*)""); break; case PROMPT: @@ -66,16 +66,15 @@ namespace core { break; case INPUT: - command = std::string(data); - command.erase(command.find_last_not_of("\r\n\t") + 1); + command = data; status = PROCESS; - protocol(); + protocol((char*)""); break; case PROCESS: doCommand(command); - status = (command == "exit")? DONE: PROMPT; - protocol(); + status = command.equals((char *)"exit") ? DONE: PROMPT; + protocol((char*)""); break; case DONE: @@ -95,7 +94,7 @@ namespace core { send(); } - void ConsoleSession::doCommand(std::string request) { + void ConsoleSession::doCommand(coreutils::ZString request) { saveCursor(); setCursorLocation(16, 1); out << "--> " << request << std::endl; diff --git a/ConsoleSession.h b/ConsoleSession.h index d0202b2..330c178 100644 --- a/ConsoleSession.h +++ b/ConsoleSession.h @@ -24,13 +24,13 @@ namespace core { void writeLog(std::string data); protected: - void protocol(std::string data) override; + void protocol(coreutils::ZString data) override; private: enum Status {WELCOME, LOGIN, WAIT_USER_PROFILE, PASSWORD, WAIT_PASSWORD, PROMPT, INPUT, PROCESS, DONE}; Status status = WELCOME; - void doCommand(std::string request); - std::string command; + void doCommand(coreutils::ZString request); + coreutils::ZString command; }; diff --git a/EPoll.cpp b/EPoll.cpp index 2ec4d47..e170b8f 100644 --- a/EPoll.cpp +++ b/EPoll.cpp @@ -84,7 +84,7 @@ namespace core { return epfd; } - int EPoll::processCommand(std::string command, TCPSession *session, std::stringstream &data) { + int EPoll::processCommand(coreutils::ZString command, TCPSession *session, std::stringstream &data) { int sequence = 0; for(auto threadx : threads) { data << "|" << ++sequence; diff --git a/EPoll.h b/EPoll.h index ad4d7d7..82d8846 100644 --- a/EPoll.h +++ b/EPoll.h @@ -110,7 +110,7 @@ namespace core { /// @param session the session to write the requested data to. /// - int processCommand(std::string command, TCPSession *session, std::stringstream &data) override; ///len) { event = (const struct inotify_event *) ptr; diff --git a/INotify.h b/INotify.h index 2bc5091..a2e9650 100644 --- a/INotify.h +++ b/INotify.h @@ -15,7 +15,7 @@ namespace core { int addWatch(std::string watch); void removeWatch(int wd); - void onDataReceived(char *buffer, int len) override; + void onDataReceived(coreutils::ZString data) override; virtual void inAccess(std::string name) {} virtual void inAttrib(std::string name) {} diff --git a/Socket.cpp b/Socket.cpp index adcbe83..ee2cc36 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -59,43 +59,33 @@ namespace core { void Socket::onUnregistered() {} bool Socket::eventReceived(struct epoll_event event) { - - coreutils::Log(coreutils::LOG_DEBUG_2) << "waiting for lock on socket " << descriptor << "."; lock.lock(); - coreutils::Log(coreutils::LOG_DEBUG_2) << "Obtained lock on socket " << descriptor << "."; if(event.events & EPOLLRDHUP) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLRDHUP " << descriptor; readHangup = true; shutdown("hangup received"); - lock.unlock(); - coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". RDHUP"; + lock.unlock(); return false; } - if(event.events & EPOLLIN) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLIN " << descriptor; - receiveData(buffer, length); + if(event.events & EPOLLIN) {} + receiveData(buffer); } if(event.events & EPOLLWRNORM) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLOUT " << descriptor; - writeSocket(); + writeSocket(); } if(event.events & EPOLLHUP) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLHUP " << descriptor; shutdown(); - lock.unlock(); - coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". HUP"; - return false; + lock.unlock(); + return false; } lock.unlock(); - coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << " with reset " << reset << "."; - reset = true; + reset = true; return reset; } @@ -103,20 +93,20 @@ namespace core { throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1); } - void Socket::onDataReceived(char *buffer, int len) { - onDataReceived(std::string(buffer, len)); + void Socket::onDataReceived(coreutils::ZString data) { + onDataReceived(std::string(data.getData(), data.getLength())); } - void Socket::receiveData(char *buffer, int bufferLength) { + void Socket::receiveData(coreutils::ZString buffer) { - if(bufferLength <= 0) + if(buffer.getLength() <= 0) throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1); int len; int error = -1; - if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0) { - onDataReceived(buffer, len); + if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) { + onDataReceived(buffer); } else { @@ -128,7 +118,7 @@ namespace core { // request we get one of these. // case ENOTCONN: - onDataReceived(std::string(buffer, 0)); + onDataReceived(std::string(buffer.getData(), 0)); break; case ECONNRESET: diff --git a/Socket.h b/Socket.h index 920d900..87e799a 100644 --- a/Socket.h +++ b/Socket.h @@ -3,6 +3,7 @@ #include "includes" #include "Object.h" +#include "ZString.h" namespace core { @@ -146,14 +147,18 @@ namespace core { virtual void onDataReceived(std::string data); ///< Called when data is received from the socket. - virtual void onDataReceived(char *buffer, int len); + /// + /// + /// + + virtual void onDataReceived(coreutils::ZString data); /// /// receiveData will read the data from the socket and place it in the socket buffer. /// TLS layer overrides this to be able to read from SSL. /// - virtual void receiveData(char *buffer, int bufferLength); + virtual void receiveData(coreutils::ZString buffer); private: diff --git a/TCPServer.cpp b/TCPServer.cpp index a4c7668..edd57c2 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -1,4 +1,5 @@ #include "TCPServer.h" +#include "TCPService.h" #include "EPoll.h" #include "TCPSession.h" #include "Exception.h" @@ -12,9 +13,10 @@ namespace core { 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)); + 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"); + throw coreutils::Exception("Error on listen to socket"); + service = getService(ePoll); } TCPServer::~TCPServer() { @@ -58,6 +60,10 @@ namespace core { throw coreutils::Exception(errorString); } + TCPService * TCPServer::getService(EPoll &epoll) { + return new TCPService(epoll); + } + TCPSession * TCPServer::getSocketAccept(EPoll &ePoll) { return new TCPSession(ePoll, *this); } @@ -68,7 +74,7 @@ namespace core { session->send(); } - int TCPServer::processCommand(std::string command, TCPSession *session, std::stringstream &data) { + int TCPServer::processCommand(coreutils::ZString command, TCPSession *session, std::stringstream &data) { int sequence = 0; for(auto *sessionx : sessions) { data << "|" << ++sequence; @@ -77,5 +83,21 @@ namespace core { } return 1; } + + void TCPSession::sendToAll() { + for(auto session : server.sessions) + if(session != this) + session->write(out.str()); + out.str(""); + } + + void TCPSession::sendToAll(SessionFilter filter) { + for(auto session : server.sessions) + if(filter.test(*session)) + if(session != this) + session->write(out.str()); + out.str(""); + } + } diff --git a/TCPServer.h b/TCPServer.h index 0a7360d..4cab2fe 100644 --- a/TCPServer.h +++ b/TCPServer.h @@ -26,13 +26,12 @@ namespace core { public: /// - /// The constructor for the BMATCPSocket object. + /// The constructor for the TCPServer object. /// /// @param ePoll the EPoll instance that manages the socket. /// @param url the IP address for the socket to receive connection requests. /// @param port the port number that the socket will listen on. /// @param commandName the name of the command used to invoke the status display for this object. - /// @return the instance of the BMATCPServerSocket. /// TCPServer(EPoll &ePoll, IPAddress address, std::string text = ""); @@ -43,22 +42,6 @@ namespace core { ~TCPServer(); - /// - /// If not NULL the blacklist object can be assigned to this server socket and the server - /// IP addresses connecting to the server attempting to accept a socket are contained in - /// this list then the connection is rejected and no accept is granted. - /// - - IPAddressList *blackList; - - /// - /// If not NULL the blacklist object can be assigned to this server socket and the server - /// IP addresses connecting to the server attempting to accept a socket are contained in - /// this list then the connection is rejected and no accept is granted. - /// - - IPAddressList *whiteList; - void removeFromSessionList(TCPSession *session); virtual void sessionErrorHandler(std::string errorString, std::stringstream &out); @@ -88,6 +71,26 @@ namespace core { CommandList commands; + /// + /// If not NULL the blacklist object can be assigned to this server socket and the server + /// IP addresses connecting to the server attempting to accept a socket are contained in + /// this list then the connection is rejected and no accept is granted. + /// + + IPAddressList *blackList; + + /// + /// If not NULL the blacklist object can be assigned to this server socket and the server + /// IP addresses connecting to the server attempting to accept a socket are contained in + /// this list then the connection is rejected and no accept is granted. + /// + + IPAddressList *whiteList; + + void removeFromSessionList(TCPSession *session); + + void output(TCPSession *session); /// 0) { - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len); - memcpy(lineBuffer + lineBufferSize, data, len); - lineBufferSize += len; - while(lineBufferSize > 0) { - if(blockSize == 0) { - lineLength = strcspn(lineBuffer, "\r\n"); - if(lineLength == lineBufferSize) - break; - onLineReceived(std::string(lineBuffer, lineLength)); - 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); + 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; + onLineReceived(coreutils::ZString(lineBuffer, lineLength)); + 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) { - onBlockReceived(std::string(lineBuffer, blockLength)); - lineBufferSize -= blockLength; - if(lineBufferSize > 0) - memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize); - lineBuffer = (char *)realloc(lineBuffer, lineBufferSize); - } - } - } + if(lineBufferSize >= blockLength) { + onBlockReceived(coreutils::ZString(lineBuffer, blockLength)); + 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(std::string line) { + + void TCPSession::onLineReceived(coreutils::ZString line) { protocol(line); send(); if(term) shutdown("termination requested"); } - - void TCPSession::onBlockReceived(std::string block) { - coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.length() << "]"; + + void TCPSession::onBlockReceived(coreutils::ZString block) { + coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]"; if(term) shutdown("termination requested"); } - - void TCPSession::sendToAll() { - for(auto session : server.sessions) - if(session != this) - session->write(out.str()); - out.str(""); - } - - void TCPSession::sendToAll(SessionFilter filter) { - for(auto session : server.sessions) - if(filter.test(*session)) - if(session != this) - session->write(out.str()); - out.str(""); - } - + void TCPSession::send() { if(out.tellp() > 0) - write(out.str()); + write(out.str()); out.str(""); } diff --git a/TCPSession.h b/TCPSession.h index 53fd52c..b0e7be4 100644 --- a/TCPSession.h +++ b/TCPSession.h @@ -54,21 +54,6 @@ namespace core { void send(); - /// - /// Use this sendToAll method to output the contents of the out stream - /// to all the connections on the server excluding the sender session. - /// - - void sendToAll(); - - /// - /// Use this sendToAll method to output the contents of the out stream - /// to all the connections on the server excluding the sender session - /// and the entries identified by the passed in filter object. - /// - - void sendToAll(SessionFilter filter); - /// /// Use this method to terminate this TCPSession. /// @@ -94,8 +79,7 @@ namespace core { /// received. If you need data split by line termination characters then /// override the onLineReceived method instead. /// - - virtual void onDataReceived(char *data, int len) override; + virtual void onDataReceived(coreutils::ZString data) override; /// /// Override the onLineReceived method to receive a string of characters that @@ -104,7 +88,7 @@ namespace core { /// this method explicitly using the class and member name. /// - virtual void onLineReceived(std::string line); + virtual void onLineReceived(coreutils::ZString line); /// /// Override the onBlockReceived method to receive a string of characters that @@ -113,7 +97,7 @@ namespace core { /// calls this method explicitly using the class and member name. /// - virtual void onBlockReceived(std::string block); + virtual void onBlockReceived(coreutils::ZString block); /// /// This method is called from within the protocol method when protocol is called @@ -133,7 +117,7 @@ namespace core { /// data through the protocol method: LINE or BLOCK. /// - virtual void protocol(std::string data); + virtual void protocol(coreutils::ZString data); /// /// Use setBlockSize to set the amount of data that should be read at once from the diff --git a/TCPSocket.cpp b/TCPSocket.cpp index efd4754..3ac3606 100644 --- a/TCPSocket.cpp +++ b/TCPSocket.cpp @@ -4,23 +4,23 @@ #include "Exception.h" namespace core { - + TCPSocket::TCPSocket(EPoll &ePoll) : Socket(ePoll) {} TCPSocket::TCPSocket(EPoll &ePoll, std::string text) : Socket(ePoll, text) {} - + TCPSocket::~TCPSocket() {} - + void TCPSocket::connect(IPAddress &address) { setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); - if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1) - throw coreutils::Exception("Error on connect to TCP socket."); - + if(::connect(getDescriptor(), (struct sockaddr *)&address.addr, address.addressLength) == -1) + throw coreutils::Exception("Error on connect to TCP socket."); + } - + void TCPSocket::output(std::stringstream &out) { - out << "|" << ipAddress.getClientAddressAndPort(); + out << "|" << ipAddress.getClientAddressAndPort(); } - + } diff --git a/TLSSession.cpp b/TLSSession.cpp index 56ee2e3..52094e0 100644 --- a/TLSSession.cpp +++ b/TLSSession.cpp @@ -80,18 +80,18 @@ namespace core { TLSSession::~TLSSession() {} - void TLSSession::protocol(std::string data) {} + void TLSSession::protocol(coreutils::ZString data) {} - void TLSSession::receiveData(char *buffer, int bufferLength) { + void TLSSession::receiveData(coreutils::ZString buffer) { int len; // int error = -1; // std::cout << "receiveData TLS" << std::endl; - if((len = ::SSL_read(ssl, buffer, bufferLength)) >= 0) { + if((len = ::SSL_read(ssl, buffer.getData(), buffer.getLength())) >= 0) { std::cout << "receiveData TLS...len=" << len << ":" << buffer << std::endl; - onDataReceived(buffer, len); + onDataReceived(buffer); } else { switch (SSL_get_error(ssl, len)) { diff --git a/TLSSession.h b/TLSSession.h index 12da72d..715d34e 100644 --- a/TLSSession.h +++ b/TLSSession.h @@ -35,10 +35,10 @@ namespace core { /// virtual void output(std::stringstream &out); - virtual void protocol(std::string data) override; + virtual void protocol(coreutils::ZString data) override; protected: - void receiveData(char *buffer, int bufferLength) override; + void receiveData(coreutils::ZString buffer) override; void onRegister(); void onRegistered(); diff --git a/html/CommandList_8h_source.html b/html/CommandList_8h_source.html index 39abef4..a07a5b2 100644 --- a/html/CommandList_8h_source.html +++ b/html/CommandList_8h_source.html @@ -86,7 +86,7 @@ $(function() {
32  void remove(Command &command);
33 
40 
-
41  bool processRequest(std::string request, TCPSession *session, std::stringstream &data);
+
41  bool processRequest(coreutils::ZString request, TCPSession *session, std::stringstream &data);
42 
48 
49  bool grabInput(TCPSession *session, Command &command);
@@ -95,7 +95,7 @@ $(function() {
55  void clearGrab(TCPSession *session);
56 
60 
-
61  int processCommand(std::string request, TCPSession *session, std::stringstream &data);
+
61  int processCommand(std::string request, TCPSession *session, std::stringstream &data);
62 
63  protected:
64 
@@ -108,15 +108,14 @@ $(function() {
74 
75 #endif
-
bool grabInput(TCPSession *session, Command &command)
Definition: CommandList.cpp:28
+
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
-
int processCommand(std::string request, TCPSession *session, std::stringstream &data)
Definition: CommandList.cpp:37
void add(Command &command, std::string name="")
Definition: CommandList.cpp:6
void remove(Command &command)
Definition: CommandList.cpp:11
Definition: Command.h:22
Definition: CommandList.h:18
-
bool processRequest(std::string request, TCPSession *session, std::stringstream &data)
Definition: CommandList.cpp:15