00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KIMAP_IMAPSTREAMPARSER_P_H
00022 #define KIMAP_IMAPSTREAMPARSER_P_H
00023
00024 #include "kimap_export.h"
00025
00026 #include <exception>
00027
00028 #include <QtCore/QByteArray>
00029 #include <QtCore/QList>
00030 #include <QtCore/QString>
00031
00032 class QIODevice;
00033
00034 namespace KIMAP {
00035
00036 class ImapParserException : public std::exception
00037 {
00038 public:
00039 ImapParserException( const char *what ) throw() : mWhat( what ) {}
00040 ImapParserException( const QByteArray &what ) throw() : mWhat( what ) {}
00041 ImapParserException( const QString &what ) throw() : mWhat( what.toUtf8() ) {}
00042 ImapParserException( const ImapParserException &other ) throw() : std::exception( other ), mWhat( other.what() ) {}
00043 virtual ~ImapParserException() throw() {}
00044 const char *what() const throw() { return mWhat.constData(); }
00045 virtual const char *type() const throw() { return "ImapParserException"; }
00046 private:
00047 QByteArray mWhat;
00048 };
00049
00053 class KIMAP_EXPORT ImapStreamParser
00054 {
00055 public:
00062 explicit ImapStreamParser( QIODevice *socket, bool serverModeEnabled = false );
00063
00067 ~ImapStreamParser();
00068
00074 QString readUtf8String();
00075
00080 QByteArray readString();
00081
00087 QList<QByteArray> readParenthesizedList();
00088
00089
00095 qint64 readNumber( bool * ok = 0 );
00096
00101 bool hasString();
00102
00109 bool hasLiteral();
00110
00130 QByteArray readLiteralPart();
00131
00136 bool atLiteralEnd() const;
00137
00142 bool hasList();
00143
00148 bool atListEnd();
00149
00154 bool hasResponseCode();
00155
00160 bool atResponseCodeEnd();
00161
00166 bool atCommandEnd();
00167
00172 QByteArray readUntilCommandEnd();
00173
00178 QByteArray readRemainingData();
00179
00180 int availableDataSize() const;
00181
00182 void setData( const QByteArray &data );
00183
00184
00185 private:
00186 void stripLeadingSpaces();
00187 QByteArray parseQuotedString();
00188
00195 bool waitForMoreData( bool wait);
00196
00200 void sendContinuationResponse( qint64 size );
00201
00205 void trimBuffer();
00206
00207 QIODevice *m_socket;
00208 bool m_isServerModeEnabled;
00209 QByteArray m_data;
00210 int m_position;
00211 qint64 m_literalSize;
00212 };
00213
00214 }
00215
00216 #endif