diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 21:49:37 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 21:49:37 +0200 |
commit | bc946633e0bcae5fe63528ad743bcc67de7e347d (patch) | |
tree | 7a3d127148c13d84e92f38c319fb5aad1e88a6cb /src/operator-fetch.cc | |
parent | 3ea7edf8c9bf7583c426178d4aaff4fb5b736bd2 (diff) |
created a Parser class
Diffstat (limited to 'src/operator-fetch.cc')
-rw-r--r-- | src/operator-fetch.cc | 115 |
1 files changed, 59 insertions, 56 deletions
diff --git a/src/operator-fetch.cc b/src/operator-fetch.cc index 7de2fbb..d64e289 100644 --- a/src/operator-fetch.cc +++ b/src/operator-fetch.cc @@ -365,56 +365,56 @@ Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request) return Operator::ProcessResult::OK; } -Parser::ParseResult FetchOperator::parse(Request &c_in) +Parser::ParseResult FetchOperator::parse(Request &c_in, Parser &p) { Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE after FETCH"); return res; } - if ((res = expectSet(c_in.getSet())) != ACCEPT) { + if ((res = p.expectSet(c_in.getSet())) != ACCEPT) { session.setLastError("Expected sequence set after FETCH SPACE"); return res; } - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE after FETCH SPACE set"); return res; } BincImapParserFetchAtt f; - if ((res = expectThisString("ALL")) == ACCEPT) { + if ((res = p.expectThisString("ALL")) == ACCEPT) { f.type = "ALL"; c_in.fatt.push_back(f); - } else if ((res = expectThisString("FULL")) == ACCEPT) { + } else if ((res = p.expectThisString("FULL")) == ACCEPT) { f.type = "FULL"; c_in.fatt.push_back(f); - } else if ((res = expectThisString("FAST")) == ACCEPT) { + } else if ((res = p.expectThisString("FAST")) == ACCEPT) { f.type = "FAST"; c_in.fatt.push_back(f); - } else if ((res = expectFetchAtt(f)) == ACCEPT) { + } else if ((res = expectFetchAtt(f, p)) == ACCEPT) { c_in.fatt.push_back(f); - } else if ((res = expectThisString("(")) == ACCEPT) { + } else if ((res = p.expectThisString("(")) == ACCEPT) { while (1) { BincImapParserFetchAtt ftmp; - if ((res = expectFetchAtt(ftmp)) != ACCEPT) { + if ((res = expectFetchAtt(ftmp, p)) != ACCEPT) { session.setLastError("Expected fetch_att"); return res; } c_in.fatt.push_back(ftmp); - if ((res = expectSPACE()) == REJECT) + if ((res = p.expectSPACE()) == REJECT) break; else if (res == ERROR) return ERROR; } - if ((res = expectThisString(")")) != ACCEPT) { + if ((res = p.expectThisString(")")) != ACCEPT) { session.setLastError("Expected )"); return res; } @@ -423,7 +423,7 @@ Parser::ParseResult FetchOperator::parse(Request &c_in) return res; } - if ((res = expectCRLF()) != ACCEPT) { + if ((res = p.expectCRLF()) != ACCEPT) { session.setLastError("Expected CRLF"); return res; } @@ -432,30 +432,31 @@ Parser::ParseResult FetchOperator::parse(Request &c_in) return ACCEPT; } -Parser::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const +Parser::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in, + Parser &p) const { Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectThisString("HEADER")) == ACCEPT) { + if ((res = p.expectThisString("HEADER")) == ACCEPT) { f_in.sectiontext = "HEADER"; - if ((res = expectThisString(".FIELDS")) == ACCEPT) { + if ((res = p.expectThisString(".FIELDS")) == ACCEPT) { f_in.sectiontext += ".FIELDS"; - if ((res = expectThisString(".NOT")) == ACCEPT) f_in.sectiontext += ".NOT"; + if ((res = p.expectThisString(".NOT")) == ACCEPT) f_in.sectiontext += ".NOT"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("expected SPACE"); return res; } - if ((res = expectHeaderList(f_in)) != ACCEPT) { + if ((res = expectHeaderList(f_in, p)) != ACCEPT) { session.setLastError("Expected header_list"); return res; } } - } else if ((res = expectThisString("TEXT")) == ACCEPT) { + } else if ((res = p.expectThisString("TEXT")) == ACCEPT) { f_in.sectiontext = "TEXT"; } else { return Parser::ParseResult::REJECT; @@ -464,25 +465,25 @@ Parser::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_i return ACCEPT; } -Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const +Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in, Parser &p) const { Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectThisString("[")) != ACCEPT) return REJECT; + if ((res = p.expectThisString("[")) != ACCEPT) return REJECT; - if ((res = expectSectionText(f_in)) != ACCEPT) { + if ((res = expectSectionText(f_in, p)) != ACCEPT) { unsigned int n; - if ((res = expectNZNumber(n)) == ACCEPT) { + if ((res = p.expectNZNumber(n)) == ACCEPT) { BincStream nstr; nstr << n; f_in.section = nstr.str(); bool gotadotalready = false; while (1) { - if ((res = expectThisString(".")) != ACCEPT) break; + if ((res = p.expectThisString(".")) != ACCEPT) break; - if ((res = expectNZNumber(n)) != ACCEPT) { + if ((res = p.expectNZNumber(n)) != ACCEPT) { gotadotalready = true; break; } @@ -493,10 +494,10 @@ Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) c f_in.section += nstr.str(); } - if (gotadotalready || (res = expectThisString(".")) == ACCEPT) { - if ((res = expectThisString("MIME")) == ACCEPT) { + if (gotadotalready || (res = p.expectThisString(".")) == ACCEPT) { + if ((res = p.expectThisString("MIME")) == ACCEPT) { f_in.sectiontext = "MIME"; - } else if ((res = expectSectionText(f_in)) != ACCEPT) { + } else if ((res = expectSectionText(f_in, p)) != ACCEPT) { session.setLastError("Expected MIME or section_text"); return res; } @@ -504,7 +505,7 @@ Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) c } } - if ((res = expectThisString("]")) != ACCEPT) { + if ((res = p.expectThisString("]")) != ACCEPT) { session.setLastError("Expected ]"); return res; } @@ -512,29 +513,30 @@ Parser::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) c return ACCEPT; } -Parser::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const +Parser::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in, + Parser &p) const { Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectThisString("(")) != ACCEPT) return REJECT; + if ((res = p.expectThisString("(")) != ACCEPT) return REJECT; string header_fld_name; while (1) { - if ((res = expectAstring(header_fld_name)) != ACCEPT) { + if ((res = p.expectAstring(header_fld_name)) != ACCEPT) { session.setLastError("Expected header_fld_name"); return res; } f_in.headerlist.push_back(header_fld_name); - if ((res = expectSPACE()) == ACCEPT) + if ((res = p.expectSPACE()) == ACCEPT) continue; else break; } - if ((res = expectThisString(")")) != ACCEPT) { + if ((res = p.expectThisString(")")) != ACCEPT) { session.setLastError("Expected )"); return res; } @@ -542,31 +544,31 @@ Parser::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in return ACCEPT; } -Parser::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const +Parser::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in, Parser &p) const { Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectThisString("<")) != ACCEPT) return REJECT; + if ((res = p.expectThisString("<")) != ACCEPT) return REJECT; unsigned int i; - if ((res = expectNumber(i)) != ACCEPT) { + if ((res = p.expectNumber(i)) != ACCEPT) { session.setLastError("Expected number"); return res; } - if ((res = expectThisString(".")) != ACCEPT) { + if ((res = p.expectThisString(".")) != ACCEPT) { session.setLastError("Expected ."); return res; } unsigned int j; - if ((res = expectNZNumber(j)) != ACCEPT) { + if ((res = p.expectNZNumber(j)) != ACCEPT) { session.setLastError("expected nz_number"); return res; } - if ((res = expectThisString(">")) != ACCEPT) { + if ((res = p.expectThisString(">")) != ACCEPT) { session.setLastError("Expected >"); return res; } @@ -576,47 +578,48 @@ Parser::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) co return ACCEPT; } -Parser::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const +Parser::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in, + Parser &p) const { Parser::ParseResult res; Session &session = Session::getInstance(); - if ((res = expectThisString("ENVELOPE")) == ACCEPT) { + if ((res = p.expectThisString("ENVELOPE")) == ACCEPT) { f_in.type = "ENVELOPE"; - } else if ((res = expectThisString("FLAGS")) == ACCEPT) { + } else if ((res = p.expectThisString("FLAGS")) == ACCEPT) { f_in.type = "FLAGS"; - } else if ((res = expectThisString("INTERNALDATE")) == ACCEPT) { + } else if ((res = p.expectThisString("INTERNALDATE")) == ACCEPT) { f_in.type = "INTERNALDATE"; - } else if ((res = expectThisString("UID")) == ACCEPT) { + } else if ((res = p.expectThisString("UID")) == ACCEPT) { f_in.type = "UID"; - } else if ((res = expectThisString("RFC822")) == ACCEPT) { + } else if ((res = p.expectThisString("RFC822")) == ACCEPT) { f_in.type = "RFC822"; - if ((res = expectThisString(".HEADER")) == ACCEPT) { + if ((res = p.expectThisString(".HEADER")) == ACCEPT) { f_in.type += ".HEADER"; - } else if ((res = expectThisString(".SIZE")) == ACCEPT) { + } else if ((res = p.expectThisString(".SIZE")) == ACCEPT) { f_in.type += ".SIZE"; - } else if ((res = expectThisString(".TEXT")) == ACCEPT) { + } else if ((res = p.expectThisString(".TEXT")) == ACCEPT) { f_in.type += ".TEXT"; - } else if ((res = expectThisString(".")) == ACCEPT) { + } else if ((res = p.expectThisString(".")) == ACCEPT) { session.setLastError("Expected RFC822, RFC822.HEADER," " RFC822.SIZE or RFC822.TEXT"); return ERROR; } - } else if ((res = expectThisString("BODY")) == ACCEPT) { + } else if ((res = p.expectThisString("BODY")) == ACCEPT) { f_in.type = "BODY"; - if ((res = expectThisString("STRUCTURE")) == ACCEPT) + if ((res = p.expectThisString("STRUCTURE")) == ACCEPT) f_in.type += "STRUCTURE"; - else if ((res = expectThisString(".PEEK")) == ACCEPT) + else if ((res = p.expectThisString(".PEEK")) == ACCEPT) f_in.type += ".PEEK"; - if ((res = expectSection(f_in)) != ACCEPT) { + if ((res = expectSection(f_in, p)) != ACCEPT) { f_in.hassection = false; } else { f_in.hassection = true; - if ((res = expectOffset(f_in)) == ERROR) return ERROR; + if ((res = expectOffset(f_in, p)) == ERROR) return ERROR; } } else { return REJECT; |