diff options
Diffstat (limited to 'src/imapserver.cc')
-rw-r--r-- | src/imapserver.cc | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/src/imapserver.cc b/src/imapserver.cc index 7c913fb..c4c0d70 100644 --- a/src/imapserver.cc +++ b/src/imapserver.cc @@ -12,6 +12,7 @@ #include "imapparser.h" #include "iodevice.h" #include "iofactory.h" +#include "operators.h" #include "session.h" #include <cstdint> @@ -42,7 +43,7 @@ int IMAPServer::initialize() void IMAPServer::prepareForNextRequest() { - serverStatus = OK; + serverStatus = ServerStatus::OK; bincClient.setFlags(IODevice::HasInputLimit); bincClient.flush(); @@ -63,7 +64,7 @@ int IMAPServer::runStub() int IMAPServer::run() { Session &session = Session::getInstance(); - bincLog.setOutputLevelLimit(IODevice::InfoLevel); + bincLog.setOutputLevelLimit(IODevice::LogLevel::InfoLevel); std::string pid = std::to_string(session.getPid()); bincDebug << "IMAPServer::run(), started server" << endl; @@ -94,20 +95,20 @@ int IMAPServer::run() // Parse the stub of the IMAP request. Request clientRequest; - int stubParseResult = broker->parseStub(clientRequest); - if (stubParseResult == Operator::TIMEOUT) { - serverStatus = Timeout; + Parser::ParseResult stubParseResult = broker->parseStub(clientRequest); + if (stubParseResult == Parser::ParseResult::TIMEOUT) { + serverStatus = ServerStatus::Timeout; break; - } else if (stubParseResult == Operator::REJECT) { - serverStatus = RequestRejected; - } else if (stubParseResult == Operator::ERROR) { - serverStatus = RequestError; + } else if (stubParseResult == Parser::ParseResult::REJECT) { + serverStatus = ServerStatus::RequestRejected; + } else if (stubParseResult == Parser::ParseResult::ERROR) { + serverStatus = ServerStatus::RequestError; } else { // Find an operator that recognizes the name of the request, and // have it continue the parsing. Operator *o = broker->get(clientRequest.getName()); if (!o) { - serverStatus = RequestRejected; + serverStatus = ServerStatus::RequestRejected; std::string err = "The command \""; if (clientRequest.getUidMode()) err += "UID "; err += clientRequest.getName(); @@ -115,26 +116,30 @@ int IMAPServer::run() session.setLastError(err); skipToNextRequest = true; } else { - int parseResult = o->parse(clientRequest); - if (parseResult == Operator::TIMEOUT) { - serverStatus = Timeout; - } else if (parseResult == Operator::REJECT) { - serverStatus = RequestRejected; - } else if (parseResult == Operator::ERROR) { - serverStatus = RequestError; + Parser::ParseResult parseResult = o->parse(clientRequest); + if (parseResult == Parser::ParseResult::TIMEOUT) { + serverStatus = ServerStatus::Timeout; + } else if (parseResult == Parser::ParseResult::REJECT) { + serverStatus = ServerStatus::RequestRejected; + } else if (parseResult == Parser::ParseResult::ERROR) { + serverStatus = ServerStatus::RequestError; } else { session.addStatement(); Depot *dep = session.getDepot(); - int processResult = o->process(*dep, clientRequest); - if (processResult == Operator::OK) { - } else if (processResult == Operator::NO) { - serverStatus = RequestRejected; - } else if (processResult == Operator::BAD) { - serverStatus = RequestError; - } else if (processResult == Operator::NOTHING) { - serverStatus = RequestIgnore; // answer given already - } else if (processResult == Operator::ABORT) { + switch (o->process(*dep, clientRequest)) { + case Operator::ProcessResult::OK: + break; + case Operator::ProcessResult::NO: + serverStatus = ServerStatus::RequestRejected; + break; + case Operator::ProcessResult::BAD: + serverStatus = ServerStatus::RequestError; + break; + case Operator::ProcessResult::NOTHING: + serverStatus = ServerStatus::RequestIgnore; // answer given already + break; + case Operator::ProcessResult::ABORT: session.setState(Session::LOGOUT); } } @@ -143,15 +148,15 @@ int IMAPServer::run() // If a syntax error was detected, we skip all characters in the // input stream up to and including '\n'. - if (serverStatus == RequestRejected) { + if (serverStatus == ServerStatus::RequestRejected) { bincClient << clientRequest.getTag() << " NO " << session.getResponseCode() << clientRequest.getName() << " failed: " << session.getLastError() << endl; - } else if (serverStatus == RequestError) { + } else if (serverStatus == ServerStatus::RequestError) { bincClient << "* BAD " << session.getLastError() << endl; skipToNextRequest = true; - } else if (serverStatus == RequestIgnore) { + } else if (serverStatus == ServerStatus::RequestIgnore) { ; - } else if (serverStatus == OK && session.getState() != Session::LOGOUT) { + } else if (serverStatus == ServerStatus::OK && session.getState() != Session::LOGOUT) { bincClient << clientRequest.getTag() << " OK"; if (clientRequest.getUidMode()) bincClient << " UID"; bincClient << " " << session.getResponseCode() << clientRequest.getName() @@ -169,10 +174,10 @@ int IMAPServer::run() if (skipToNextRequest) { if (!bincClient.skipTo('\n')) { - if (bincClient.getLastError() == IODevice::Timeout) - serverStatus = Timeout; + if (bincClient.getLastError() == IODevice::Error::Timeout) + serverStatus = ServerStatus::Timeout; else - serverStatus = ClientDisconnected; + serverStatus = ServerStatus::ClientDisconnected; break; } } @@ -190,12 +195,12 @@ int IMAPServer::run() << " Statements: " << session.getStatements() << ")\n"; } - if (serverStatus == Timeout) { + if (serverStatus == ServerStatus::Timeout) { bincClient << "* BYE Timeout after " << session.timeout() << " seconds of inactivity\n"; bincClient.flush(); bincLog << "bincimapd: pid " << pid << " Timed out: <" << userID << "> after " << IDLE_TIMEOUT << "s"; - } else if (serverStatus == ClientDisconnected) { + } else if (serverStatus == ServerStatus::ClientDisconnected) { bincLog << "bincimapd: pid " << pid << "Disconnected: <" << userID << ">\n"; } else { if (this->stubMode) { |