diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 19:28:50 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-10-11 19:28:50 +0200 |
commit | 3ea7edf8c9bf7583c426178d4aaff4fb5b736bd2 (patch) | |
tree | ae78ebf9e9d1f70da8a6fdad1504063644ee8f1e /src/recursivedescent.cc | |
parent | 1a7c572099edf744d6bb67318cff215de3fcd897 (diff) |
use some enum classes
move ParseResult to recursivedescent.h
Diffstat (limited to 'src/recursivedescent.cc')
-rw-r--r-- | src/recursivedescent.cc | 492 |
1 files changed, 245 insertions, 247 deletions
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; } |