summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-10-11 19:28:50 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-10-11 19:28:50 +0200
commit3ea7edf8c9bf7583c426178d4aaff4fb5b736bd2 (patch)
treeae78ebf9e9d1f70da8a6fdad1504063644ee8f1e
parent1a7c572099edf744d6bb67318cff215de3fcd897 (diff)
use some enum classes
move ParseResult to recursivedescent.h
-rw-r--r--src/Makefile2
-rw-r--r--src/broker.cc88
-rw-r--r--src/imapserver.cc75
-rw-r--r--src/include/broker.h23
-rw-r--r--src/include/imapserver.h2
-rw-r--r--src/include/iodevice.h4
-rw-r--r--src/include/iofactory.h16
-rw-r--r--src/include/operators.h154
-rw-r--r--src/include/recursivedescent.h71
-rw-r--r--src/include/session.h18
-rw-r--r--src/iodevice.cc6
-rw-r--r--src/operator-append.cc18
-rw-r--r--src/operator-authenticate.cc16
-rw-r--r--src/operator-capability.cc17
-rw-r--r--src/operator-check.cc13
-rw-r--r--src/operator-close.cc14
-rw-r--r--src/operator-copy.cc16
-rw-r--r--src/operator-create.cc15
-rw-r--r--src/operator-delete.cc16
-rw-r--r--src/operator-expunge.cc14
-rw-r--r--src/operator-fetch.cc42
-rw-r--r--src/operator-id.cc15
-rw-r--r--src/operator-idle.cc20
-rw-r--r--src/operator-list.cc16
-rw-r--r--src/operator-login.cc18
-rw-r--r--src/operator-logout.cc17
-rw-r--r--src/operator-lsub.cc14
-rw-r--r--src/operator-namespace.cc16
-rw-r--r--src/operator-noop-pending.cc2
-rw-r--r--src/operator-noop.cc17
-rw-r--r--src/operator-rename.cc20
-rw-r--r--src/operator-search.cc20
-rw-r--r--src/operator-select.cc23
-rw-r--r--src/operator-starttls.cc37
-rw-r--r--src/operator-status.cc18
-rw-r--r--src/operator-store.cc10
-rw-r--r--src/operator-subscribe.cc20
-rw-r--r--src/operator-unsubscribe.cc22
-rw-r--r--src/recursivedescent.cc492
-rw-r--r--src/session-initialize-bincimap-up.cc2
-rw-r--r--src/session-initialize-bincimapd.cc2
-rw-r--r--src/session.cc4
-rw-r--r--src/stdiodevice.cc4
43 files changed, 750 insertions, 699 deletions
diff --git a/src/Makefile b/src/Makefile
index aff63b7..20a6c07 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
SHELL=/bin/sh
CXX = c++
-CXXFLAGS = -Og -Iinclude -Wall
+CXXFLAGS = -Og -Iinclude -Wall
#LIBDL = -ldl
bincimapd_OBJECTS = bincimapd.o address.o argparser.o authenticate.o base64.o \
diff --git a/src/broker.cc b/src/broker.cc
index 0a063f5..4fa9ec8 100644
--- a/src/broker.cc
+++ b/src/broker.cc
@@ -20,9 +20,9 @@ using std::string;
BrokerFactory::BrokerFactory()
{
- brokers[Session::NONAUTHENTICATED] = new Broker();
- brokers[Session::AUTHENTICATED] = new Broker();
- brokers[Session::SELECTED] = new Broker();
+ brokers[Session::State::NONAUTHENTICATED] = new Broker();
+ brokers[Session::State::AUTHENTICATED] = new Broker();
+ brokers[Session::State::SELECTED] = new Broker();
}
BrokerFactory::~BrokerFactory()
@@ -59,7 +59,7 @@ void BrokerFactory::assign(const string &fname, Operator *o)
}
}
-Operator *BrokerFactory::getOperator(int state, const string &name) const
+Operator *BrokerFactory::getOperator(Session::State state, const string &name) const
{
if (brokers.find(state) == brokers.end())
return nullptr;
@@ -67,20 +67,17 @@ Operator *BrokerFactory::getOperator(int state, const string &name) const
return brokers.find(state)->second->get(name);
}
-Broker *BrokerFactory::getBroker(int state)
+Broker *BrokerFactory::getBroker(Session::State state)
{
- if (brokers.find(state) == brokers.end()) {
+ auto it = brokers.find(state);
+ if (it == brokers.end()) {
setLastError("No appropriate broker for state.");
return nullptr;
}
- return brokers[state];
+ return it->second;
}
-Broker::Broker() {}
-
-Broker::~Broker() {}
-
void Broker::assign(const string &fname, Operator *o, bool deletable)
{
deletables[fname] = deletable;
@@ -93,47 +90,52 @@ Operator *Broker::get(const string &name) const
return operators.find(name)->second;
}
-Operator::ParseResult Broker::parseStub(Request &command)
+Parser::ParseResult Broker::parseStub(Request &command)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+ constexpr auto REJECT = Parser::ParseResult::REJECT;
+ constexpr auto ERROR = Parser::ParseResult::ERROR;
+ constexpr auto TIMEOUT = Parser::ParseResult::TIMEOUT;
+
Session &session = Session::getInstance();
string tag;
string cmd;
switch (expectTag(tag)) {
- case Operator::ACCEPT:
+ case ACCEPT:
break;
- case Operator::REJECT:
+ case REJECT:
session.setLastError("Syntax error; first token must be a tag");
[[fallthrough]];
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
switch (expectSPACE()) {
- case Operator::ACCEPT:
+ case ACCEPT:
break;
- case Operator::REJECT:
+ case REJECT:
session.setLastError("Syntax error; second token must be a SPACE");
[[fallthrough]];
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
switch (expectAstring(cmd)) {
- case Operator::ACCEPT:
+ case ACCEPT:
break;
- case Operator::REJECT:
+ case REJECT:
session.setLastError("Syntax error; third token must be a command");
[[fallthrough]];
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
uppercase(cmd);
@@ -142,27 +144,27 @@ Operator::ParseResult Broker::parseStub(Request &command)
command.setUidMode();
switch (expectSPACE()) {
- case Operator::ACCEPT:
+ case ACCEPT:
break;
- case Operator::REJECT:
+ case REJECT:
session.setLastError("Syntax error; after UID there must come a SPACE");
[[fallthrough]];
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
switch (expectAstring(cmd)) {
- case Operator::ACCEPT:
+ case ACCEPT:
break;
- case Operator::REJECT:
+ case REJECT:
session.setLastError("Syntax error; after UID SPACE there must come a command");
[[fallthrough]];
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
uppercase(cmd);
@@ -171,5 +173,5 @@ Operator::ParseResult Broker::parseStub(Request &command)
command.setTag(tag);
command.setName(cmd);
- return Operator::ACCEPT;
+ return ACCEPT;
}
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) {
diff --git a/src/include/broker.h b/src/include/broker.h
index 7cca0aa..0ead7a0 100644
--- a/src/include/broker.h
+++ b/src/include/broker.h
@@ -10,6 +10,7 @@
#include "depot.h"
#include "operators.h"
+#include "session.h"
#include <map>
#include <string>
@@ -21,17 +22,17 @@ namespace Binc {
class BrokerFactory {
private:
- std::map<int, Broker *> brokers;
+ std::map<Session::State, Broker *> brokers;
BrokerFactory();
mutable std::string lastError;
public:
- Broker *getBroker(int state);
+ Broker *getBroker(Session::State state);
void assign(const std::string &fname, Operator *o);
void addCapability(const std::string &c);
- Operator *getOperator(int state, const std::string &name) const;
+ Operator *getOperator(Session::State state, const std::string &name) const;
inline const std::string &getLastError() const;
inline void setLastError(const std::string &error) const;
@@ -40,12 +41,12 @@ namespace Binc {
~BrokerFactory();
};
- inline const std::string &BrokerFactory::getLastError() const
+ const std::string &BrokerFactory::getLastError() const
{
return lastError;
}
- inline void BrokerFactory::setLastError(const std::string &error) const
+ void BrokerFactory::setLastError(const std::string &error) const
{
lastError = error;
}
@@ -58,18 +59,12 @@ namespace Binc {
public:
Operator *get(const std::string &name) const;
void assign(const std::string &fname, Operator *o, bool deletable = false);
- Operator::ParseResult parseStub(Request &cmd);
+ Parser::ParseResult parseStub(Request &cmd);
- inline Broker(Broker &);
- inline Broker(const Broker &);
- Broker();
- ~Broker();
+ Broker() = default;
+ Broker(Broker &&) = default;
};
- inline Broker::Broker(Broker &) {}
-
- inline Broker::Broker(const Broker &) {}
-
}
#endif
diff --git a/src/include/imapserver.h b/src/include/imapserver.h
index 76b2a83..b975022 100644
--- a/src/include/imapserver.h
+++ b/src/include/imapserver.h
@@ -16,7 +16,7 @@ namespace Binc {
int runStub();
int run();
- enum ServerStatus {
+ enum class ServerStatus {
OK,
RequestError,
RequestIgnore, // required for StartTLS, premature answer
diff --git a/src/include/iodevice.h b/src/include/iodevice.h
index 3e3330d..18e3a83 100644
--- a/src/include/iodevice.h
+++ b/src/include/iodevice.h
@@ -43,7 +43,7 @@ namespace Binc {
};
/// Errors from when an operation returned false.
- enum Error { Unknown, Timeout };
+ enum class Error { Unknown, Timeout };
/**
* Constructs an invalid IODevice.
@@ -123,7 +123,7 @@ namespace Binc {
*/
unsigned int getTimeout() const;
- enum LogLevel { ErrorLevel, InfoLevel, WarningLevel, DebugLevel };
+ enum class LogLevel { ErrorLevel, InfoLevel, WarningLevel, DebugLevel };
/**
* Sets the output level for the following write operations on this
diff --git a/src/include/iofactory.h b/src/include/iofactory.h
index 52e911b..24dfe9f 100644
--- a/src/include/iofactory.h
+++ b/src/include/iofactory.h
@@ -40,19 +40,19 @@ namespace Binc {
#define bincDebug std::cerr
// #define bincDebug if (false) std::cout
#else
-#define bincError \
- IOFactory::getLogger().setOutputLevel(IODevice::ErrorLevel); \
+#define bincError \
+ IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::ErrorLevel); \
IOFactory::getLogger()
-#define bincWarning \
- IOFactory::getLogger().setOutputLevel(IODevice::WarningLevel); \
+#define bincWarning \
+ IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::WarningLevel); \
IOFactory::getLogger()
-#define bincDebug \
- IOFactory::getLogger().setOutputLevel(IODevice::DebugLevel); \
+#define bincDebug \
+ IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::DebugLevel); \
IOFactory::getLogger()
#endif
-#define bincLog \
- IOFactory::getLogger().setOutputLevel(IODevice::InfoLevel); \
+#define bincLog \
+ IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::InfoLevel); \
IOFactory::getLogger()
#endif
diff --git a/src/include/operators.h b/src/include/operators.h
index 9cfd10a..bc03607 100644
--- a/src/include/operators.h
+++ b/src/include/operators.h
@@ -11,32 +11,30 @@
#include "depot.h"
#include "imapparser.h"
#include "message.h"
+#include "recursivedescent.h"
+#include "session.h"
#include <string>
#include <vector>
namespace Binc {
- class Operator {
- public:
- enum ProcessResult { OK, BAD, NO, NOTHING, ABORT };
-
- enum ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT };
+ struct Operator {
+ enum class ProcessResult { OK, BAD, NO, NOTHING, ABORT };
virtual ProcessResult process(Depot &, Request &) = 0;
- virtual ParseResult parse(Request &) const = 0;
- virtual int getState() const = 0;
+ virtual Parser::ParseResult parse(Request &) = 0;
+ virtual Session::State getState() const = 0;
virtual const std::string getName() const = 0;
- virtual ~Operator(){};
+ virtual ~Operator() = default;
};
- class AppendOperator : public Operator {
- public:
- ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
- const std::string getName() const;
- int getState() const;
+ struct AppendOperator : public Operator {
+ ProcessResult process(Depot &, Request &) final;
+ Parser::ParseResult parse(Request &) final;
+ const std::string getName() const final;
+ Session::State getState() const final;
AppendOperator();
~AppendOperator();
@@ -44,11 +42,11 @@ namespace Binc {
class AuthenticateOperator : public Operator {
public:
- ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ ProcessResult process(Depot &, Request &) override;
+ virtual Parser::ParseResult parse(Request &) override;
- const std::string getName() const;
- int getState() const;
+ const std::string getName() const override;
+ Session::State getState() const override;
ProcessResult Login(std::string &username, std::string &password);
ProcessResult Plain(std::string &username, std::string &password);
@@ -63,10 +61,10 @@ namespace Binc {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
void addCapability(const std::string &cap);
@@ -77,10 +75,10 @@ namespace Binc {
class CheckOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
CheckOperator();
~CheckOperator();
@@ -89,10 +87,10 @@ namespace Binc {
class CreateOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
CreateOperator();
~CreateOperator();
@@ -101,10 +99,10 @@ namespace Binc {
class CloseOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
CloseOperator();
~CloseOperator();
@@ -113,10 +111,10 @@ namespace Binc {
class CopyOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
CopyOperator();
~CopyOperator();
@@ -125,10 +123,10 @@ namespace Binc {
class DeleteOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
DeleteOperator();
~DeleteOperator();
@@ -137,10 +135,10 @@ namespace Binc {
class ExpungeOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
ExpungeOperator();
~ExpungeOperator();
@@ -148,18 +146,18 @@ namespace Binc {
class FetchOperator : public Operator {
protected:
- ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const;
- ParseResult expectSection(BincImapParserFetchAtt &f_in) const;
- ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
- ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
- ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectSection(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
FetchOperator();
~FetchOperator();
@@ -168,10 +166,10 @@ namespace Binc {
class IdOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
IdOperator();
~IdOperator();
@@ -179,18 +177,18 @@ namespace Binc {
class IdleOperator : public Operator {
protected:
- ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const;
- ParseResult expectSection(BincImapParserFetchAtt &f_in) const;
- ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
- ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
- ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectSection(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
+ Parser::ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
IdleOperator();
~IdleOperator();
@@ -210,10 +208,10 @@ namespace Binc {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
ListOperator();
~ListOperator();
@@ -222,10 +220,10 @@ namespace Binc {
class LoginOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
LoginOperator();
~LoginOperator();
@@ -234,10 +232,10 @@ namespace Binc {
class LogoutOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
LogoutOperator();
~LogoutOperator();
@@ -246,10 +244,10 @@ namespace Binc {
class LsubOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
LsubOperator();
~LsubOperator();
@@ -258,10 +256,10 @@ namespace Binc {
class NamespaceOperator : public Operator {
public:
virtual ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
NamespaceOperator();
~NamespaceOperator();
@@ -270,10 +268,10 @@ namespace Binc {
class NoopOperator : public Operator {
public:
virtual ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
NoopOperator();
~NoopOperator();
@@ -290,10 +288,10 @@ namespace Binc {
class RenameOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
RenameOperator();
~RenameOperator();
@@ -301,7 +299,7 @@ namespace Binc {
class SearchOperator : public Operator {
protected:
- ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const;
+ Parser::ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const;
class SearchNode {
std::string date;
@@ -386,10 +384,10 @@ namespace Binc {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
SearchOperator();
~SearchOperator();
@@ -398,10 +396,10 @@ namespace Binc {
class SelectOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
SelectOperator();
~SelectOperator();
@@ -417,11 +415,11 @@ namespace Binc {
class StarttlsOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
- int goStartTLS() const;
+ Session::State getState() const;
+ ProcessResult goStartTLS() const;
StarttlsOperator();
~StarttlsOperator();
@@ -432,10 +430,10 @@ namespace Binc {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
StatusOperator();
~StatusOperator();
@@ -444,10 +442,10 @@ namespace Binc {
class StoreOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
StoreOperator();
~StoreOperator();
@@ -456,10 +454,10 @@ namespace Binc {
class SubscribeOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
SubscribeOperator();
~SubscribeOperator();
@@ -468,10 +466,10 @@ namespace Binc {
class UnsubscribeOperator : public Operator {
public:
ProcessResult process(Depot &, Request &);
- virtual ParseResult parse(Request &) const;
+ virtual Parser::ParseResult parse(Request &);
const std::string getName() const;
- int getState() const;
+ Session::State getState() const;
UnsubscribeOperator();
~UnsubscribeOperator();
diff --git a/src/include/recursivedescent.h b/src/include/recursivedescent.h
index ea8dc67..1200211 100644
--- a/src/include/recursivedescent.h
+++ b/src/include/recursivedescent.h
@@ -1,15 +1,14 @@
/**
- * @file recursivedescent.h
- * @brief Declaration of a recursive descent IMAP command parser.
- * @author Andreas Aardal Hanssen
- * @date Andreas Aardal Hanssen
+ * @file recursivedescent.h
+ * @brief Declaration of a recursive descent IMAP command parser.
+ * @author Andreas Aardal Hanssen, Jannis M. Hoffmann
+ * @date 2002-2023
*/
#ifndef expectcommand_h_inluded
#define expectcommand_h_inluded
#include "imapparser.h"
-#include "operators.h"
#include <stack>
#include <string>
@@ -23,44 +22,50 @@ namespace Binc {
void unReadChar(int c_in);
void unReadChar(const std::string &s_in);
- Operator::ParseResult expectTag(std::string &s_in);
- Operator::ParseResult expectTagChar(int &c_in);
- Operator::ParseResult expectSPACE();
+ namespace Parser {
+ enum class ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT };
+ }
- Operator::ParseResult expectFlag(std::vector<std::string> &v_in);
+ using ParseResult = Parser::ParseResult;
- Operator::ParseResult expectListMailbox(std::string &s_in);
- Operator::ParseResult expectListWildcards(int &c_in);
+ ParseResult expectTag(std::string &s_in);
+ ParseResult expectTagChar(int &c_in);
+ ParseResult expectSPACE();
- Operator::ParseResult expectDateTime(std::string &s_in);
- Operator::ParseResult expectTime(std::string &s_in);
- Operator::ParseResult expectZone(std::string &s_in);
+ ParseResult expectFlag(std::vector<std::string> &v_in);
- Operator::ParseResult expectMailbox(std::string &s_in);
- Operator::ParseResult expectAstring(std::string &s_in);
- Operator::ParseResult expectAtom(std::string &s_in);
- Operator::ParseResult expectAtomChar(int &i_in);
- Operator::ParseResult expectString(std::string &s_in);
+ ParseResult expectListMailbox(std::string &s_in);
+ ParseResult expectListWildcards(int &c_in);
- Operator::ParseResult expectDate(std::string &s_in);
+ ParseResult expectDateTime(std::string &s_in);
+ ParseResult expectTime(std::string &s_in);
+ ParseResult expectZone(std::string &s_in);
- Operator::ParseResult expectNumber(unsigned int &i_in);
- Operator::ParseResult expectDigit(unsigned int &i_in);
- Operator::ParseResult expectDigitNZ(unsigned int &i_in);
+ ParseResult expectMailbox(std::string &s_in);
+ ParseResult expectAstring(std::string &s_in);
+ ParseResult expectAtom(std::string &s_in);
+ ParseResult expectAtomChar(int &i_in);
+ ParseResult expectString(std::string &s_in);
- Operator::ParseResult expectLiteral(std::string &s_in);
- Operator::ParseResult expectQuoted(std::string &s_in);
- Operator::ParseResult expectQuotedChar(int &c_in);
+ ParseResult expectDate(std::string &s_in);
- Operator::ParseResult expectSet(SequenceSet &s_in);
- Operator::ParseResult expectSequenceNum(unsigned int &i_in);
- Operator::ParseResult expectNZNumber(unsigned int &i_in);
+ ParseResult expectNumber(unsigned int &i_in);
+ ParseResult expectDigit(unsigned int &i_in);
+ ParseResult expectDigitNZ(unsigned int &i_in);
- Operator::ParseResult expectCRLF();
- Operator::ParseResult expectCR();
- Operator::ParseResult expectLF();
+ ParseResult expectLiteral(std::string &s_in);
+ ParseResult expectQuoted(std::string &s_in);
+ ParseResult expectQuotedChar(int &c_in);
- Operator::ParseResult expectThisString(const std::string &s_in);
+ ParseResult expectSet(SequenceSet &s_in);
+ ParseResult expectSequenceNum(unsigned int &i_in);
+ ParseResult expectNZNumber(unsigned int &i_in);
+
+ ParseResult expectCRLF();
+ ParseResult expectCR();
+ ParseResult expectLF();
+
+ ParseResult expectThisString(const std::string &s_in);
}
#endif
diff --git a/src/include/session.h b/src/include/session.h
index 6d9ffc1..8712307 100644
--- a/src/include/session.h
+++ b/src/include/session.h
@@ -38,7 +38,7 @@ namespace Binc {
NONAUTHENTICATED = 0x01,
AUTHENTICATED = 0x02,
SELECTED = 0x04,
- LOGOUT = 0x00
+ LOGOUT = 0x00,
};
CommandLineArgs args;
@@ -49,8 +49,9 @@ namespace Binc {
std::string getEnv(const std::string &key);
void setEnv(const std::string &key, const std::string &value);
- int getState() const;
- void setState(int n);
+ Session::State getState() const;
+ void setState(Session::State n);
+
bool parseCommandLine(int argc, char *argv[]);
void assignCommandLineArgs();
int getWriteBytes() const;
@@ -76,14 +77,17 @@ namespace Binc {
void setIP(const std::string &ip);
void setUserID(const std::string &s);
- inline Depot *getDepot() const;
+ Depot *getDepot() const
+ {
+ return depot;
+ }
static Session &getInstance();
bool initialize(int argc, char *argv[]);
private:
- int state;
+ Session::State state;
std::string userid;
std::string ip;
char **argv;
@@ -107,10 +111,6 @@ namespace Binc {
Session();
};
- inline Depot *Session::getDepot() const
- {
- return depot;
- }
}
#endif
diff --git a/src/iodevice.cc b/src/iodevice.cc
index e68167f..6ee0e5f 100644
--- a/src/iodevice.cc
+++ b/src/iodevice.cc
@@ -24,9 +24,9 @@ IODevice::IODevice(int f)
, timeout(0)
, readCount(0)
, writeCount(0)
- , outputLevel(ErrorLevel)
- , outputLevelLimit(ErrorLevel)
- , error(Unknown)
+ , outputLevel(LogLevel::ErrorLevel)
+ , outputLevelLimit(LogLevel::ErrorLevel)
+ , error(Error::Unknown)
, errorString("Unknown device error")
, dumpfd(0)
{}
diff --git a/src/operator-append.cc b/src/operator-append.cc
index 9463723..0e856ba 100644
--- a/src/operator-append.cc
+++ b/src/operator-append.cc
@@ -31,13 +31,17 @@ const string AppendOperator::getName() const
return "APPEND";
}
-int AppendOperator::getState() const
+Session::State AppendOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::State::AUTHENTICATED | Session::State::SELECTED);
}
Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command)
{
+ constexpr auto NO = ProcessResult::NO;
+ constexpr auto ABORT = ProcessResult::ABORT;
+ constexpr auto BAD = ProcessResult::BAD;
+
Session &session = Session::getInstance();
const string &srcmailbox = command.getMailbox();
@@ -242,15 +246,17 @@ Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command)
true);
}
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult AppendOperator::parse(Request &c_in) const
+Parser::ParseResult AppendOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after APPEND");
diff --git a/src/operator-authenticate.cc b/src/operator-authenticate.cc
index 045b008..8689b2c 100644
--- a/src/operator-authenticate.cc
+++ b/src/operator-authenticate.cc
@@ -22,6 +22,10 @@
using namespace Binc;
using std::endl;
using std::string;
+constexpr auto BAD = Operator::ProcessResult::BAD;
+constexpr auto NO = Operator::ProcessResult::NO;
+constexpr auto OK = Operator::ProcessResult::OK;
+constexpr auto NOTHING = Operator::ProcessResult::NOTHING;
AuthenticateOperator::AuthenticateOperator() {}
@@ -32,7 +36,7 @@ const string AuthenticateOperator::getName() const
return "AUTHENTICATE";
}
-int AuthenticateOperator::getState() const
+Session::State AuthenticateOperator::getState() const
{
return Session::NONAUTHENTICATED;
}
@@ -276,13 +280,15 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot, Request &com
return NOTHING;
}
-Operator::ParseResult AuthenticateOperator::parse(Request &c_in) const
+Parser::ParseResult AuthenticateOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected single SPACE after AUTHENTICATE");
@@ -292,7 +298,7 @@ Operator::ParseResult AuthenticateOperator::parse(Request &c_in) const
string authtype;
if ((res = expectAtom(authtype)) != ACCEPT) {
session.setLastError("Expected auth_type after AUTHENTICATE SPACE");
- return ERROR;
+ return Parser::ParseResult::ERROR;
}
if ((res = expectCRLF()) != ACCEPT) {
diff --git a/src/operator-capability.cc b/src/operator-capability.cc
index eff7e5a..33d787a 100644
--- a/src/operator-capability.cc
+++ b/src/operator-capability.cc
@@ -27,9 +27,10 @@ const string CapabilityOperator::getName() const
return "CAPABILITY";
}
-int CapabilityOperator::getState() const
+Session::State CapabilityOperator::getState() const
{
- return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED
+ | Session::SELECTED);
}
void CapabilityOperator::addCapability(const string &cap)
@@ -69,22 +70,22 @@ Operator::ProcessResult CapabilityOperator::process(Depot &depot, Request &comma
}
bincClient << std::endl;
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult CapabilityOperator::parse(Request &c_in) const
+Parser::ParseResult CapabilityOperator::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 after CAPABILITY");
return res;
}
c_in.setName("CAPABILITY");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-check.cc b/src/operator-check.cc
index 260487e..2514fcc 100644
--- a/src/operator-check.cc
+++ b/src/operator-check.cc
@@ -25,7 +25,7 @@ const std::string CheckOperator::getName() const
return "CHECK";
}
-int CheckOperator::getState() const
+Session::State CheckOperator::getState() const
{
return Session::SELECTED;
}
@@ -39,21 +39,20 @@ Operator::ProcessResult CheckOperator::process(Depot &depot, Request &command)
true);
}
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult CheckOperator::parse(Request &c_in) const
+Parser::ParseResult CheckOperator::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) {
+ if (Parser::ParseResult res = expectCRLF(); res != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected CRLF after CHECK");
return res;
}
c_in.setName("CHECK");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-close.cc b/src/operator-close.cc
index 322dea1..37e4805 100644
--- a/src/operator-close.cc
+++ b/src/operator-close.cc
@@ -24,7 +24,7 @@ const std::string CloseOperator::getName() const
return "CLOSE";
}
-int CloseOperator::getState() const
+Session::State CloseOperator::getState() const
{
return Session::SELECTED;
}
@@ -39,21 +39,21 @@ Operator::ProcessResult CloseOperator::process(Depot &depot, Request &command)
Session &session = Session::getInstance();
session.setState(Session::AUTHENTICATED);
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult CloseOperator::parse(Request &c_in) const
+Parser::ParseResult CloseOperator::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 after CLOSE");
return res;
}
c_in.setName("CLOSE");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-copy.cc b/src/operator-copy.cc
index 06204b2..b2aaa62 100644
--- a/src/operator-copy.cc
+++ b/src/operator-copy.cc
@@ -28,7 +28,7 @@ const string CopyOperator::getName() const
return "COPY";
}
-int CopyOperator::getState() const
+Session::State CopyOperator::getState() const
{
return Session::SELECTED;
}
@@ -46,7 +46,7 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command)
if (destMailbox == nullptr) {
session.setResponseCode("TRYCREATE");
session.setLastError("invalid mailbox " + toImapString(dmailbox));
- return NO;
+ return Operator::ProcessResult::NO;
}
unsigned int mode = Mailbox::SKIP_EXPUNGED;
@@ -103,14 +103,14 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command)
if (!success && !destMailbox->rollBackNewMessages()) {
session.setLastError("Failed to rollback after unsuccessful copy: "
+ destMailbox->getLastError());
- return NO;
+ return Operator::ProcessResult::NO;
}
if (success) {
if (!destMailbox->commitNewMessages(depot.mailboxToFilename(toCanonMailbox(dmailbox)))) {
session.setLastError("Failed to commit after successful copy: "
+ destMailbox->getLastError());
- return NO;
+ return Operator::ProcessResult::NO;
}
}
@@ -120,14 +120,16 @@ Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command)
"more information.");
}
- return success ? OK : NO;
+ return success ? Operator::ProcessResult::OK : Operator::ProcessResult::NO;
}
-Operator::ParseResult CopyOperator::parse(Request &c_in) const
+Parser::ParseResult CopyOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after COPY");
return res;
diff --git a/src/operator-create.cc b/src/operator-create.cc
index 4269c7a..399e740 100644
--- a/src/operator-create.cc
+++ b/src/operator-create.cc
@@ -26,29 +26,30 @@ const std::string CreateOperator::getName() const
return "CREATE";
}
-int CreateOperator::getState() const
+Session::State CreateOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult CreateOperator::process(Depot &depot, Request &command)
{
if (depot.createMailbox(command.getMailbox())) {
- return OK;
+ return Operator::ProcessResult::OK;
} else {
Session &session = Session::getInstance();
session.setLastError(depot.getLastError());
- return NO;
+ return Operator::ProcessResult::NO;
}
}
-Operator::ParseResult CreateOperator::parse(Request &c_in) const
+Parser::ParseResult CreateOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after CREATE");
return res;
diff --git a/src/operator-delete.cc b/src/operator-delete.cc
index fb7ff4d..a706d01 100644
--- a/src/operator-delete.cc
+++ b/src/operator-delete.cc
@@ -26,29 +26,31 @@ const std::string DeleteOperator::getName() const
return "DELETE";
}
-int DeleteOperator::getState() const
+Session::State DeleteOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult DeleteOperator::process(Depot &depot, Request &command)
{
if (depot.deleteMailbox(command.getMailbox())) {
- return OK;
+ return Operator::ProcessResult::OK;
} else {
Session &session = Session::getInstance();
session.setLastError(depot.getLastError());
- return NO;
+ return Operator::ProcessResult::NO;
}
}
-Operator::ParseResult DeleteOperator::parse(Request &c_in) const
+Parser::ParseResult DeleteOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after DELETE");
return res;
diff --git a/src/operator-expunge.cc b/src/operator-expunge.cc
index c987543..0a70c2f 100644
--- a/src/operator-expunge.cc
+++ b/src/operator-expunge.cc
@@ -26,7 +26,7 @@ const std::string ExpungeOperator::getName() const
return "EXPUNGE";
}
-int ExpungeOperator::getState() const
+Session::State ExpungeOperator::getState() const
{
return Session::SELECTED;
}
@@ -41,21 +41,21 @@ Operator::ProcessResult ExpungeOperator::process(Depot &depot, Request &command)
| PendingUpdates::FLAGS,
true);
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult ExpungeOperator::parse(Request &c_in) const
+Parser::ParseResult ExpungeOperator::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("EXPUNGE");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-fetch.cc b/src/operator-fetch.cc
index be6cbba..7de2fbb 100644
--- a/src/operator-fetch.cc
+++ b/src/operator-fetch.cc
@@ -1,8 +1,8 @@
/**
- * @file operator-fetch.cc
- * @brief Implementation of the FETCH command
- * @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @file operator-fetch.cc
+ * @brief Implementation of the FETCH command
+ * @author Andreas Aardal Hanssen
+ * @date 2002-2005
*/
#include "convert.h"
@@ -22,6 +22,10 @@ using namespace Binc;
using std::string;
using std::vector;
+constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+constexpr auto ERROR = Parser::ParseResult::ERROR;
+constexpr auto REJECT = Parser::ParseResult::REJECT;
+
namespace {
void outputFlags(const Message &message)
{
@@ -62,7 +66,7 @@ const string FetchOperator::getName() const
return "FETCH";
}
-int FetchOperator::getState() const
+Session::State FetchOperator::getState() const
{
return Session::SELECTED;
}
@@ -358,14 +362,14 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request)
| PendingUpdates::RECENT,
true);
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult FetchOperator::parse(Request &c_in) const
+Parser::ParseResult FetchOperator::parse(Request &c_in)
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after FETCH");
return res;
@@ -428,11 +432,11 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const
return ACCEPT;
}
-Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
+Parser::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectThisString("HEADER")) == ACCEPT) {
f_in.sectiontext = "HEADER";
@@ -454,17 +458,17 @@ Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f
} else if ((res = expectThisString("TEXT")) == ACCEPT) {
f_in.sectiontext = "TEXT";
} else {
- return REJECT;
+ return Parser::ParseResult::REJECT;
}
return ACCEPT;
}
-Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
+Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectThisString("[")) != ACCEPT) return REJECT;
if ((res = expectSectionText(f_in)) != ACCEPT) {
@@ -508,11 +512,11 @@ Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in)
return ACCEPT;
}
-Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
+Parser::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectThisString("(")) != ACCEPT) return REJECT;
string header_fld_name;
@@ -538,10 +542,10 @@ Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_
return ACCEPT;
}
-Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const
+Parser::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectThisString("<")) != ACCEPT) return REJECT;
@@ -572,9 +576,9 @@ Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in)
return ACCEPT;
}
-Operator::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const
+Parser::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const
{
- Operator::ParseResult res;
+ Parser::ParseResult res;
Session &session = Session::getInstance();
diff --git a/src/operator-id.cc b/src/operator-id.cc
index db5b79b..4d72320 100644
--- a/src/operator-id.cc
+++ b/src/operator-id.cc
@@ -27,9 +27,10 @@ const std::string IdOperator::getName() const
return "ID";
}
-int IdOperator::getState() const
+Session::State IdOperator::getState() const
{
- return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED
+ | Session::SELECTED);
}
Operator::ProcessResult IdOperator::process(Depot &depot, Request &command)
@@ -37,16 +38,18 @@ Operator::ProcessResult IdOperator::process(Depot &depot, Request &command)
bincClient << "* ID (\"name\" \"Binc IMAP\""
<< " \"version\" \"" << BINC_VERSION "\")" << std::endl;
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult IdOperator::parse(Request &c_in) const
+Parser::ParseResult IdOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT && (res = expectCRLF()) != ACCEPT) {
session.setLastError("Expected SPACE or CRLF");
return res;
diff --git a/src/operator-idle.cc b/src/operator-idle.cc
index 7c5ce40..3ce9673 100644
--- a/src/operator-idle.cc
+++ b/src/operator-idle.cc
@@ -57,7 +57,7 @@ const std::string IdleOperator::getName() const
return "IDLE";
}
-int IdleOperator::getState() const
+Session::State IdleOperator::getState() const
{
return Session::SELECTED;
}
@@ -120,7 +120,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command)
session.setState(Session::LOGOUT);
close(newfd);
close(curfd);
- return NOTHING;
+ return Operator::ProcessResult::NOTHING;
} else
#endif
if (time(nullptr) > startTime + IDLE_TIMEOUT)
@@ -128,7 +128,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command)
bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity."
<< endl;
session.setState(Session::LOGOUT);
- return NOTHING;
+ return Operator::ProcessResult::NOTHING;
}
}
@@ -181,7 +181,7 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command)
close(newfd);
close(curfd);
#endif
- return NO;
+ return Operator::ProcessResult::NO;
}
#ifdef HAVE_FNOTIFY
@@ -211,21 +211,21 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command)
close(newfd);
close(curfd);
#endif
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult IdleOperator::parse(Request &c_in) const
+Parser::ParseResult IdleOperator::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 after IDLE");
return res;
}
c_in.setName("IDLE");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-list.cc b/src/operator-list.cc
index 25934fa..519eb79 100644
--- a/src/operator-list.cc
+++ b/src/operator-list.cc
@@ -39,9 +39,9 @@ const string ListOperator::getName() const
return "LIST";
}
-int ListOperator::getState() const
+Session::State ListOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult ListOperator::process(Depot &depot, Request &command)
@@ -54,7 +54,7 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command)
string wildcard;
if ((wildcard = command.getListMailbox()) == "") {
bincClient << "* LIST (\\Noselect) \"" << delim << "\" \"\"" << std::endl;
- return OK;
+ return Operator::ProcessResult::OK;
}
// remove leading or trailing delimiter in wildcard
@@ -196,16 +196,18 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command)
}
}
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult ListOperator::parse(Request &c_in) const
+Parser::ParseResult ListOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after LIST");
return res;
diff --git a/src/operator-login.cc b/src/operator-login.cc
index db091aa..cef8acb 100644
--- a/src/operator-login.cc
+++ b/src/operator-login.cc
@@ -34,7 +34,7 @@ const std::string LoginOperator::getName() const
return "LOGIN";
}
-int LoginOperator::getState() const
+Session::State LoginOperator::getState() const
{
return Session::NONAUTHENTICATED;
}
@@ -46,7 +46,7 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command)
if (!session.command.ssl && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
session.setLastError("Plain text password authentication is disallowd. "
"Please enable StartTLS or TLS in your mail client.");
- return NO;
+ return Operator::ProcessResult::NO;
}
session.setEnv("BINCIMAP_LOGIN", "LOGIN+" + command.getTag());
@@ -57,13 +57,13 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command)
session.setLastError("An internal error occurred when you attempted "
"to log in to the IMAP server. Please contact "
"your system administrator.");
- return NO;
+ return Operator::ProcessResult::NO;
case 2:
session.setLastError("Login failed. Either your user name "
"or your password was wrong. Please try again, "
"and if the problem persists, please contact "
"your system administrator.");
- return NO;
+ return Operator::ProcessResult::NO;
case 3:
bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity."
<< std::endl;
@@ -78,16 +78,18 @@ Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command)
// go to logout
session.setState(Session::LOGOUT);
- return NOTHING;
+ return Operator::ProcessResult::NOTHING;
}
-Operator::ParseResult LoginOperator::parse(Request &c_in) const
+Parser::ParseResult LoginOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected single SPACE after LOGIN");
return res;
diff --git a/src/operator-logout.cc b/src/operator-logout.cc
index af40b72..d58972b 100644
--- a/src/operator-logout.cc
+++ b/src/operator-logout.cc
@@ -28,9 +28,10 @@ const std::string LogoutOperator::getName() const
return "LOGOUT";
}
-int LogoutOperator::getState() const
+Session::State LogoutOperator::getState() const
{
- return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED
+ | Session::SELECTED);
}
Operator::ProcessResult LogoutOperator::process(Depot &depot, Request &command)
@@ -50,21 +51,21 @@ Operator::ProcessResult LogoutOperator::process(Depot &depot, Request &command)
Session &session = Session::getInstance();
session.setState(Session::LOGOUT);
- return NOTHING;
+ return Operator::ProcessResult::NOTHING;
}
-Operator::ParseResult LogoutOperator::parse(Request &c_in) const
+Parser::ParseResult LogoutOperator::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("LOGOUT");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-lsub.cc b/src/operator-lsub.cc
index 375ffcc..c4d1908 100644
--- a/src/operator-lsub.cc
+++ b/src/operator-lsub.cc
@@ -40,9 +40,9 @@ const string LsubOperator::getName() const
return "LSUB";
}
-int LsubOperator::getState() const
+Session::State LsubOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command)
@@ -179,16 +179,20 @@ Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command)
}
}
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult LsubOperator::parse(Request &c_in) const
+Parser::ParseResult LsubOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+ constexpr auto ERROR = Parser::ParseResult::ERROR;
+ constexpr auto REJECT = Parser::ParseResult::REJECT;
+
Session &session = Session::getInstance();
if (c_in.getUidMode()) return REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after LSUB");
return ERROR;
diff --git a/src/operator-namespace.cc b/src/operator-namespace.cc
index a331420..6bf80f4 100644
--- a/src/operator-namespace.cc
+++ b/src/operator-namespace.cc
@@ -26,9 +26,9 @@ const std::string NamespaceOperator::getName() const
return "NAMESPACE";
}
-int NamespaceOperator::getState() const
+Session::State NamespaceOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult NamespaceOperator::process(Depot &depot, Request &command)
@@ -46,22 +46,22 @@ Operator::ProcessResult NamespaceOperator::process(Depot &depot, Request &comman
bincClient << " NIL"; // shared namespaces
bincClient << std::endl;
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult NamespaceOperator::parse(Request &c_in) const
+Parser::ParseResult NamespaceOperator::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 after NAMESPACE");
return res;
}
c_in.setName("NAMESPACE");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-noop-pending.cc b/src/operator-noop-pending.cc
index 9104275..d9ea952 100644
--- a/src/operator-noop-pending.cc
+++ b/src/operator-noop-pending.cc
@@ -31,5 +31,5 @@ Operator::ProcessResult NoopPendingOperator::process(Depot &depot, Request &comm
true);
}
- return OK;
+ return Operator::ProcessResult::OK;
}
diff --git a/src/operator-noop.cc b/src/operator-noop.cc
index 77d2d9d..9d72e8f 100644
--- a/src/operator-noop.cc
+++ b/src/operator-noop.cc
@@ -24,29 +24,30 @@ const std::string NoopOperator::getName() const
return "NOOP";
}
-int NoopOperator::getState() const
+Session::State NoopOperator::getState() const
{
- return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED
+ | Session::SELECTED);
}
Operator::ProcessResult NoopOperator::process(Depot &depot, Request &command)
{
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult NoopOperator::parse(Request &c_in) const
+Parser::ParseResult NoopOperator::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 after NOOP");
return res;
}
c_in.setName("NOOP");
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-rename.cc b/src/operator-rename.cc
index c6c01f6..b8298f8 100644
--- a/src/operator-rename.cc
+++ b/src/operator-rename.cc
@@ -29,9 +29,9 @@ const string RenameOperator::getName() const
return "RENAME";
}
-int RenameOperator::getState() const
+Session::State RenameOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult RenameOperator::process(Depot &depot, Request &command)
@@ -48,27 +48,29 @@ Operator::ProcessResult RenameOperator::process(Depot &depot, Request &command)
session.setLastError("Sorry, renaming INBOX is not yet supported"
" by this IMAP server. Try copying the messages"
" instead");
- return NO;
+ return Operator::ProcessResult::NO;
}
if (canondestmailbox == "INBOX") {
session.setLastError("It is not allowed to rename a mailbox to INBOX");
- return NO;
+ return Operator::ProcessResult::NO;
}
if (depot.renameMailbox(canonmailbox, canondestmailbox))
- return OK;
+ return Operator::ProcessResult::OK;
else
- return NO;
+ return Operator::ProcessResult::NO;
}
-Operator::ParseResult RenameOperator::parse(Request &c_in) const
+Parser::ParseResult RenameOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after RENAME");
return res;
diff --git a/src/operator-search.cc b/src/operator-search.cc
index c013e70..1da4ee7 100644
--- a/src/operator-search.cc
+++ b/src/operator-search.cc
@@ -485,7 +485,7 @@ const string SearchOperator::getName() const
return "SEARCH";
}
-int SearchOperator::getState() const
+Session::State SearchOperator::getState() const
{
return Session::SELECTED;
}
@@ -499,7 +499,7 @@ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command)
if (command.getCharSet() != "" && command.getCharSet() != "US-ASCII") {
session.setLastError("The " + command.getCharSet() + " charset is not supported");
session.setResponseCode("[BADCHARSET (\"US-ASCII\")]");
- return NO;
+ return Operator::ProcessResult::NO;
}
bincClient << "* SEARCH";
@@ -524,14 +524,16 @@ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command)
}
bincClient << endl;
- return OK;
+ return Operator::ProcessResult::OK;
}
-Operator::ParseResult SearchOperator::parse(Request &c_in) const
+Parser::ParseResult SearchOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
return res;
@@ -587,10 +589,12 @@ Operator::ParseResult SearchOperator::parse(Request &c_in) const
return ACCEPT;
}
-Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
+Parser::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
s_in.type = BincImapParserSearchKey::KEY_OTHER;
if ((res = expectThisString("ALL")) == ACCEPT) {
@@ -913,7 +917,7 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
return res;
}
} else {
- return REJECT;
+ return Parser::ParseResult::REJECT;
}
return ACCEPT;
diff --git a/src/operator-select.cc b/src/operator-select.cc
index de16e5e..5d30bbd 100644
--- a/src/operator-select.cc
+++ b/src/operator-select.cc
@@ -30,9 +30,10 @@ const string SelectOperator::getName() const
return "SELECT";
}
-int SelectOperator::getState() const
+Session::State SelectOperator::getState() const
{
- return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::NONAUTHENTICATED | Session::AUTHENTICATED
+ | Session::SELECTED);
}
Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
@@ -53,7 +54,7 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
mailbox = depot.get(canonmailbox);
if (mailbox == nullptr) {
session.setLastError(depot.getLastError());
- return NO;
+ return ProcessResult::NO;
}
mailbox->setReadOnly(examine);
@@ -61,7 +62,7 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
if (!mailbox->selectMailbox(canonmailbox, depot.mailboxToFilename(canonmailbox))) {
bincWarning << "selecting mailbox failed: " << mailbox->getLastError() << endl;
session.setLastError(mailbox->getLastError());
- return NO;
+ return ProcessResult::NO;
}
// find first unseen
@@ -94,8 +95,8 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
// uidnext
bincClient << "*"
- << " OK [UIDNEXT " << toString(mailbox->getUidNext()) << "] "
- << toString(mailbox->getUidNext()) << " is the next UID" << endl;
+ << " OK [UIDNEXT " << std::to_string(mailbox->getUidNext()) << "] "
+ << std::to_string(mailbox->getUidNext()) << " is the next UID" << endl;
// flags
bincClient << "*"
@@ -110,16 +111,18 @@ Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
depot.setSelected(mailbox);
session.setResponseCode(examine ? "READ-ONLY" : "READ-WRITE");
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult SelectOperator::parse(Request &c_in) const
+Parser::ParseResult SelectOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after" + c_in.getName());
return res;
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;
}
diff --git a/src/operator-status.cc b/src/operator-status.cc
index 0cc5341..da37a55 100644
--- a/src/operator-status.cc
+++ b/src/operator-status.cc
@@ -33,9 +33,9 @@ const std::string StatusOperator::getName() const
return "STATUS";
}
-int StatusOperator::getState() const
+Session::State StatusOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command)
@@ -45,7 +45,7 @@ Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command)
Status status;
if (!depot.getStatus(command.getMailbox(), status)) {
session.setLastError(depot.getLastError());
- return NO;
+ return ProcessResult::NO;
}
bincClient << "* STATUS " << toImapString(command.getMailbox()) << " (";
@@ -72,16 +72,18 @@ Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command)
}
bincClient << ")" << std::endl;
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult StatusOperator::parse(Request &c_in) const
+Parser::ParseResult StatusOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- if (c_in.getUidMode()) return REJECT;
+ if (c_in.getUidMode()) return Parser::ParseResult::REJECT;
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
return res;
@@ -131,7 +133,7 @@ Operator::ParseResult StatusOperator::parse(Request &c_in) const
if ((res = expectCRLF()) != ACCEPT) {
session.setLastError("Expected CRLF");
- return ERROR;
+ return Parser::ParseResult::ERROR;
}
return ACCEPT;
diff --git a/src/operator-store.cc b/src/operator-store.cc
index 4c5b9d4..23d97e2 100644
--- a/src/operator-store.cc
+++ b/src/operator-store.cc
@@ -29,7 +29,7 @@ const string StoreOperator::getName() const
return "STORE";
}
-int StoreOperator::getState() const
+Session::State StoreOperator::getState() const
{
return Session::SELECTED;
}
@@ -117,14 +117,16 @@ Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command)
command.getUidMode());
}
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult StoreOperator::parse(Request &c_in) const
+Parser::ParseResult StoreOperator::parse(Request &c_in)
{
+ constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ Parser::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
return res;
diff --git a/src/operator-subscribe.cc b/src/operator-subscribe.cc
index b05590b..3209986 100644
--- a/src/operator-subscribe.cc
+++ b/src/operator-subscribe.cc
@@ -28,9 +28,9 @@ const string SubscribeOperator::getName() const
return "SUBSCRIBE";
}
-int SubscribeOperator::getState() const
+Session::State SubscribeOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult SubscribeOperator::process(Depot &depot, Request &command)
@@ -42,32 +42,32 @@ Operator::ProcessResult SubscribeOperator::process(Depot &depot, Request &comman
depot.subscribeTo(canonmailbox);
depot.saveSubscribes();
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult SubscribeOperator::parse(Request &c_in) const
+Parser::ParseResult SubscribeOperator::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 = expectSPACE()) != ACCEPT) {
+ Parser::ParseResult res;
+ if ((res = expectSPACE()) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected SPACE");
return res;
}
string mailbox;
- if ((res = expectMailbox(mailbox)) != ACCEPT) {
+ if ((res = expectMailbox(mailbox)) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected mailbox");
return res;
}
c_in.setMailbox(mailbox);
- if ((res = expectCRLF()) != ACCEPT) {
+ if ((res = expectCRLF()) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected CRLF");
return res;
}
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/operator-unsubscribe.cc b/src/operator-unsubscribe.cc
index 34b12a0..cafa10a 100644
--- a/src/operator-unsubscribe.cc
+++ b/src/operator-unsubscribe.cc
@@ -29,9 +29,9 @@ const string UnsubscribeOperator::getName() const
return "UNSUBSCRIBE";
}
-int UnsubscribeOperator::getState() const
+Session::State UnsubscribeOperator::getState() const
{
- return Session::AUTHENTICATED | Session::SELECTED;
+ return Session::State(Session::AUTHENTICATED | Session::SELECTED);
}
Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, Request &command)
@@ -43,38 +43,38 @@ Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, Request &comm
if (!depot.unsubscribeTo(canonmailbox)) {
Session &session = Session::getInstance();
session.setLastError("Not subscribed to " + toImapString(mailbox));
- return NO;
+ return ProcessResult::NO;
}
depot.saveSubscribes();
- return OK;
+ return ProcessResult::OK;
}
-Operator::ParseResult UnsubscribeOperator::parse(Request &c_in) const
+Parser::ParseResult UnsubscribeOperator::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 = expectSPACE()) != ACCEPT) {
+ Parser::ParseResult res;
+ if ((res = expectSPACE()) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected SPACE");
return res;
}
string mailbox;
- if ((res = expectMailbox(mailbox)) != ACCEPT) {
+ if ((res = expectMailbox(mailbox)) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected mailbox");
return res;
}
- if ((res = expectCRLF()) != ACCEPT) {
+ if ((res = expectCRLF()) != Parser::ParseResult::ACCEPT) {
session.setLastError("Expected CRLF");
return res;
}
c_in.setMailbox(mailbox);
- return ACCEPT;
+ return Parser::ParseResult::ACCEPT;
}
diff --git a/src/recursivedescent.cc b/src/recursivedescent.cc
index 68cd0e0..b734779 100644
--- a/src/recursivedescent.cc
+++ b/src/recursivedescent.cc
@@ -1,8 +1,8 @@
/**
- * @file recursivedescent.cc
- * @brief Implementation of a recursive descent IMAP command parser.
- * @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @file recursivedescent.cc
+ * @brief Implementation of a recursive descent IMAP command parser.
+ * @author Andreas Aardal Hanssen
+ * @date 2002-2005
*/
#include "recursivedescent.h"
@@ -11,39 +11,39 @@
#include "imapparser.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "operators.h"
#include "session.h"
+#include <cctype>
#include <iomanip>
#include <iostream>
#include <stack>
-#include <ctype.h>
-#include <stdio.h>
-
using namespace Binc;
using std::string;
+using ParseResult = Binc::Parser::ParseResult;
-std::stack<int> Binc::inputBuffer;
-int Binc::charnr = 0;
+constexpr auto ERROR = Parser::ParseResult::ERROR;
+constexpr auto REJECT = Parser::ParseResult::REJECT;
+constexpr auto ACCEPT = Parser::ParseResult::ACCEPT;
+constexpr auto TIMEOUT = Parser::ParseResult::TIMEOUT;
-Operator::ParseResult Binc::expectThisString(const string &s_in)
+ParseResult Binc::expectThisString(const string &s_in)
{
Session &session = Session::getInstance();
- string tmp;
+ char c;
bool match = true;
for (string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
- char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout)
+ return Parser::ParseResult::TIMEOUT;
+ return ERROR;
}
- tmp += c;
-
if (toupper(*i) != toupper(c)) {
match = false;
break;
@@ -51,34 +51,34 @@ Operator::ParseResult Binc::expectThisString(const string &s_in)
}
if (!match) {
- bincClient.unreadStr(tmp);
- return Operator::REJECT;
+ bincClient.unreadChar(c);
+ return REJECT;
} else {
- return Operator::ACCEPT;
+ return ACCEPT;
}
}
-Operator::ParseResult Binc::expectDateTime(string &s_in)
+ParseResult Binc::expectDateTime(string &s_in)
{
Session &session = Session::getInstance();
- if (expectThisString("\"") != Operator::ACCEPT) return Operator::REJECT;
+ if (expectThisString("\"") != ACCEPT) return REJECT;
unsigned int digit1, digit2;
- if (expectSPACE() == Operator::ACCEPT) {
+ if (expectSPACE() == ACCEPT) {
digit1 = 0;
- Operator::ParseResult res;
- if ((res = expectDigit(digit2)) != Operator::ACCEPT) {
+ ParseResult res;
+ if ((res = expectDigit(digit2)) != ACCEPT) {
session.setLastError("expected digit (day) after \" and a SPACE.");
return res;
}
} else {
- Operator::ParseResult res;
- if ((res = expectDigit(digit1)) != Operator::ACCEPT) {
+ ParseResult res;
+ if ((res = expectDigit(digit1)) != ACCEPT) {
session.setLastError("expected first digit of day");
return res;
}
- if ((res = expectDigit(digit2)) != Operator::ACCEPT) {
+ if ((res = expectDigit(digit2)) != ACCEPT) {
session.setLastError("expected second digit of day");
return res;
}
@@ -93,8 +93,8 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
s_in += daystr.str();
- Operator::ParseResult res;
- if ((res = expectThisString("-")) != Operator::ACCEPT) {
+ ParseResult res;
+ if ((res = expectThisString("-")) != ACCEPT) {
session.setLastError("expected -");
return res;
}
@@ -102,36 +102,36 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
s_in += "-";
/* month */
- if ((res = expectThisString("Jan")) == Operator::ACCEPT) {
+ if ((res = expectThisString("Jan")) == ACCEPT) {
s_in += "Jan";
- } else if ((res = expectThisString("Feb")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Feb")) == ACCEPT) {
s_in += "Feb";
- } else if ((res = expectThisString("Mar")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Mar")) == ACCEPT) {
s_in += "Mar";
- } else if ((res = expectThisString("Apr")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Apr")) == ACCEPT) {
s_in += "Apr";
- } else if ((res = expectThisString("May")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("May")) == ACCEPT) {
s_in += "May";
- } else if ((res = expectThisString("Jun")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Jun")) == ACCEPT) {
s_in += "Jun";
- } else if ((res = expectThisString("Jul")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Jul")) == ACCEPT) {
s_in += "Jul";
- } else if ((res = expectThisString("Aug")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Aug")) == ACCEPT) {
s_in += "Aug";
- } else if ((res = expectThisString("Sep")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Sep")) == ACCEPT) {
s_in += "Sep";
- } else if ((res = expectThisString("Oct")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Oct")) == ACCEPT) {
s_in += "Oct";
- } else if ((res = expectThisString("Nov")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Nov")) == ACCEPT) {
s_in += "Nov";
- } else if ((res = expectThisString("Dec")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Dec")) == ACCEPT) {
s_in += "Dec";
} else {
session.setLastError("expected month");
return res;
}
- if ((res = expectThisString("-")) != Operator::ACCEPT) {
+ if ((res = expectThisString("-")) != ACCEPT) {
session.setLastError("expected -");
return res;
}
@@ -140,26 +140,26 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
/* year */
unsigned int year, c;
- if ((res = expectDigit(year)) != Operator::ACCEPT) {
+ if ((res = expectDigit(year)) != ACCEPT) {
session.setLastError("expected digit (first digit of year)");
return res;
}
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit (second digit of year)");
return res;
}
year = (year * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit (third digit of year)");
return res;
}
year = (year * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit (last digit of year)");
return res;
}
@@ -172,47 +172,47 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
s_in += yearstr.str();
- if ((res = expectSPACE()) != Operator::ACCEPT) {
+ if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("expected SPACE");
return res;
}
s_in += " ";
- if ((res = expectTime(s_in)) != Operator::ACCEPT) {
+ if ((res = expectTime(s_in)) != ACCEPT) {
session.setLastError("expected time");
return res;
}
- if ((res = expectSPACE()) != Operator::ACCEPT) {
+ if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("expected SPACE");
return res;
}
s_in += " ";
- if ((res = expectZone(s_in)) != Operator::ACCEPT) {
+ if ((res = expectZone(s_in)) != ACCEPT) {
session.setLastError("expected zone");
return res;
}
- if ((res = expectThisString("\"")) != Operator::ACCEPT) {
+ if ((res = expectThisString("\"")) != ACCEPT) {
session.setLastError("expected \"");
return res;
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectTime(string &s_in)
+ParseResult Binc::expectTime(string &s_in)
{
Session &session = Session::getInstance();
unsigned int c, t;
- Operator::ParseResult res;
- if ((res = expectDigit(t)) != Operator::ACCEPT) return res;
+ ParseResult res;
+ if ((res = expectDigit(t)) != ACCEPT) return res;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
@@ -225,19 +225,19 @@ Operator::ParseResult Binc::expectTime(string &s_in)
s_in += tstr.str();
- if ((res = expectThisString(":")) != Operator::ACCEPT) {
+ if ((res = expectThisString(":")) != ACCEPT) {
session.setLastError("expected colon");
return res;
}
s_in += ":";
- if ((res = expectDigit(t)) != Operator::ACCEPT) {
+ if ((res = expectDigit(t)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
@@ -250,19 +250,19 @@ Operator::ParseResult Binc::expectTime(string &s_in)
s_in += tstr.str();
- if ((res = expectThisString(":")) != Operator::ACCEPT) {
+ if ((res = expectThisString(":")) != ACCEPT) {
session.setLastError("expected colon");
return res;
}
s_in += ":";
- if ((res = expectDigit(t)) != Operator::ACCEPT) {
+ if ((res = expectDigit(t)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
@@ -275,42 +275,42 @@ Operator::ParseResult Binc::expectTime(string &s_in)
s_in += tstr.str();
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectZone(string &s_in)
+ParseResult Binc::expectZone(string &s_in)
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
- if ((res = expectThisString("-")) == Operator::ACCEPT)
+ ParseResult res;
+ if ((res = expectThisString("-")) == ACCEPT)
s_in += "-";
- else if ((res = expectThisString("+")) == Operator::ACCEPT)
+ else if ((res = expectThisString("+")) == ACCEPT)
s_in += "+";
else
return res;
unsigned int c, t;
- if ((res = expectDigit(t)) != Operator::ACCEPT) {
+ if ((res = expectDigit(t)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
t = (t * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
t = (t * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
@@ -323,40 +323,38 @@ Operator::ParseResult Binc::expectZone(string &s_in)
s_in += tstr.str();
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectListWildcards(int &c_in)
+ParseResult Binc::expectListWildcards(int &c_in)
{
- Operator::ParseResult res;
- if ((res = expectThisString("%")) == Operator::ACCEPT) {
+ ParseResult res;
+ if ((res = expectThisString("%")) == ACCEPT) {
c_in = '%';
- return Operator::ACCEPT;
- } else if ((res = expectThisString("*")) == Operator::ACCEPT) {
+ return ACCEPT;
+ } else if ((res = expectThisString("*")) == ACCEPT) {
c_in = '*';
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
return res;
}
}
-Operator::ParseResult Binc::expectListMailbox(string &s_in)
+ParseResult Binc::expectListMailbox(string &s_in)
{
- Operator::ParseResult res;
- if ((res = expectString(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+ ParseResult res;
+ if ((res = expectString(s_in)) == ACCEPT) return ACCEPT;
int c;
- if ((res = expectAtomChar(c)) == Operator::ACCEPT
- || (res = expectListWildcards(c)) == Operator::ACCEPT
- || (res = expectThisString("]")) == Operator::ACCEPT)
+ if ((res = expectAtomChar(c)) == ACCEPT || (res = expectListWildcards(c)) == ACCEPT
+ || (res = expectThisString("]")) == ACCEPT)
{
do {
s_in += (char)c;
- if ((res = expectAtomChar(c)) != Operator::ACCEPT
- && (res = expectListWildcards(c)) != Operator::ACCEPT
- && (res = expectThisString("]")) != Operator::ACCEPT)
+ if ((res = expectAtomChar(c)) != ACCEPT && (res = expectListWildcards(c)) != ACCEPT
+ && (res = expectThisString("]")) != ACCEPT)
{
- return Operator::ACCEPT;
+ return ACCEPT;
}
} while (1);
}
@@ -366,54 +364,54 @@ Operator::ParseResult Binc::expectListMailbox(string &s_in)
return res;
}
-Operator::ParseResult Binc::expectFlag(std::vector<string> &v_in)
+ParseResult Binc::expectFlag(std::vector<string> &v_in)
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ ParseResult res;
string flag;
- if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) {
+ if ((res = expectThisString("\\Answered")) == ACCEPT) {
v_in.push_back("\\Answered");
- } else if ((res = expectThisString("\\Flagged")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\Flagged")) == ACCEPT) {
v_in.push_back("\\Flagged");
- } else if ((res = expectThisString("\\Deleted")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\Deleted")) == ACCEPT) {
v_in.push_back("\\Deleted");
- } else if ((res = expectThisString("\\Seen")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\Seen")) == ACCEPT) {
v_in.push_back("\\Seen");
- } else if ((res = expectThisString("\\Draft")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\Draft")) == ACCEPT) {
v_in.push_back("\\Draft");
- } else if ((res = expectThisString("\\Answered")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\Answered")) == ACCEPT) {
v_in.push_back("\\Answered");
- } else if ((res = expectThisString("\\")) == Operator::ACCEPT) {
- if ((res = expectAtom(flag)) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("\\")) == ACCEPT) {
+ if ((res = expectAtom(flag)) == ACCEPT) {
v_in.push_back("\\" + flag);
} else {
session.setLastError("expected atom");
return res;
}
- } else if (expectAtom(flag) == Operator::ACCEPT) {
+ } else if (expectAtom(flag) == ACCEPT) {
v_in.push_back(flag);
} else {
return res;
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectDate(string &s_in)
+ParseResult Binc::expectDate(string &s_in)
{
Session &session = Session::getInstance();
- Operator::ParseResult res;
+ ParseResult res;
bool quoted = false;
- if ((res = expectThisString("\"")) == Operator::ACCEPT) quoted = true;
+ if ((res = expectThisString("\"")) == ACCEPT) quoted = true;
/* day */
unsigned int day, c;
- if ((res = expectDigit(c)) == Operator::ACCEPT) {
+ if ((res = expectDigit(c)) == ACCEPT) {
day = c;
- if ((res = expectDigit(c)) == Operator::ACCEPT) day = (day * 10) + c;
+ if ((res = expectDigit(c)) == ACCEPT) day = (day * 10) + c;
BincStream daystr;
@@ -426,7 +424,7 @@ Operator::ParseResult Binc::expectDate(string &s_in)
}
/* - */
- if ((res = expectThisString("-")) != Operator::ACCEPT) {
+ if ((res = expectThisString("-")) != ACCEPT) {
session.setLastError("expected -");
return res;
}
@@ -434,29 +432,29 @@ Operator::ParseResult Binc::expectDate(string &s_in)
s_in += '-';
/* month */
- if ((res = expectThisString("Jan")) == Operator::ACCEPT) {
+ if ((res = expectThisString("Jan")) == ACCEPT) {
s_in += "Jan";
- } else if ((res = expectThisString("Feb")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Feb")) == ACCEPT) {
s_in += "Feb";
- } else if ((res = expectThisString("Mar")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Mar")) == ACCEPT) {
s_in += "Mar";
- } else if ((res = expectThisString("Apr")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Apr")) == ACCEPT) {
s_in += "Apr";
- } else if ((res = expectThisString("May")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("May")) == ACCEPT) {
s_in += "May";
- } else if ((res = expectThisString("Jun")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Jun")) == ACCEPT) {
s_in += "Jun";
- } else if ((res = expectThisString("Jul")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Jul")) == ACCEPT) {
s_in += "Jul";
- } else if ((res = expectThisString("Aug")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Aug")) == ACCEPT) {
s_in += "Aug";
- } else if ((res = expectThisString("Sep")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Sep")) == ACCEPT) {
s_in += "Sep";
- } else if ((res = expectThisString("Oct")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Oct")) == ACCEPT) {
s_in += "Oct";
- } else if ((res = expectThisString("Nov")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Nov")) == ACCEPT) {
s_in += "Nov";
- } else if ((res = expectThisString("Dec")) == Operator::ACCEPT) {
+ } else if ((res = expectThisString("Dec")) == ACCEPT) {
s_in += "Dec";
} else {
session.setLastError("expected month");
@@ -464,7 +462,7 @@ Operator::ParseResult Binc::expectDate(string &s_in)
}
/* - */
- if ((res = expectThisString("-")) != Operator::ACCEPT) {
+ if ((res = expectThisString("-")) != ACCEPT) {
session.setLastError("expected -");
return res;
}
@@ -473,26 +471,26 @@ Operator::ParseResult Binc::expectDate(string &s_in)
/* year */
unsigned int year;
- if ((res = expectDigit(year)) != Operator::ACCEPT) {
+ if ((res = expectDigit(year)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
year = (year * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
year = (year * 10) + c;
- if ((res = expectDigit(c)) != Operator::ACCEPT) {
+ if ((res = expectDigit(c)) != ACCEPT) {
session.setLastError("expected digit");
return res;
}
@@ -506,25 +504,25 @@ Operator::ParseResult Binc::expectDate(string &s_in)
s_in += yearstr.str();
if (quoted) {
- if ((res = expectThisString("\"")) != Operator::ACCEPT) {
+ if ((res = expectThisString("\"")) != ACCEPT) {
session.setLastError("expected \"");
return res;
}
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectCRLF()
+ParseResult Binc::expectCRLF()
{
- Operator::ParseResult res;
- if ((res = expectCR()) == Operator::ACCEPT && (res = expectLF()) == Operator::ACCEPT)
- return Operator::ACCEPT;
+ ParseResult res;
+ if ((res = expectCR()) == ACCEPT && (res = expectLF()) == ACCEPT)
+ return ACCEPT;
else
return res;
}
-Operator::ParseResult Binc::expectCR()
+ParseResult Binc::expectCR()
{
Session &session = Session::getInstance();
@@ -532,19 +530,19 @@ Operator::ParseResult Binc::expectCR()
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (c == 0x0d) {
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
}
-Operator::ParseResult Binc::expectLF()
+ParseResult Binc::expectLF()
{
Session &session = Session::getInstance();
@@ -552,19 +550,19 @@ Operator::ParseResult Binc::expectLF()
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (c == 0x0a) {
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
}
-Operator::ParseResult Binc::expectTagChar(int &c_in)
+ParseResult Binc::expectTagChar(int &c_in)
{
Session &session = Session::getInstance();
@@ -572,8 +570,8 @@ Operator::ParseResult Binc::expectTagChar(int &c_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
switch (c) {
@@ -664,28 +662,28 @@ Operator::ParseResult Binc::expectTagChar(int &c_in)
case 0175:
case 0176:
c_in = c;
- return Operator::ACCEPT;
+ return ACCEPT;
default:
break;
}
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
-Operator::ParseResult Binc::expectTag(string &s_in)
+ParseResult Binc::expectTag(string &s_in)
{
string tag;
int tagchar;
- int eres = expectTagChar(tagchar);
- if (eres == Operator::REJECT) {
- return Operator::REJECT;
- } else if (eres == Operator::ERROR) {
- return Operator::ERROR;
- } else if (eres == Operator::TIMEOUT) {
- return Operator::TIMEOUT;
+ ParseResult eres = expectTagChar(tagchar);
+ if (eres == REJECT) {
+ return REJECT;
+ } else if (eres == ERROR) {
+ return ERROR;
+ } else if (eres == TIMEOUT) {
+ return TIMEOUT;
} else {
tag += tagchar;
@@ -693,26 +691,26 @@ Operator::ParseResult Binc::expectTag(string &s_in)
while (!done) {
switch (expectTagChar(tagchar)) {
- case Operator::ACCEPT:
+ case ACCEPT:
tag += tagchar;
break;
- case Operator::REJECT:
+ case REJECT:
done = true;
break;
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case ERROR:
+ return ERROR;
+ case TIMEOUT:
+ return TIMEOUT;
}
}
}
s_in = tag;
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectSPACE()
+ParseResult Binc::expectSPACE()
{
Session &session = Session::getInstance();
@@ -720,35 +718,35 @@ Operator::ParseResult Binc::expectSPACE()
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (c == ' ') {
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
}
-Operator::ParseResult Binc::expectMailbox(string &s_in)
+ParseResult Binc::expectMailbox(string &s_in)
{
return expectAstring(s_in);
}
// FIXME: This rule is wrong.
-Operator::ParseResult Binc::expectAstring(string &s_in)
+ParseResult Binc::expectAstring(string &s_in)
{
- Operator::ParseResult res;
- if ((res = expectAtom(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+ ParseResult res;
+ if ((res = expectAtom(s_in)) == ACCEPT) return ACCEPT;
- if ((res = expectString(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+ if ((res = expectString(s_in)) == ACCEPT) return ACCEPT;
return res;
}
-Operator::ParseResult Binc::expectAtomChar(int &c_in)
+ParseResult Binc::expectAtomChar(int &c_in)
{
Session &session = Session::getInstance();
@@ -756,8 +754,8 @@ Operator::ParseResult Binc::expectAtomChar(int &c_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
switch (c) {
@@ -849,22 +847,22 @@ Operator::ParseResult Binc::expectAtomChar(int &c_in)
case 0175:
case 0176:
c_in = c;
- return Operator::ACCEPT;
+ return ACCEPT;
default:
break;
}
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
-Operator::ParseResult Binc::expectAtom(string &s_in)
+ParseResult Binc::expectAtom(string &s_in)
{
string atom;
int atomchar;
- Operator::ParseResult res;
- while ((res = expectAtomChar(atomchar)) == Operator::ACCEPT)
+ ParseResult res;
+ while ((res = expectAtomChar(atomchar)) == ACCEPT)
atom += atomchar;
if (atom == "") {
@@ -874,40 +872,40 @@ Operator::ParseResult Binc::expectAtom(string &s_in)
s_in = atom;
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectString(string &s_in)
+ParseResult Binc::expectString(string &s_in)
{
- Operator::ParseResult res;
- if ((res = expectQuoted(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+ ParseResult res;
+ if ((res = expectQuoted(s_in)) == ACCEPT) return ACCEPT;
- if ((res = expectLiteral(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+ if ((res = expectLiteral(s_in)) == ACCEPT) return ACCEPT;
return res;
}
-Operator::ParseResult Binc::expectQuoted(string &s_in)
+ParseResult Binc::expectQuoted(string &s_in)
{
string quoted;
int quotedchar;
- Operator::ParseResult res;
+ ParseResult res;
- if ((res = expectThisString("\"")) != Operator::ACCEPT) return res;
+ if ((res = expectThisString("\"")) != ACCEPT) return res;
- while ((res = expectQuotedChar(quotedchar)) == Operator::ACCEPT)
+ while ((res = expectQuotedChar(quotedchar)) == ACCEPT)
quoted += quotedchar;
- if ((res = expectThisString("\"")) != Operator::ACCEPT) {
+ if ((res = expectThisString("\"")) != ACCEPT) {
bincClient.unreadStr("\"" + quoted);
return res;
}
s_in = quoted;
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectQuotedChar(int &c_in)
+ParseResult Binc::expectQuotedChar(int &c_in)
{
Session &session = Session::getInstance();
@@ -915,8 +913,8 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
switch (c) {
@@ -1044,23 +1042,23 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in)
case 0176:
case 0177:
c_in = c;
- return Operator::ACCEPT;
+ return ACCEPT;
case '\\': {
char d;
if (!bincClient.readChar(&d)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (d == '\"' || d == '\\') {
c_in = d;
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(d);
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
}
default:
@@ -1068,21 +1066,21 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in)
}
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
-Operator::ParseResult Binc::expectLiteral(string &s_in)
+ParseResult Binc::expectLiteral(string &s_in)
{
Session &session = Session::getInstance();
string literal;
- Operator::ParseResult res;
+ ParseResult res;
- if ((res = expectThisString("{")) != Operator::ACCEPT) return res;
+ if ((res = expectThisString("{")) != ACCEPT) return res;
unsigned int nchar;
- if ((res = expectNumber(nchar)) != Operator::ACCEPT) {
+ if ((res = expectNumber(nchar)) != ACCEPT) {
session.setLastError("expected number");
return res;
}
@@ -1091,16 +1089,16 @@ Operator::ParseResult Binc::expectLiteral(string &s_in)
// sent by the client with an extra '+' appended after the octet
// count.
bool literalPlus = false;
- if ((res = expectThisString("+")) == Operator::ACCEPT) literalPlus = true;
+ if ((res = expectThisString("+")) == ACCEPT) literalPlus = true;
- if ((res = expectThisString("}")) != Operator::ACCEPT) {
+ if ((res = expectThisString("}")) != ACCEPT) {
session.setLastError("expected }");
return res;
}
- if ((res = expectCRLF()) != Operator::ACCEPT) {
+ if ((res = expectCRLF()) != ACCEPT) {
session.setLastError("expected CRLF");
- return Operator::ERROR;
+ return ERROR;
}
// Only send the reply if the client did not send a LITERAL+
@@ -1114,8 +1112,8 @@ Operator::ParseResult Binc::expectLiteral(string &s_in)
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
literal += c;
@@ -1123,27 +1121,27 @@ Operator::ParseResult Binc::expectLiteral(string &s_in)
s_in = literal;
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectNumber(unsigned int &i_in)
+ParseResult Binc::expectNumber(unsigned int &i_in)
{
i_in = 0;
unsigned int n;
- Operator::ParseResult res;
+ ParseResult res;
- while ((res = expectDigit(n)) == Operator::ACCEPT)
+ while ((res = expectDigit(n)) == ACCEPT)
if (i_in == 0)
i_in = n;
else
i_in = (i_in * 10) + n;
- if (res == Operator::TIMEOUT) return res;
+ if (res == TIMEOUT) return res;
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectDigit(unsigned int &i_in)
+ParseResult Binc::expectDigit(unsigned int &i_in)
{
Session &session = Session::getInstance();
@@ -1151,23 +1149,23 @@ Operator::ParseResult Binc::expectDigit(unsigned int &i_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (c == '0') {
i_in = 0;
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(c);
}
- if (expectDigitNZ(i_in) != Operator::ACCEPT) return Operator::REJECT;
+ if (expectDigitNZ(i_in) != ACCEPT) return REJECT;
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
+ParseResult Binc::expectDigitNZ(unsigned int &i_in)
{
Session &session = Session::getInstance();
@@ -1175,8 +1173,8 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
switch (c) {
@@ -1209,27 +1207,27 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
break;
case -1:
session.setLastError(bincClient.getLastErrorString());
- return Operator::ERROR;
+ return ERROR;
case -2:
- return Operator::TIMEOUT;
+ return TIMEOUT;
default:
bincClient.unreadChar(c);
- return Operator::REJECT;
+ return REJECT;
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectSet(SequenceSet &s_in)
+ParseResult Binc::expectSet(SequenceSet &s_in)
{
Session &session = Session::getInstance();
unsigned int seqnum = (unsigned int)-1;
- Operator::ParseResult res;
+ ParseResult res;
/* if a set does not start with a sequencenum, then it's not a
* set. :-) seqnum == -1 means '*'. */
- if ((res = expectSequenceNum(seqnum)) != Operator::ACCEPT) return res;
+ if ((res = expectSequenceNum(seqnum)) != ACCEPT) return res;
/* the first number is always a part of the set */
s_in.addNumber(seqnum);
@@ -1237,9 +1235,9 @@ Operator::ParseResult Binc::expectSet(SequenceSet &s_in)
/* if _after_ a set there is a ':', then there will always be a
* sequencenum after the colon. if not, it's a syntax error. a
* colon delimits two numbers in a range. */
- if ((res = expectThisString(":")) == Operator::ACCEPT) {
+ if ((res = expectThisString(":")) == ACCEPT) {
unsigned int seqnum2 = (unsigned int)-1;
- if ((res = expectSequenceNum(seqnum2)) != Operator::ACCEPT) {
+ if ((res = expectSequenceNum(seqnum2)) != ACCEPT) {
session.setLastError("expected sequencenum");
return res;
}
@@ -1249,17 +1247,17 @@ Operator::ParseResult Binc::expectSet(SequenceSet &s_in)
/* if _after_ a set there is a ',', then there will always be
* a set after the comma. if not, it's a syntax error. */
- if ((res = expectThisString(",")) == Operator::ACCEPT) {
- if ((res = expectSet(s_in)) != Operator::ACCEPT) {
+ if ((res = expectThisString(",")) == ACCEPT) {
+ if ((res = expectSet(s_in)) != ACCEPT) {
session.setLastError("expected set");
return res;
}
}
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in)
+ParseResult Binc::expectSequenceNum(unsigned int &i_in)
{
Session &session = Session::getInstance();
@@ -1267,35 +1265,35 @@ Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
- return Operator::ERROR;
+ if (bincClient.getLastError() == IODevice::Error::Timeout) return TIMEOUT;
+ return ERROR;
}
if (c == '*') {
i_in = (unsigned int)-1;
- return Operator::ACCEPT;
+ return ACCEPT;
} else {
bincClient.unreadChar(c);
}
- if (expectNZNumber(i_in) != Operator::ACCEPT)
- return Operator::REJECT;
+ if (expectNZNumber(i_in) != ACCEPT)
+ return REJECT;
else
- return Operator::ACCEPT;
+ return ACCEPT;
}
-Operator::ParseResult Binc::expectNZNumber(unsigned int &i_in)
+ParseResult Binc::expectNZNumber(unsigned int &i_in)
{
unsigned int c;
- Operator::ParseResult res;
+ ParseResult res;
- if ((res = expectDigitNZ(c)) != Operator::ACCEPT) return res;
+ if ((res = expectDigitNZ(c)) != ACCEPT) return res;
i_in = c;
- while ((res = expectDigit(c)) == Operator::ACCEPT)
+ while ((res = expectDigit(c)) == ACCEPT)
i_in = (i_in * 10) + c;
- if (res == Operator::TIMEOUT) return res;
+ if (res == TIMEOUT) return res;
- return Operator::ACCEPT;
+ return ACCEPT;
}
diff --git a/src/session-initialize-bincimap-up.cc b/src/session-initialize-bincimap-up.cc
index a17a171..646315a 100644
--- a/src/session-initialize-bincimap-up.cc
+++ b/src/session-initialize-bincimap-up.cc
@@ -105,7 +105,7 @@ bool Session::initialize(int argc, char *argv[])
// Now that we know the log type, we can flush.
IOFactory::getLogger().setFlags(IODevice::FlushesOnEndl);
- IOFactory::getLogger().setOutputLevelLimit(IODevice::InfoLevel);
+ IOFactory::getLogger().setOutputLevelLimit(IODevice::LogLevel::InfoLevel);
// imaps (port 993) -- requires sslserver with option -e
diff --git a/src/session-initialize-bincimapd.cc b/src/session-initialize-bincimapd.cc
index e98f0af..2590403 100644
--- a/src/session-initialize-bincimapd.cc
+++ b/src/session-initialize-bincimapd.cc
@@ -109,7 +109,7 @@ bool Session::initialize(int argc, char *argv[])
// Now that we know the log type, we can flush.
IOFactory::getLogger().flush();
IOFactory::getLogger().setFlags(IODevice::FlushesOnEndl);
- IOFactory::getLogger().setOutputLevelLimit(IODevice::InfoLevel);
+ IOFactory::getLogger().setOutputLevelLimit(IODevice::LogLevel::InfoLevel);
string pid = std::to_string(session.getPid());
diff --git a/src/session.cc b/src/session.cc
index 0ae87df..fc7bde7 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -35,12 +35,12 @@ Session &Session::getInstance()
return session;
}
-int Session::getState() const
+Session::State Session::getState() const
{
return state;
}
-void Session::setState(int n)
+void Session::setState(Session::State n)
{
state = n;
}
diff --git a/src/stdiodevice.cc b/src/stdiodevice.cc
index 919e92c..4b97c07 100644
--- a/src/stdiodevice.cc
+++ b/src/stdiodevice.cc
@@ -49,7 +49,7 @@ bool StdIODevice::waitForWrite() const
&writeMask,
nullptr,
timeout ? &tv : nullptr);
- if (result == 0) error = Timeout;
+ if (result == 0) error = Error::Timeout;
return result > 0;
}
@@ -64,7 +64,7 @@ bool StdIODevice::waitForRead() const
tv.tv_usec = 0;
int result = select(fileno(stdin) + 1, &readMask, nullptr, nullptr, timeout ? &tv : nullptr);
- if (result == 0) error = Timeout;
+ if (result == 0) error = Error::Timeout;
return result > 0;
}