diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/broker.h | 5 | ||||
-rw-r--r-- | src/include/operators.h | 66 | ||||
-rw-r--r-- | src/include/recursivedescent.h | 78 |
3 files changed, 78 insertions, 71 deletions
diff --git a/src/include/broker.h b/src/include/broker.h index 0ead7a0..57c79dc 100644 --- a/src/include/broker.h +++ b/src/include/broker.h @@ -10,6 +10,7 @@ #include "depot.h" #include "operators.h" +#include "recursivedescent.h" #include "session.h" #include <map> @@ -57,11 +58,13 @@ namespace Binc { std::map<std::string, bool> deletables; public: + Parser &parser; + Operator *get(const std::string &name) const; void assign(const std::string &fname, Operator *o, bool deletable = false); Parser::ParseResult parseStub(Request &cmd); - Broker() = default; + Broker(Parser &p) : parser(p){}; Broker(Broker &&) = default; }; diff --git a/src/include/operators.h b/src/include/operators.h index bc03607..fe28680 100644 --- a/src/include/operators.h +++ b/src/include/operators.h @@ -23,7 +23,7 @@ namespace Binc { enum class ProcessResult { OK, BAD, NO, NOTHING, ABORT }; virtual ProcessResult process(Depot &, Request &) = 0; - virtual Parser::ParseResult parse(Request &) = 0; + virtual Parser::ParseResult parse(Request &, Parser &) = 0; virtual Session::State getState() const = 0; virtual const std::string getName() const = 0; @@ -32,7 +32,7 @@ namespace Binc { struct AppendOperator : public Operator { ProcessResult process(Depot &, Request &) final; - Parser::ParseResult parse(Request &) final; + Parser::ParseResult parse(Request &, Parser &) final; const std::string getName() const final; Session::State getState() const final; @@ -43,7 +43,7 @@ namespace Binc { class AuthenticateOperator : public Operator { public: ProcessResult process(Depot &, Request &) override; - virtual Parser::ParseResult parse(Request &) override; + virtual Parser::ParseResult parse(Request &, Parser &) override; const std::string getName() const override; Session::State getState() const override; @@ -61,7 +61,7 @@ namespace Binc { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -75,7 +75,7 @@ namespace Binc { class CheckOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -87,7 +87,7 @@ namespace Binc { class CreateOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -99,7 +99,7 @@ namespace Binc { class CloseOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -111,7 +111,7 @@ namespace Binc { class CopyOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -123,7 +123,7 @@ namespace Binc { class DeleteOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -135,7 +135,7 @@ namespace Binc { class ExpungeOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -146,15 +146,15 @@ namespace Binc { class FetchOperator : public Operator { protected: - 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; + Parser::ParseResult expectSectionText(BincImapParserFetchAtt &f_in, Parser &p) const; + Parser::ParseResult expectSection(BincImapParserFetchAtt &f_in, Parser &p) const; + Parser::ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in, Parser &p) const; + Parser::ParseResult expectOffset(BincImapParserFetchAtt &f_in, Parser &p) const; + Parser::ParseResult expectHeaderList(BincImapParserFetchAtt &f_in, Parser &p) const; public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -166,7 +166,7 @@ namespace Binc { class IdOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -185,7 +185,7 @@ namespace Binc { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -208,7 +208,7 @@ namespace Binc { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -220,7 +220,7 @@ namespace Binc { class LoginOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -232,7 +232,7 @@ namespace Binc { class LogoutOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -244,7 +244,7 @@ namespace Binc { class LsubOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -256,7 +256,7 @@ namespace Binc { class NamespaceOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -268,7 +268,7 @@ namespace Binc { class NoopOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -288,7 +288,7 @@ namespace Binc { class RenameOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -299,7 +299,7 @@ namespace Binc { class SearchOperator : public Operator { protected: - Parser::ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const; + Parser::ParseResult expectSearchKey(BincImapParserSearchKey &s_in, Parser &p) const; class SearchNode { std::string date; @@ -384,7 +384,7 @@ namespace Binc { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -396,7 +396,7 @@ namespace Binc { class SelectOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -415,7 +415,7 @@ namespace Binc { class StarttlsOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -430,7 +430,7 @@ namespace Binc { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -442,7 +442,7 @@ namespace Binc { class StoreOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -454,7 +454,7 @@ namespace Binc { class SubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; @@ -466,7 +466,7 @@ namespace Binc { class UnsubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); - virtual Parser::ParseResult parse(Request &); + virtual Parser::ParseResult parse(Request &, Parser &); const std::string getName() const; Session::State getState() const; diff --git a/src/include/recursivedescent.h b/src/include/recursivedescent.h index 1200211..bf1fee4 100644 --- a/src/include/recursivedescent.h +++ b/src/include/recursivedescent.h @@ -9,63 +9,67 @@ #define expectcommand_h_inluded #include "imapparser.h" +#include "session.h" #include <stack> #include <string> namespace Binc { - extern std::stack<int> inputBuffer; - extern int charnr; + class Parser { + std::stack<int> inputBuffer; + int charnr; + Session &session; - int readChar(); - void unReadChar(int c_in); - void unReadChar(const std::string &s_in); + public: + Parser(Session &session) : charnr(0), session(session){}; + Parser(const Parser &) = delete; - namespace Parser { - enum class ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT }; - } + int readChar(); + void unReadChar(int c_in); + void unReadChar(const std::string &s_in); - using ParseResult = Parser::ParseResult; + enum class ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT }; - ParseResult expectTag(std::string &s_in); - ParseResult expectTagChar(int &c_in); - ParseResult expectSPACE(); + ParseResult expectTag(std::string &s_in); + ParseResult expectTagChar(int &c_in); + ParseResult expectSPACE(); - ParseResult expectFlag(std::vector<std::string> &v_in); + ParseResult expectFlag(std::vector<std::string> &v_in); - ParseResult expectListMailbox(std::string &s_in); - ParseResult expectListWildcards(int &c_in); + ParseResult expectListMailbox(std::string &s_in); + ParseResult expectListWildcards(int &c_in); - ParseResult expectDateTime(std::string &s_in); - ParseResult expectTime(std::string &s_in); - ParseResult expectZone(std::string &s_in); + ParseResult expectDateTime(std::string &s_in); + ParseResult expectTime(std::string &s_in); + ParseResult expectZone(std::string &s_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); + 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); - ParseResult expectDate(std::string &s_in); + ParseResult expectDate(std::string &s_in); - ParseResult expectNumber(unsigned int &i_in); - ParseResult expectDigit(unsigned int &i_in); - ParseResult expectDigitNZ(unsigned int &i_in); + ParseResult expectNumber(unsigned int &i_in); + ParseResult expectDigit(unsigned int &i_in); + ParseResult expectDigitNZ(unsigned int &i_in); - ParseResult expectLiteral(std::string &s_in); - ParseResult expectQuoted(std::string &s_in); - ParseResult expectQuotedChar(int &c_in); + ParseResult expectLiteral(std::string &s_in); + ParseResult expectQuoted(std::string &s_in); + ParseResult expectQuotedChar(int &c_in); - ParseResult expectSet(SequenceSet &s_in); - ParseResult expectSequenceNum(unsigned int &i_in); - ParseResult expectNZNumber(unsigned int &i_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 expectCRLF(); + ParseResult expectCR(); + ParseResult expectLF(); - ParseResult expectThisString(const std::string &s_in); + ParseResult expectThisString(const std::string &s_in); + }; } #endif |