diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 19:28:50 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 19:28:50 +0200 |
commit | 3ea7edf8c9bf7583c426178d4aaff4fb5b736bd2 (patch) | |
tree | ae78ebf9e9d1f70da8a6fdad1504063644ee8f1e /src/operator-starttls.cc | |
parent | 1a7c572099edf744d6bb67318cff215de3fcd897 (diff) |
use some enum classes
move ParseResult to recursivedescent.h
Diffstat (limited to 'src/operator-starttls.cc')
-rw-r--r-- | src/operator-starttls.cc | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/operator-starttls.cc b/src/operator-starttls.cc index 4f68285..7e8b1f4 100644 --- a/src/operator-starttls.cc +++ b/src/operator-starttls.cc @@ -29,12 +29,13 @@ const std::string StarttlsOperator::getName() const return "STARTTLS"; } -int StarttlsOperator::getState() const +Session::State StarttlsOperator::getState() const { - return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED; + return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED + | Session::SELECTED); } -int StarttlsOperator::goStartTLS() const +Operator::ProcessResult StarttlsOperator::goStartTLS() const { Session &session = Session::getInstance(); @@ -44,25 +45,25 @@ int StarttlsOperator::goStartTLS() const fdstr = session.getEnv("SSLCTLFD"); fd = std::stoi(fdstr); - if (write(fd, "Y", 1) < 1) return NOTHING; + if (write(fd, "Y", 1) < 1) return ProcessResult::NOTHING; bincClient.flush(); // flush all previous received data fdstr = session.getEnv("SSLREADFD"); fd = std::stoi(fdstr); - if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING; + if (fcntl(fd, F_GETFL, 0) == -1) return ProcessResult::NOTHING; close(0); - if (fcntl(fd, F_DUPFD, 0) == -1) return NOTHING; + if (fcntl(fd, F_DUPFD, 0) == -1) return ProcessResult::NOTHING; close(fd); fdstr = session.getEnv("SSLWRITEFD"); fd = std::stoi(fdstr); - if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING; + if (fcntl(fd, F_GETFL, 0) == -1) return ProcessResult::NOTHING; close(1); - if (fcntl(fd, F_DUPFD, 1) == -1) return NOTHING; + if (fcntl(fd, F_DUPFD, 1) == -1) return ProcessResult::NOTHING; close(fd); } - return ACCEPT; + return ProcessResult::OK; } Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command) @@ -70,33 +71,33 @@ Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command Session &session = Session::getInstance(); if (session.command.ssl) { session.setLastError("Already in TLS mode"); - return BAD; + return ProcessResult::BAD; } bincClient << "* ENABLED StartTLS - begin negotiation now" << std::endl; bincClient << command.getTag() << " OK STARTTLS completed" << std::endl; - if (goStartTLS() == ACCEPT) + if (goStartTLS() == ProcessResult::OK) session.command.ssl = true; else - return NO; + return ProcessResult::NO; - return NOTHING; + return ProcessResult::NOTHING; } -Operator::ParseResult StarttlsOperator::parse(Request &c_in) const +Parser::ParseResult StarttlsOperator::parse(Request &c_in) { Session &session = Session::getInstance(); - if (c_in.getUidMode()) return REJECT; + if (c_in.getUidMode()) return Parser::ParseResult::REJECT; - Operator::ParseResult res; - if ((res = expectCRLF()) != ACCEPT) { + Parser::ParseResult res; + if ((res = expectCRLF()) != Parser::ParseResult::ACCEPT) { session.setLastError("Expected CRLF"); return res; } c_in.setName("STARTTLS"); - return ACCEPT; + return Parser::ParseResult::ACCEPT; } |