diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/messagequeue.cpp | 5 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 2 | ||||
-rw-r--r-- | common/storage.h | 5 | ||||
-rw-r--r-- | common/storage_common.cpp | 22 |
4 files changed, 31 insertions, 3 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index 3754b16..76f8162 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "messagequeue.h" | 1 | #include "messagequeue.h" |
2 | #include "storage.h" | ||
2 | #include <QDebug> | 3 | #include <QDebug> |
3 | 4 | ||
4 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) | 5 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) |
@@ -24,7 +25,7 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
24 | bool readValue = false; | 25 | bool readValue = false; |
25 | mStorage.scan("", 0, [this, resultHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 26 | mStorage.scan("", 0, [this, resultHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
26 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); | 27 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); |
27 | if (key.startsWith("__internal")) { | 28 | if (Akonadi2::Storage::isInternalKey(key)) { |
28 | return true; | 29 | return true; |
29 | } | 30 | } |
30 | readValue = true; | 31 | readValue = true; |
@@ -55,7 +56,7 @@ bool MessageQueue::isEmpty() | |||
55 | int count = 0; | 56 | int count = 0; |
56 | mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 57 | mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
57 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); | 58 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); |
58 | if (!key.startsWith("__internal")) { | 59 | if (!Akonadi2::Storage::isInternalKey(key)) { |
59 | count++; | 60 | count++; |
60 | return false; | 61 | return false; |
61 | } | 62 | } |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index b874679..fc63e7c 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -319,7 +319,7 @@ bool ResourceAccess::processMessageBuffer() | |||
319 | return false; | 319 | return false; |
320 | } | 320 | } |
321 | 321 | ||
322 | const uint messageId = *(int*)(d->partialMessageBuffer.constData()); | 322 | //const uint messageId = *(int*)(d->partialMessageBuffer.constData()); |
323 | const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); | 323 | const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); |
324 | const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); | 324 | const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); |
325 | 325 | ||
diff --git a/common/storage.h b/common/storage.h index 758765e..d8378e2 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -79,6 +79,11 @@ public: | |||
79 | void setMaxRevision(qint64 revision); | 79 | void setMaxRevision(qint64 revision); |
80 | 80 | ||
81 | bool exists() const; | 81 | bool exists() const; |
82 | |||
83 | static bool isInternalKey(const char *key); | ||
84 | static bool isInternalKey(void *key, int keySize); | ||
85 | static bool isInternalKey(const QByteArray &key); | ||
86 | |||
82 | private: | 87 | private: |
83 | class Private; | 88 | class Private; |
84 | Private * const d; | 89 | Private * const d; |
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index bdae9dd..ff2a2cd 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -25,6 +25,9 @@ | |||
25 | namespace Akonadi2 | 25 | namespace Akonadi2 |
26 | { | 26 | { |
27 | 27 | ||
28 | static const char *s_internalPrefix = "__internal"; | ||
29 | static const int s_internalPrefixSize = strlen(s_internalPrefix); | ||
30 | |||
28 | void errorHandler(const Storage::Error &error) | 31 | void errorHandler(const Storage::Error &error) |
29 | { | 32 | { |
30 | //TODO: allow this to be turned on / off globally | 33 | //TODO: allow this to be turned on / off globally |
@@ -71,4 +74,23 @@ qint64 Storage::maxRevision() | |||
71 | return r; | 74 | return r; |
72 | } | 75 | } |
73 | 76 | ||
77 | bool Storage::isInternalKey(const char *key) | ||
78 | { | ||
79 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; | ||
80 | } | ||
81 | |||
82 | bool Storage::isInternalKey(void *key, int size) | ||
83 | { | ||
84 | if (size < 1) { | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | return key && strncmp(static_cast<char *>(key), s_internalPrefix, (size > s_internalPrefixSize ? s_internalPrefixSize : size)) == 0; | ||
89 | } | ||
90 | |||
91 | bool Storage::isInternalKey(const QByteArray &key) | ||
92 | { | ||
93 | return key.startsWith(s_internalPrefix); | ||
94 | } | ||
95 | |||
74 | } // namespace Akonadi2 | 96 | } // namespace Akonadi2 |