blob: 34f66e4ff51d0ab794f5c305da0d3d9f9ea9e556 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* -*- 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
#include "nsImapCore.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
|