diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/broker.h | 23 | ||||
-rw-r--r-- | src/include/imapserver.h | 2 | ||||
-rw-r--r-- | src/include/iodevice.h | 4 | ||||
-rw-r--r-- | src/include/iofactory.h | 16 | ||||
-rw-r--r-- | src/include/operators.h | 154 | ||||
-rw-r--r-- | src/include/recursivedescent.h | 71 | ||||
-rw-r--r-- | src/include/session.h | 18 |
7 files changed, 143 insertions, 145 deletions
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 |