diff --git a/autotests/server/fakedatastore.h b/autotests/server/fakedatastore.h index 95d743843..5b9944642 100644 --- a/autotests/server/fakedatastore.h +++ b/autotests/server/fakedatastore.h @@ -1,136 +1,136 @@ /* Copyright (c) 2014 Daniel Vrátil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_SERVER_FAKEDATASTORE_H #define AKONADI_SERVER_FAKEDATASTORE_H #include "storage/datastore.h" namespace Akonadi { namespace Server { class FakeDataStore : public DataStore { Q_OBJECT public: virtual ~FakeDataStore(); static DataStore *self(); bool init() Q_DECL_OVERRIDE; QMap changes() const { return mChanges; } virtual bool setItemsFlags(const PimItem::List &items, const QVector &flags, - bool *flagsChanged = 0, + bool *flagsChanged = nullptr, const Collection &col = Collection(), bool silent = false) Q_DECL_OVERRIDE; virtual bool appendItemsFlags(const PimItem::List &items, const QVector &flags, - bool *flagsChanged = 0, + bool *flagsChanged = nullptr, bool checkIfExists = true, const Collection &col = Collection(), bool silent = false) Q_DECL_OVERRIDE; virtual bool removeItemsFlags(const PimItem::List &items, const QVector &flags, - bool *flagsChanged = 0, + bool *flagsChanged = nullptr, const Collection &col = Collection(), bool silent = false) Q_DECL_OVERRIDE; virtual bool setItemsTags(const PimItem::List &items, const Tag::List &tags, - bool *tagsChanged = 0, + bool *tagsChanged = nullptr, bool silent = false) Q_DECL_OVERRIDE; virtual bool appendItemsTags(const PimItem::List &items, const Tag::List &tags, - bool *tagsChanged = 0, + bool *tagsChanged = nullptr, bool checkIfExists = true, const Collection &col = Collection(), bool silent = false) Q_DECL_OVERRIDE; virtual bool removeItemsTags(const PimItem::List &items, const Tag::List &tags, - bool *tagsChanged = 0, + bool *tagsChanged = nullptr, bool silent = false) Q_DECL_OVERRIDE; virtual bool removeItemParts(const PimItem &item, const QSet &parts) Q_DECL_OVERRIDE; virtual bool invalidateItemCache(const PimItem &item) Q_DECL_OVERRIDE; virtual bool appendCollection(Collection &collection) Q_DECL_OVERRIDE; virtual bool cleanupCollection(Collection &collection) Q_DECL_OVERRIDE; virtual bool cleanupCollection_slow(Collection &collection) Q_DECL_OVERRIDE; virtual bool moveCollection(Collection &collection, const Collection &newParent) Q_DECL_OVERRIDE; virtual bool appendMimeTypeForCollection(qint64 collectionId, const QStringList &mimeTypes) Q_DECL_OVERRIDE; virtual void activeCachePolicy(Collection &col) Q_DECL_OVERRIDE; virtual bool appendPimItem(QVector &parts, const QVector &flags, const MimeType &mimetype, const Collection &collection, const QDateTime &dateTime, const QString &remote_id, const QString &remoteRevision, const QString &gid, PimItem &pimItem) Q_DECL_OVERRIDE; virtual bool cleanupPimItems(const PimItem::List &items) Q_DECL_OVERRIDE; virtual bool unhidePimItem(PimItem &pimItem) Q_DECL_OVERRIDE; virtual bool unhideAllPimItems() Q_DECL_OVERRIDE; virtual bool addCollectionAttribute(const Collection &col, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; virtual bool removeCollectionAttribute(const Collection &col, const QByteArray &key) Q_DECL_OVERRIDE; virtual bool beginTransaction(const QString &name = QString()) Q_DECL_OVERRIDE; virtual bool rollbackTransaction() Q_DECL_OVERRIDE; virtual bool commitTransaction() Q_DECL_OVERRIDE; virtual NotificationCollector *notificationCollector() Q_DECL_OVERRIDE; void setPopulateDb(bool populate); protected: FakeDataStore(); QMap mChanges; private: bool populateDatabase(); bool mPopulateDb; }; } } #endif // AKONADI_SERVER_FAKEDATASTORE_H diff --git a/autotests/server/mockobjects.h b/autotests/server/mockobjects.h index dbd269d89..205ea47bd 100644 --- a/autotests/server/mockobjects.h +++ b/autotests/server/mockobjects.h @@ -1,61 +1,61 @@ /*************************************************************************** * Copyright (C) 2006 by Till Adam * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program 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 Library 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. * ***************************************************************************/ #ifndef MOCKOBJECTS_H #define MOCKOBJECTS_H #include "akonadiconnection.h" #include "teststoragebackend.h" using namespace Akonadi; -static AkonadiConnection *s_connection = 0; -static DataStore *s_backend = 0; +static AkonadiConnection *s_connection = nullptr; +static DataStore *s_backend = nullptr; class MockConnection : public AkonadiConnection { public: MockConnection() { } DataStore *storageBackend() { if (!s_backend) { s_backend = new MockBackend(); } return s_backend; } }; class MockObjects { public: MockObjects(); ~MockObjects(); static AkonadiConnection *mockConnection() { if (!s_connection) { s_connection = new MockConnection(); } return s_connection; } }; // End of class MockObjects #endif // MOCKOBJECTS_H diff --git a/src/core/item_p.h b/src/core/item_p.h index 3e83824b0..25fe0e47d 100644 --- a/src/core/item_p.h +++ b/src/core/item_p.h @@ -1,472 +1,472 @@ /* Copyright (c) 2008 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_ITEM_P_H #define AKONADI_ITEM_P_H #include #include #include "itempayloadinternals_p.h" #include "itemchangelog_p.h" #include "tag.h" #include #include #include #include namespace Akonadi { namespace _detail { template class clone_ptr { T *t; public: clone_ptr() : t(0) { } explicit clone_ptr(T *t) : t(t) { } clone_ptr(const clone_ptr &other) : t(other.t ? other.t->clone() : 0) { } ~clone_ptr() { delete t; } clone_ptr &operator=(const clone_ptr &other) { if (this != &other) { clone_ptr copy(other); swap(copy); } return *this; } void swap(clone_ptr &other) { using std::swap; swap(t, other.t); } T *operator->() const { return get(); } T &operator*() const { assert(get() != 0); return *get(); } T *get() const { return t; } T *release() { T *const r = t; t = 0; return r; } - void reset(T *other = 0) + void reset(T *other = nullptr) { delete t; t = other; } private: struct _save_bool { void f() { } }; typedef void (_save_bool::*save_bool)(); public: operator save_bool() const { return get() ? &_save_bool::f : 0; } }; template inline void swap(clone_ptr &lhs, clone_ptr &rhs) { lhs.swap(rhs); } template class VarLengthArray { QVarLengthArray impl; // ###should be replaced by self-written container that doesn't waste so much space public: typedef T value_type; typedef T *iterator; typedef const T *const_iterator; typedef T *pointer; typedef const T *const_pointer; typedef T &reference; typedef const T &const_reference; explicit VarLengthArray(int size = 0) : impl(size) { } // compiler-generated dtor, copy ctor, copy assignment are ok // swap() makes little sense void push_back(const T &t) { impl.append(t); } int capacity() const { return impl.capacity(); } void clear() { impl.clear(); } size_t size() const { return impl.count(); } bool empty() const { return impl.isEmpty(); } void pop_back() { return impl.removeLast(); } void reserve(size_t n) { impl.reserve(n); } void resize(size_t n) { impl.resize(n); } iterator begin() { return impl.data(); } iterator end() { return impl.data() + impl.size(); } const_iterator begin() const { return impl.data(); } const_iterator end() const { return impl.data() + impl.size(); } const_iterator cbegin() const { return begin(); } const_iterator cend() const { return end(); } reference front() { return *impl.data(); } reference back() { return *(impl.data() + impl.size()); } const_reference front() const { return *impl.data(); } const_reference back() const { return *(impl.data() + impl.size()); } reference operator[](size_t n) { return impl[n]; } const_reference operator[](size_t n) const { return impl[n]; } }; struct TypedPayload { clone_ptr payload; int sharedPointerId; int metaTypeId; }; struct BySharedPointerAndMetaTypeID : std::unary_function { const int spid; const int mtid; BySharedPointerAndMetaTypeID(int spid, int mtid) : spid(spid) , mtid(mtid) { } bool operator()(const TypedPayload &tp) const { return (mtid == -1 || mtid == tp.metaTypeId) && (spid == -1 || spid == tp.sharedPointerId); } }; } } // namespace Akonadi namespace std { template <> inline void swap(Akonadi::_detail::TypedPayload &lhs, Akonadi::_detail::TypedPayload &rhs) { lhs.payload.swap(rhs.payload); swap(lhs.sharedPointerId, rhs.sharedPointerId); swap(lhs.metaTypeId, rhs.metaTypeId); } } namespace Akonadi { //typedef _detail::VarLengthArray<_detail::TypedPayload,2> PayloadContainer; typedef std::vector<_detail::TypedPayload> PayloadContainer; } #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) // see qtbase e5e2629 namespace QtPrivate { #endif // disable Q_FOREACH on PayloadContainer (b/c it likes to take copies and clone_ptr doesn't like that) template <> class QForeachContainer { }; #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) } #endif namespace Akonadi { /** * @internal */ class ItemPrivate : public QSharedData { public: explicit ItemPrivate(Item::Id id = -1) : QSharedData() , mRevision(-1) , mId(id) , mParent(nullptr) , mLegacyPayload() , mPayloads() , mCollectionId(-1) , mSize(0) , mModificationTime() , mFlagsOverwritten(false) , mTagsOverwritten(false) , mSizeChanged(false) , mClearPayload(false) , mConversionInProgress(false) { } ItemPrivate(const ItemPrivate &other) : QSharedData(other) , mParent(nullptr) { mId = other.mId; mRemoteId = other.mRemoteId; mRemoteRevision = other.mRemoteRevision; mPayloadPath = other.mPayloadPath; Q_FOREACH (Attribute *attr, other.mAttributes) { mAttributes.insert(attr->type(), attr->clone()); } if (other.mParent) { mParent = new Collection(*(other.mParent)); } mFlags = other.mFlags; mRevision = other.mRevision; mTags = other.mTags; mRelations = other.mRelations; mSize = other.mSize; mModificationTime = other.mModificationTime; mMimeType = other.mMimeType; mLegacyPayload = other.mLegacyPayload; mPayloads = other.mPayloads; mFlagsOverwritten = other.mFlagsOverwritten; mSizeChanged = other.mSizeChanged; mCollectionId = other.mCollectionId; mClearPayload = other.mClearPayload; mVirtualReferences = other.mVirtualReferences; mGid = other.mGid; mCachedPayloadParts = other.mCachedPayloadParts; mTagsOverwritten = other.mTagsOverwritten; mConversionInProgress = false; ItemChangeLog *changelog = ItemChangeLog::instance(); changelog->addedFlags(this) = changelog->addedFlags(&other); changelog->deletedFlags(this) = changelog->deletedFlags(&other); changelog->addedTags(this) = changelog->addedTags(&other); changelog->deletedTags(this) = changelog->deletedTags(&other); changelog->deletedAttributes(this) = changelog->deletedAttributes(&other); } ~ItemPrivate() { qDeleteAll(mAttributes); delete mParent; ItemChangeLog::instance()->clearItemChangelog(this); } void resetChangeLog() { mFlagsOverwritten = false; mSizeChanged = false; mTagsOverwritten = false; ItemChangeLog::instance()->clearItemChangelog(this); } bool hasMetaTypeId(int mtid) const { return std::find_if(mPayloads.cbegin(), mPayloads.cend(), _detail::BySharedPointerAndMetaTypeID(-1, mtid)) != mPayloads.cend(); } Internal::PayloadBase *payloadBaseImpl(int spid, int mtid) const { auto it = std::find_if(mPayloads.cbegin(), mPayloads.cend(), _detail::BySharedPointerAndMetaTypeID(spid, mtid)); return it == mPayloads.cend() ? 0 : it->payload.get(); } bool movePayloadFrom(ItemPrivate *other, int mtid) const /*sic!*/ { assert(other); const size_t oldSize = mPayloads.size(); PayloadContainer &oPayloads = other->mPayloads; const _detail::BySharedPointerAndMetaTypeID matcher(-1, mtid); const size_t numMatching = std::count_if(oPayloads.begin(), oPayloads.end(), matcher); mPayloads.resize(oldSize + numMatching); using namespace std; // for swap() for (PayloadContainer::iterator dst = mPayloads.begin() + oldSize, src = oPayloads.begin(), end = oPayloads.end(); src != end; ++src) { if (matcher(*src)) { swap(*dst, *src); ++dst; } } return numMatching > 0; } #if 0 std::auto_ptr takePayloadBaseImpl(int spid, int mtid) { PayloadContainer::iterator it = std::find_if(mPayloads.begin(), mPayloads.end(), _detail::BySharedPointerAndMetaTypeID(spid, mtid)); if (it == mPayloads.end()) { return std::auto_ptr(); } std::rotate(it, it + 1, mPayloads.end()); std::auto_ptr result(it->payload.release()); mPayloads.pop_back(); return result; } #endif void setPayloadBaseImpl(int spid, int mtid, std::unique_ptr &p, bool add) const /*sic!*/ { if (!add) { mLegacyPayload.reset(); } if (!p.get()) { if (!add) { mPayloads.clear(); } return; } // if !add, delete all payload variants // (they're conversions of each other) mPayloadPath.clear(); mPayloads.resize(add ? mPayloads.size() + 1 : 1); _detail::TypedPayload &tp = mPayloads.back(); tp.payload.reset(p.release()); tp.sharedPointerId = spid; tp.metaTypeId = mtid; } void setLegacyPayloadBaseImpl(std::unique_ptr p); void tryEnsureLegacyPayload() const; // Utilise the 4-bytes padding from QSharedData int mRevision; Item::Id mId; QString mRemoteId; QString mRemoteRevision; mutable QString mPayloadPath; QHash mAttributes; mutable Collection *mParent; mutable _detail::clone_ptr mLegacyPayload; mutable PayloadContainer mPayloads; Item::Flags mFlags; Tag::List mTags; Relation::List mRelations; Item::Id mCollectionId; Collection::List mVirtualReferences; // TODO: Maybe just use uint? Would save us another 8 bytes after reordering qint64 mSize; QDateTime mModificationTime; QString mMimeType; QString mGid; QSet mCachedPayloadParts; bool mFlagsOverwritten : 1; bool mTagsOverwritten : 1; bool mSizeChanged : 1; bool mClearPayload : 1; mutable bool mConversionInProgress; // 6 bytes padding here }; } #endif diff --git a/src/private/imapparser_p.h b/src/private/imapparser_p.h index b5289df3f..99da7d9cd 100644 --- a/src/private/imapparser_p.h +++ b/src/private/imapparser_p.h @@ -1,212 +1,212 @@ /* Copyright (c) 2006 - 2007 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_IMAPPARSER_P_H #define AKONADI_IMAPPARSER_P_H #include "akonadiprivate_export.h" #include "imapset_p.h" #include #include #include namespace Akonadi { /** Parser for IMAP messages. */ class AKONADIPRIVATE_EXPORT ImapParser { public: /** Parses the next parenthesized list in @p data starting from @p start and puts the result into @p result. The number of used characters is returned. This does not recurse into sub-lists. @param data Source data. @param result The parsed list. @param start Start parsing at this index. */ static int parseParenthesizedList(const QByteArray &data, QList &result, int start = 0); static int parseParenthesizedList(const QByteArray &data, QVarLengthArray &result, int start = 0); /** Parse the next string in @p data (quoted or literal) starting from @p start and puts the result into @p result. The number of used characters is returned (this is not equal to result.length()!). @param data Source data. @param result Parsed string, quotation, literal marker, etc. are removed, 'NIL' is transformed into an empty QByteArray. @param start start parsing at this index. */ static int parseString(const QByteArray &data, QByteArray &result, int start = 0); /** Parses the next quoted string from @p data starting at @p start and puts it into @p result. The number of parsed characters is returned (this is not equal to result.length()!). @param data Source data. @param result Parsed string, quotation is removed and 'NIL' is transformed to an empty QByteArray. @param start Start parsing at this index. */ static int parseQuotedString(const QByteArray &data, QByteArray &result, int start = 0); /** Returns the number of leading espaces in @p data starting from @p start. @param data The source data. @param start Start parsing at this index. */ static int stripLeadingSpaces(const QByteArray &data, int start = 0); /** Returns the parentheses balance for the given data, considering quotes. @param data The source data. @param start Start parsing at this index. */ static int parenthesesBalance(const QByteArray &data, int start = 0); /** Joins a QByteArray list with the given separator. @param list The QByteArray list to join. @param separator The separator. */ static QByteArray join(const QList &list, const QByteArray &separator); /** Joins a QByteArray set with the given separator. @param set The QByteArray set to join. @param separator The separator. */ static QByteArray join(const QSet &set, const QByteArray &separator); /** Same as parseString(), but with additional UTF-8 decoding of the result. @param data Source data. @param result Parsed string, quotation, literal marker, etc. are removed, 'NIL' is transformed into an empty QString. UTF-8 decoding is applied.. @param start Start parsing at this index. */ static int parseString(const QByteArray &data, QString &result, int start = 0); /** Parses the next integer number from @p data starting at start and puts it into @p result. The number of characters parsed is returned (this is not the parsed result!). @param data Source data. @param result Parsed integer number, invalid if ok is false. @param ok Set to false if the parsing failed. @param start Start parsing at this index. */ - static int parseNumber(const QByteArray &data, qint64 &result, bool *ok = 0, int start = 0); + static int parseNumber(const QByteArray &data, qint64 &result, bool *ok = nullptr, int start = 0); /** Quotes the given QByteArray. @param data Source data. */ static QByteArray quote(const QByteArray &data); /** Parse an IMAP sequence set. @param data source data. @param result The parse sequence set. @param start start parsing at this index. @return end position of parsing. */ static int parseSequenceSet(const QByteArray &data, ImapSet &result, int start = 0); /** Parse an IMAP date/time value. @param data source data. @param dateTime The result date/time. @param start Start parsing at this index. @return end position of parsing. */ static int parseDateTime(const QByteArray &data, QDateTime &dateTime, int start = 0); /** Split a versioned key of the form 'key[version]' into its components. @param data The versioned key. @param key The unversioned key. @param version The version of the key or 0 if no version was set. */ static void splitVersionedKey(const QByteArray &data, QByteArray &key, int &version); /** Constructs a new IMAP parser. */ ImapParser(); /** Destroys an IMAP parser. */ ~ImapParser(); /** Parses the given line. @returns True if an IMAP message was parsed completely, false if more data is needed. @todo read from a QIODevice directly to avoid an extra line buffer */ bool parseNextLine(const QByteArray &readBuffer); /** Parses the given block of data. Note: This currently only handles continuation blocks. @param data The data to parse. */ void parseBlock(const QByteArray &data); /** Returns the tag of the parsed message. Only valid if parseNextLine() returned true. */ QByteArray tag() const; /** Return the raw data of the parsed IMAP message. Only valid if parseNextLine() returned true. */ QByteArray data() const; /** Resets the internal state of the parser. Call before parsing a new IMAP message. */ void reset(); /** Returns true if the last parsed line contained a literal continuation, ie. readiness for receiving literal data needs to be indicated. */ bool continuationStarted() const; /** Returns the expected size of liteal data. */ qint64 continuationSize() const; private: Q_DISABLE_COPY(ImapParser) class Private; Private *const d; }; } #endif