Fixing command list delimiter depth.
This commit is contained in:
parent
45aee7ab6f
commit
9af17daed6
@ -11,20 +11,20 @@ namespace core {
|
|||||||
|
|
||||||
void CommandList::remove(Command &command) {}
|
void CommandList::remove(Command &command) {}
|
||||||
|
|
||||||
bool CommandList::processRequest(coreutils::ZString &request, TCPSession &session) {
|
int CommandList::processRequest(coreutils::ZString &request, TCPSession &session) {
|
||||||
if(session.grab != NULL)
|
if(session.grab != NULL)
|
||||||
return session.grab->processCommand(request, session);
|
return session.grab->processCommand(request, session);
|
||||||
else {
|
else {
|
||||||
if(request.equals(""))
|
if(request.equals(""))
|
||||||
return false;
|
return 0;
|
||||||
request.split(delimiter, 10);
|
request.split(delimiter, depth);
|
||||||
request.reset();
|
request.reset();
|
||||||
try {
|
try {
|
||||||
auto command = commands.at(request[0].str());
|
auto command = commands.at(request[0].str());
|
||||||
return command->processCommand(request, session);
|
return command->processCommand(request, session);
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -40,12 +40,9 @@ namespace core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) {
|
int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||||
// for(Command *command : commands)
|
// for(Command *command : commands)
|
||||||
// session.out << command->getName() << std::endl;
|
// session.out << command->getName() << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace core {
|
|||||||
/// then control is given to the process handler holding the grab on the input.
|
/// then control is given to the process handler holding the grab on the input.
|
||||||
///
|
///
|
||||||
|
|
||||||
bool processRequest(coreutils::ZString &request, TCPSession &session);
|
int processRequest(coreutils::ZString &request, TCPSession &session);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Use grabInput() within a Command object to force the requesting handler to receive
|
/// Use grabInput() within a Command object to force the requesting handler to receive
|
||||||
|
@ -1 +0,0 @@
|
|||||||
0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos: 0.000000| pos:
|
|
@ -9,24 +9,24 @@ namespace core {
|
|||||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
||||||
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
||||||
|
|
||||||
commands.add(subscriptions, "publish");
|
commands.add(subscriptions, "publish");
|
||||||
commands.add(subscriptions, "unpublish");
|
commands.add(subscriptions, "unpublish");
|
||||||
commands.add(subscriptions, "subscribe");
|
commands.add(subscriptions, "subscribe");
|
||||||
commands.add(subscriptions, "unsubscribe");
|
commands.add(subscriptions, "unsubscribe");
|
||||||
commands.add(subscriptions, "catalog");
|
commands.add(subscriptions, "catalog");
|
||||||
commands.add(subscriptions, "event");
|
commands.add(subscriptions, "event");
|
||||||
|
|
||||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
|
|
||||||
if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
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)
|
if(listen(getDescriptor(), 20) < 0)
|
||||||
throw coreutils::Exception("Error on listen to socket");
|
throw coreutils::Exception("Error on listen to socket");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPServer::~TCPServer() {
|
TCPServer::~TCPServer() {
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
||||||
@ -70,13 +70,13 @@ namespace core {
|
|||||||
|
|
||||||
void TCPServer::removeFromSessionList(TCPSession *session) {
|
void TCPServer::removeFromSessionList(TCPSession *session) {
|
||||||
std::vector<TCPSession *>::iterator cursor;
|
std::vector<TCPSession *>::iterator cursor;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
||||||
if(*cursor == session) {
|
if(*cursor == session) {
|
||||||
sessions.erase(cursor);
|
sessions.erase(cursor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) {
|
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) {
|
||||||
@ -103,22 +103,22 @@ namespace core {
|
|||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data) {
|
void TCPServer::sendToAll(std::stringstream &data) {
|
||||||
for(auto session : sessions)
|
for(auto session : sessions)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender) {
|
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender) {
|
||||||
for(auto session : sessions)
|
for(auto session : sessions)
|
||||||
if(session != &sender)
|
if(session != &sender)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) {
|
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) {
|
||||||
for(auto session : sessions)
|
for(auto session : sessions)
|
||||||
if(filter.test(*session))
|
if(filter.test(*session))
|
||||||
if(session != &sender)
|
if(session != &sender)
|
||||||
session->write(data.str());
|
session->write(data.str());
|
||||||
data.str("");
|
data.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ namespace core {
|
|||||||
|
|
||||||
void TCPSession::protocol(coreutils::ZString &data) {
|
void TCPSession::protocol(coreutils::ZString &data) {
|
||||||
if(data.getLength() != 0) {
|
if(data.getLength() != 0) {
|
||||||
if(!server.commands.processRequest(data, *this)) {
|
if(server.commands.processRequest(data, *this) == 0) {
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,40 +30,40 @@ namespace core {
|
|||||||
protocol(blank);
|
protocol(blank);
|
||||||
send();
|
send();
|
||||||
if(term)
|
if(term)
|
||||||
shutdown("termination requested");
|
shutdown("termination requested");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPSession::onConnected() {}
|
void TCPSession::onConnected() {}
|
||||||
|
|
||||||
void TCPSession::onDataReceived(coreutils::ZString &data) {
|
void TCPSession::onDataReceived(coreutils::ZString &data) {
|
||||||
if(data.getLength() > 0) {
|
if(data.getLength() > 0) {
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
|
||||||
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength());
|
||||||
lineBufferSize += data.getLength();
|
lineBufferSize += data.getLength();
|
||||||
while(lineBufferSize > 0) {
|
while(lineBufferSize > 0) {
|
||||||
if(blockSize == 0) {
|
if(blockSize == 0) {
|
||||||
lineLength = strcspn(lineBuffer, "\r\n");
|
lineLength = strcspn(lineBuffer, "\r\n");
|
||||||
if(lineLength == lineBufferSize)
|
if(lineLength == lineBufferSize)
|
||||||
break;
|
break;
|
||||||
coreutils::ZString zLine(lineBuffer, lineLength);
|
coreutils::ZString zLine(lineBuffer, lineLength);
|
||||||
onLineReceived(zLine);
|
onLineReceived(zLine);
|
||||||
if(lineBuffer[lineLength] == '\r')
|
if(lineBuffer[lineLength] == '\r')
|
||||||
++lineLength;
|
++lineLength;
|
||||||
if(lineBuffer[lineLength] == '\n')
|
if(lineBuffer[lineLength] == '\n')
|
||||||
++lineLength;
|
++lineLength;
|
||||||
lineBufferSize -= lineLength;
|
lineBufferSize -= lineLength;
|
||||||
if(lineBufferSize > 0)
|
if(lineBufferSize > 0)
|
||||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||||
} else if(lineBufferSize >= blockLength) {
|
} else if(lineBufferSize >= blockLength) {
|
||||||
coreutils::ZString zBlock(lineBuffer, blockLength);
|
coreutils::ZString zBlock(lineBuffer, blockLength);
|
||||||
onBlockReceived(zBlock);
|
onBlockReceived(zBlock);
|
||||||
lineBufferSize -= blockLength;
|
lineBufferSize -= blockLength;
|
||||||
if(lineBufferSize > 0)
|
if(lineBufferSize > 0)
|
||||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace core {
|
|||||||
|
|
||||||
void TCPSession::send() {
|
void TCPSession::send() {
|
||||||
if(out.tellp() > 0)
|
if(out.tellp() > 0)
|
||||||
write(out.str());
|
write(out.str());
|
||||||
out.str("");
|
out.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user