diff options
Diffstat (limited to 'libksieve/ksieve')
-rw-r--r-- | libksieve/ksieve/Makefile.am | 8 | ||||
-rw-r--r-- | libksieve/ksieve/error.h | 139 | ||||
-rw-r--r-- | libksieve/ksieve/lexer.h | 108 | ||||
-rw-r--r-- | libksieve/ksieve/parser.h | 72 | ||||
-rw-r--r-- | libksieve/ksieve/scriptbuilder.h | 80 |
5 files changed, 407 insertions, 0 deletions
diff --git a/libksieve/ksieve/Makefile.am b/libksieve/ksieve/Makefile.am new file mode 100644 index 000000000..9d086dd2a --- /dev/null +++ b/libksieve/ksieve/Makefile.am @@ -0,0 +1,8 @@ +# here are header files that are part of the public api: +ksievedir = $(includedir)/ksieve + +ksieve_HEADERS = \ + error.h \ + lexer.h \ + parser.h \ + scriptbuilder.h diff --git a/libksieve/ksieve/error.h b/libksieve/ksieve/error.h new file mode 100644 index 000000000..2dbed32c8 --- /dev/null +++ b/libksieve/ksieve/error.h @@ -0,0 +1,139 @@ +/* -*- c++ -*- + ksieve/error.h + + This file is part of KSieve, + the KDE internet mail/usenet news message filtering library. + Copyright (c) 2002-2003 Marc Mutz <mutz@kde.org> + + KSieve is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KSieve is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KSIEVE_ERROR_H__ +#define __KSIEVE_ERROR_H__ + +#include <qstring.h> + +#include <kdepimmacros.h> + +#ifdef None // X headers +# undef None +#endif + +namespace KSieve { + + class KDE_EXPORT Error { + public: + enum Type { + None = 0, + Custom, + // parse (well-formedness in XML speak) errors: + FirstParseError, + + CRWithoutLF = FirstParseError, + SlashWithoutAsterisk, + IllegalCharacter, + UnexpectedCharacter, + NoLeadingDigits, + NonCWSAfterTextColon, + + NumberOutOfRange, + InvalidUTF8, + + UnfinishedBracketComment, + PrematureEndOfMultiLine, + PrematureEndOfQuotedString, + PrematureEndOfStringList, + PrematureEndOfTestList, + PrematureEndOfBlock, + MissingWhitespace, + MissingSemicolonOrBlock, + + ExpectedBlockOrSemicolon, + ExpectedCommand, + ConsecutiveCommasInStringList, + ConsecutiveCommasInTestList, + MissingCommaInTestList, + MissingCommaInStringList, + NonStringInStringList, + NonCommandInCommandList, + NonTestInTestList, + LastParseError = NonTestInTestList, + // validity errors: + FirstValidityError, + RequireNotFirst = FirstValidityError, // rfc3028, 3.2 + RequireMissingForCommand, + RequireMissingForTest, + RequireMissingForComparator, + UnsupportedCommand, + UnsupportedTest, + UnsupportedComparator, + TestNestingTooDeep, // site policy + BlockNestingTooDeep, // site policy + InvalidArgument, + ConflictingArguments, // e.g. rfc3028, 2.7.{1,3} + ArgumentsRepeated, // similar to ConflictingArguments, e.g. :is :is + CommandOrderingConstraintViolation, // e.g. else w/o if, rfc3028, 3.1 + LastValidityError = CommandOrderingConstraintViolation, + // runtime errors: + FirstRuntimeError, + IncompatibleActionsRequested = FirstRuntimeError, + MailLoopDetected, + TooManyActions, + LastRuntimeError = TooManyActions + }; + + static const char * typeToString( Type type ); + + Error( Type type=None, + const QString & s1=QString::null, const QString & s2=QString::null, + int line=-1, int col=-1 ) + : mType( type ), mLine( line ), mCol( col ), + mStringOne( s1 ), mStringTwo( s2 ) {} + Error( Type type, int line, int col ) + : mType( type ), mLine( line ), mCol( col ) {} + + QString asString() const; + + /** So you can write <pre>if( error() )</pre> with e.g. @ref Lexer */ + operator bool() const { + return type() != None; + } + + Type type() const { return mType; } + int line() const { return mLine; } + int column() const { return mCol; } + QString firstString() const { return mStringOne; } + QString secondString() const { return mStringTwo; } + + protected: + Type mType; + int mLine; + int mCol; + QString mStringOne, mStringTwo; + }; + +} // namespace KSieve + +#endif // __KSIEVE_ERROR_H__ diff --git a/libksieve/ksieve/lexer.h b/libksieve/ksieve/lexer.h new file mode 100644 index 000000000..d5bb1fc3b --- /dev/null +++ b/libksieve/ksieve/lexer.h @@ -0,0 +1,108 @@ +/* -*- c++ -*- + ksieve/lexer.h + + This file is part of KSieve, + the KDE internet mail/usenet news message filtering library. + Copyright (c) 2003 Marc Mutz <mutz@kde.org> + + KSieve is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KSieve is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KSIEVE_LEXER_H__ +#define __KSIEVE_LEXER_H__ + +class QString; + +namespace KSieve { + + class Error; + + class Lexer { + public: + enum Options { + IncludeComments = 0, + IgnoreComments = 1, + IncludeLineFeeds = 0, + IgnoreLineFeeds = 2 + }; + + Lexer( const char * scursor, const char * send, int options=0 ); + ~Lexer(); + + /** Return whether comments are returned by @ref + nextToken. Default is to not ignore comments. Ignoring them + can speed up script parsing a bit, and can be used when the + internal representation of the script won't be serialized into + string form again (or if you simply want to delete all + comments) + **/ + bool ignoreComments() const; + + /** Return whether line feeds are returned by @ref + nextToken. Default is to not ignore line feeds. Ignoring them + can speed up script parsing a bit, and can be used when the + internal representation of the script won't be serialized into + string form again. + **/ + bool ignoreLineFeeds() const; + + const Error & error() const; + + bool atEnd() const; + int column() const; + int line() const; + + enum Token { + None = 0, + Number, // 1, 100, 1M, 10k, 1G, 2g, 3m + Identifier, // atom + Tag, // :tag + Special, // {} [] () ,; + QuotedString, // "foo\"bar" -> foo"bar + MultiLineString, // text: \nfoo\n. -> foo + HashComment, // # foo + BracketComment, // /* foo */ + LineFeeds // the number of line feeds encountered + }; + + /** Parse the next token and return it's type. @p result will contain + the value of the token. */ + Token nextToken( QString & result ); + + void save(); + void restore(); + + class Impl; + private: + Impl * i; + + private: + const Lexer & operator=( const Lexer & ); + Lexer( const Lexer & ); + }; + +} // namespace KSieve + +#endif // __KSIEVE_LEXER_H__ diff --git a/libksieve/ksieve/parser.h b/libksieve/ksieve/parser.h new file mode 100644 index 000000000..e70e1db4d --- /dev/null +++ b/libksieve/ksieve/parser.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- + ksieve/parser.h + + This file is part of KSieve, + the KDE internet mail/usenet news message filtering library. + Copyright (c) 2002-2003 Marc Mutz <mutz@kde.org> + + KSieve is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KSieve is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KSIEVE_PARSING_H__ +#define __KSIEVE_PARSING_H__ + +#include <kdepimmacros.h> + +class QString; + +namespace KSieve { + + class ScriptBuilder; + class Error; + + /** @short Parser for the Sieve grammar. + @author Marc Mutz <mutz@kde.org> + **/ + class KDE_EXPORT Parser { + public: + + Parser( const char * scursor, const char * const send, int options=0 ); + ~Parser(); + + void setScriptBuilder( ScriptBuilder * builder ); + ScriptBuilder * scriptBuilder() const; + + bool parse(); + + const Error & error() const; + + class Impl; + private: + Impl * i; + + private: + const Parser & operator=( const Parser & ); + Parser( const Parser & ); + }; + +} // namespace KSieve + +#endif // __KSIEVE_PARSING_H__ diff --git a/libksieve/ksieve/scriptbuilder.h b/libksieve/ksieve/scriptbuilder.h new file mode 100644 index 000000000..5e0a955bb --- /dev/null +++ b/libksieve/ksieve/scriptbuilder.h @@ -0,0 +1,80 @@ +/* -*- c++ -*- + ksieve/interfaces/scriptbuilder.h + + This file is part of KSieve, + the KDE internet mail/usenet news message filtering library. + Copyright (c) 2002-2003 Marc Mutz <mutz@kde.org> + + KSieve is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KSieve is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KSIEVE_INTERFACES_SCRIPTBUILDER_H__ +#define __KSIEVE_INTERFACES_SCRIPTBUILDER_H__ + +class QString; + +namespace KSieve { + + class Error; + + class ScriptBuilder { + public: + virtual ~ScriptBuilder() {} + + virtual void taggedArgument( const QString & tag ) = 0; + virtual void stringArgument( const QString & string, bool multiLine, const QString & embeddedHashComment ) = 0; + virtual void numberArgument( unsigned long number, char quantifier ) = 0; + + virtual void stringListArgumentStart() = 0; + virtual void stringListEntry( const QString & string, bool multiLine, const QString & embeddedHashComment ) = 0; + virtual void stringListArgumentEnd() = 0; + + virtual void commandStart( const QString & identifier ) = 0; + virtual void commandEnd() = 0; + + virtual void testStart( const QString & identifier ) = 0; + virtual void testEnd() = 0; + + virtual void testListStart() = 0; + virtual void testListEnd() = 0; + + virtual void blockStart() = 0; + virtual void blockEnd() = 0; + + /** A hash comment always includes an implicit lineFeed() at it's end. */ + virtual void hashComment( const QString & comment ) = 0; + /** Bracket comments inclde explicit lineFeed()s in their content */ + virtual void bracketComment( const QString & comment ) = 0; + + virtual void lineFeed() = 0; + + virtual void error( const Error & error ) = 0; + + virtual void finished() = 0; + }; + +} // namespace KSieve + +#endif // __KSIEVE_INTERFACES_SCRIPTBUILDER_H__ |