Changeset View
Changeset View
Standalone View
Standalone View
src/api/KWallet/kwallet.cpp
Show All 20 Lines | |||||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kwallet.h" | 23 | #include "kwallet.h" | ||
24 | #include <config-kwallet.h> | 24 | #include <config-kwallet.h> | ||
25 | #include "kwallet_api_debug.h" | 25 | #include "kwallet_api_debug.h" | ||
26 | 26 | | |||
27 | #include <QApplication> | 27 | #include <QApplication> | ||
28 | #include <QDBusConnection> | 28 | #include <QDBusConnection> | ||
29 | #include <QRegularExpression> | ||||
29 | 30 | | |||
30 | #include <kconfiggroup.h> | 31 | #include <kconfiggroup.h> | ||
31 | #include <ksharedconfig.h> | 32 | #include <ksharedconfig.h> | ||
32 | #include <kwindowsystem.h> | 33 | #include <kwindowsystem.h> | ||
33 | 34 | | |||
34 | #if HAVE_KSECRETSSERVICE | 35 | #if HAVE_KSECRETSSERVICE | ||
35 | #include "ksecretsservice/ksecretsservicecollection.h" | 36 | #include "ksecretsservice/ksecretsservicecollection.h" | ||
36 | #endif | 37 | #endif | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 148 | #if HAVE_KSECRETSSERVICE | |||
171 | template <typename V> | 172 | template <typename V> | ||
172 | int forEachItemThatMatches(const QString &key, V verb) | 173 | int forEachItemThatMatches(const QString &key, V verb) | ||
173 | { | 174 | { | ||
174 | int rc = -1; | 175 | int rc = -1; | ||
175 | KSecretsService::StringStringMap attrs; | 176 | KSecretsService::StringStringMap attrs; | ||
176 | attrs[KSS_ATTR_ENTRYFOLDER] = folder; | 177 | attrs[KSS_ATTR_ENTRYFOLDER] = folder; | ||
177 | KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); | 178 | KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); | ||
178 | if (searchItemsJob->exec()) { | 179 | if (searchItemsJob->exec()) { | ||
179 | const QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard); | 180 | // HACK: QRegularExpression::wildcardToRegularExpression() mainly handles file pattern | ||
181 | // globbing (e.g. "*.txt") which means it doesn't allow "/" in the file name (which is | ||||
182 | // technically correct); we have to subvert it because the keys in kwallet are in the | ||||
183 | // form e.g. "foo.com/<User name>" which does have a "/" in it | ||||
184 | const QString pattern = QRegularExpression::wildcardToRegularExpression(key).replace( | ||||
185 | QLatin1String("[^/]"), QLatin1String(".")); | ||||
186 | const QRegularExpression re(pattern); | ||||
180 | const auto list = searchItemsJob->items(); | 187 | const auto list = searchItemsJob->items(); | ||
181 | for (KSecretsService::SearchCollectionItemsJob::Item item : list) { | 188 | for (KSecretsService::SearchCollectionItemsJob::Item item : list) { | ||
182 | KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); | 189 | KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); | ||
183 | if (readLabelJob->exec()) { | 190 | if (readLabelJob->exec()) { | ||
184 | QString label = readLabelJob->propertyValue().toString(); | 191 | QString label = readLabelJob->propertyValue().toString(); | ||
185 | if (re.exactMatch(label)) { | 192 | if (re.match(label).hasMatch()) { | ||
186 | if (verb(this, label, item.data())) { | 193 | if (verb(this, label, item.data())) { | ||
187 | rc = 0; // one successful iteration already produced results, so success return | 194 | rc = 0; // one successful iteration already produced results, so success return | ||
188 | } | 195 | } | ||
189 | } | 196 | } | ||
190 | } else { | 197 | } else { | ||
191 | qCDebug(KWALLET_API_LOG) << "Cannot execute ReadItemPropertyJob " << readLabelJob->errorString(); | 198 | qCDebug(KWALLET_API_LOG) << "Cannot execute ReadItemPropertyJob " << readLabelJob->errorString(); | ||
192 | } | 199 | } | ||
193 | } | 200 | } | ||
▲ Show 20 Lines • Show All 1479 Lines • Show Last 20 Lines |