summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/imap/src/nsImapGenericParser.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/imap/src/nsImapGenericParser.h
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/imap/src/nsImapGenericParser.h')
-rw-r--r--comm/mailnews/imap/src/nsImapGenericParser.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/comm/mailnews/imap/src/nsImapGenericParser.h b/comm/mailnews/imap/src/nsImapGenericParser.h
new file mode 100644
index 0000000000..50abffa5e1
--- /dev/null
+++ b/comm/mailnews/imap/src/nsImapGenericParser.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+nsImapGenericParser is the base parser class used by the server parser and body
+shell parser
+*/
+
+#ifndef nsImapGenericParser_H
+#define nsImapGenericParser_H
+
+#define WHITESPACE " \015\012" // token delimiter
+
+class nsImapGenericParser {
+ public:
+ nsImapGenericParser();
+ virtual ~nsImapGenericParser();
+
+ // Add any specific stuff in the derived class
+ virtual bool LastCommandSuccessful();
+
+ bool SyntaxError() { return (fParserState & stateSyntaxErrorFlag) != 0; }
+ bool ContinueParse() { return fParserState == stateOK; }
+ bool Connected() { return !(fParserState & stateDisconnectedFlag); }
+ void SetConnected(bool error);
+
+ protected:
+ // This is a pure virtual member which must be overridden in the derived class
+ // for each different implementation of a nsImapGenericParser.
+ // For instance, one implementation (the nsIMAPServerState) might get the next
+ // line from an open socket, whereas another implementation might just get it
+ // from a buffer somewhere. This fills in nextLine with the buffer, and
+ // returns true if everything is OK. Returns false if there was some error
+ // encountered. In that case, we reset the parser.
+ virtual bool GetNextLineForParser(char** nextLine) = 0;
+
+ virtual void HandleMemoryFailure();
+ void skip_to_CRLF();
+ void skip_to_close_paren();
+ char* CreateString();
+ char* CreateAstring();
+ char* CreateNilString();
+ char* CreateLiteral();
+ char* CreateAtom(bool isAstring = false);
+ char* CreateQuoted(bool skipToEnd = true);
+ char* CreateParenGroup();
+ virtual void SetSyntaxError(bool error, const char* msg);
+
+ void AdvanceToNextToken();
+ void AdvanceToNextLine();
+ void AdvanceTokenizerStartingPoint(int32_t bytesToAdvance);
+ void ResetLexAnalyzer();
+
+ protected:
+ // use with care
+ const char* fNextToken;
+ char* fCurrentLine;
+ char* fLineOfTokens;
+ char* fStartOfLineOfTokens;
+ char* fCurrentTokenPlaceHolder;
+ bool fAtEndOfLine;
+
+ private:
+ enum nsImapGenericParserState {
+ stateOK = 0,
+ stateSyntaxErrorFlag = 0x1,
+ stateDisconnectedFlag = 0x2
+ };
+ uint32_t fParserState;
+};
+
+#endif