Changeset View
Changeset View
Standalone View
Standalone View
src/api/KWallet/kwallet.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Line(s) | 151 | { | |||
---|---|---|---|---|---|
164 | rc = createItemJob->error(); | 164 | rc = createItemJob->error(); | ||
165 | return rc; | 165 | return rc; | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | QExplicitlySharedDataPointer<KSecretsService::SecretItem> findItem(const QString &key) const; | 168 | QExplicitlySharedDataPointer<KSecretsService::SecretItem> findItem(const QString &key) const; | ||
169 | template <typename T> int readEntry(const QString &key, T &value) const; | 169 | template <typename T> int readEntry(const QString &key, T &value) const; | ||
170 | bool readSecret(const QString &key, KSecretsService::Secret &value) const; | 170 | bool readSecret(const QString &key, KSecretsService::Secret &value) const; | ||
171 | 171 | | |||
172 | #if KWALLET_BUILD_DEPRECATED_SINCE(5, 70) | ||||
172 | template <typename V> | 173 | template <typename V> | ||
173 | int forEachItemThatMatches(const QString &key, V verb) | 174 | int forEachItemThatMatches(const QString &key, V verb) | ||
174 | { | 175 | { | ||
175 | int rc = -1; | 176 | int rc = -1; | ||
176 | KSecretsService::StringStringMap attrs; | 177 | KSecretsService::StringStringMap attrs; | ||
177 | attrs[KSS_ATTR_ENTRYFOLDER] = folder; | 178 | attrs[KSS_ATTR_ENTRYFOLDER] = folder; | ||
178 | KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); | 179 | KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); | ||
179 | if (searchItemsJob->exec()) { | 180 | if (searchItemsJob->exec()) { | ||
Show All 18 Lines | 198 | } else { | |||
198 | qCDebug(KWALLET_API_LOG) << "Cannot execute ReadItemPropertyJob " << readLabelJob->errorString(); | 199 | qCDebug(KWALLET_API_LOG) << "Cannot execute ReadItemPropertyJob " << readLabelJob->errorString(); | ||
199 | } | 200 | } | ||
200 | } | 201 | } | ||
201 | } else { | 202 | } else { | ||
202 | qCDebug(KWALLET_API_LOG) << "Cannot execute KSecretsService::SearchCollectionItemsJob " << searchItemsJob->errorString(); | 203 | qCDebug(KWALLET_API_LOG) << "Cannot execute KSecretsService::SearchCollectionItemsJob " << searchItemsJob->errorString(); | ||
203 | } | 204 | } | ||
204 | return rc; | 205 | return rc; | ||
205 | } | 206 | } | ||
207 | #endif | ||||
208 | | ||||
209 | template <typename V> int checkItems(V verb) | ||||
210 | { | ||||
211 | int rc = -1; | ||||
212 | KSecretsService::StringStringMap attrs; | ||||
213 | attrs[KSS_ATTR_ENTRYFOLDER] = folder; | ||||
214 | KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); | ||||
215 | if (searchItemsJob->exec()) { | ||||
216 | const auto list = searchItemsJob->items(); | ||||
217 | for (KSecretsService::SearchCollectionItemsJob::Item item : list) { | ||||
218 | KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); | ||||
219 | if (readLabelJob->exec()) { | ||||
dfaure: Urgh. This actually calls for async API instead.
But now I'm really confused. | |||||
220 | const QString label = readLabelJob->propertyValue().toString(); | ||||
221 | if (verb(this, label, item.data())) { | ||||
222 | rc = 0; // one successful iteration already produced results, so success return | ||||
223 | } | ||||
224 | } else { | ||||
225 | qCDebug(KWALLET_API_LOG) << "Cannot execute ReadItemPropertyJob " << readLabelJob->errorString(); | ||||
226 | } | ||||
227 | } | ||||
228 | } else { | ||||
229 | qCDebug(KWALLET_API_LOG) << "Cannot execute KSecretsService::SearchCollectionItemsJob " << searchItemsJob->errorString(); | ||||
230 | } | ||||
231 | return rc; | ||||
232 | } | ||||
206 | 233 | | |||
207 | void createDefaultFolders(); | 234 | void createDefaultFolders(); | ||
208 | 235 | | |||
209 | struct InsertIntoEntryList; | 236 | struct InsertIntoEntryList; | ||
210 | struct InsertIntoMapList; | 237 | struct InsertIntoMapList; | ||
211 | struct InsertIntoPasswordList; | 238 | struct InsertIntoPasswordList; | ||
212 | 239 | | |||
213 | KSecretsService::Collection *secretsCollection; | 240 | KSecretsService::Collection *secretsCollection; | ||
▲ Show 20 Lines • Show All 827 Lines • ▼ Show 20 Line(s) | 1067 | } else { | |||
1041 | qCDebug(KWALLET_API_LOG) << "Cannot execute GetSecretItemSecretJob " << readSecretJob->errorString(); | 1068 | qCDebug(KWALLET_API_LOG) << "Cannot execute GetSecretItemSecretJob " << readSecretJob->errorString(); | ||
1042 | } | 1069 | } | ||
1043 | return result; | 1070 | return result; | ||
1044 | } | 1071 | } | ||
1045 | QMap< QString, QByteArray > _value; | 1072 | QMap< QString, QByteArray > _value; | ||
1046 | }; | 1073 | }; | ||
1047 | #endif | 1074 | #endif | ||
1048 | 1075 | | |||
1076 | #if KWALLET_BUILD_DEPRECATED_SINCE(5, 70) | ||||
1049 | int Wallet::readEntryList(const QString &key, QMap<QString, QByteArray> &value) | 1077 | int Wallet::readEntryList(const QString &key, QMap<QString, QByteArray> &value) | ||
1050 | { | 1078 | { | ||
1051 | 1079 | | |||
1052 | int rc = -1; | 1080 | int rc = -1; | ||
1053 | 1081 | | |||
1054 | #if HAVE_KSECRETSSERVICE | 1082 | #if HAVE_KSECRETSSERVICE | ||
1055 | if (walletLauncher()->m_useKSecretsService) { | 1083 | if (walletLauncher()->m_useKSecretsService) { | ||
1056 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoEntryList(value)); | 1084 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoEntryList(value)); | ||
Show All 15 Lines | 1094 | if (r.isValid()) { | |||
1072 | } | 1100 | } | ||
1073 | } | 1101 | } | ||
1074 | #if HAVE_KSECRETSSERVICE | 1102 | #if HAVE_KSECRETSSERVICE | ||
1075 | } | 1103 | } | ||
1076 | #endif | 1104 | #endif | ||
1077 | 1105 | | |||
1078 | return rc; | 1106 | return rc; | ||
1079 | } | 1107 | } | ||
1108 | #endif | ||||
1109 | | ||||
1110 | int Wallet::entriesList(QMap<QString, QByteArray> &value) | ||||
1111 | { | ||||
1112 | | ||||
1113 | int rc = -1; | ||||
1114 | | ||||
1115 | #if HAVE_KSECRETSSERVICE | ||||
1116 | if (walletLauncher()->m_useKSecretsService) { | ||||
1117 | rc = d->checkItems(WalletPrivate::InsertIntoEntryList(value)); | ||||
1118 | } else { | ||||
1119 | #endif | ||||
1120 | registerTypes(); | ||||
1121 | | ||||
1122 | if (d->handle == -1) { | ||||
1123 | return rc; | ||||
1124 | } | ||||
1125 | | ||||
1126 | QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().entriesList(d->handle, d->folder, appid()); | ||||
1127 | if (reply.isValid()) { | ||||
1128 | rc = 0; | ||||
1129 | // convert <QString, QVariant> to <QString, QByteArray> | ||||
1130 | const QVariantMap val = reply.value(); | ||||
1131 | for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) { | ||||
1132 | value.insert(it.key(), it.value().toByteArray()); | ||||
1133 | } | ||||
1134 | } | ||||
1135 | #if HAVE_KSECRETSSERVICE | ||||
1136 | } | ||||
1137 | #endif | ||||
1138 | | ||||
1139 | return rc; | ||||
1140 | } | ||||
1141 | | ||||
1080 | 1142 | | |||
1081 | int Wallet::renameEntry(const QString &oldName, const QString &newName) | 1143 | int Wallet::renameEntry(const QString &oldName, const QString &newName) | ||
1082 | { | 1144 | { | ||
1083 | int rc = -1; | 1145 | int rc = -1; | ||
1084 | 1146 | | |||
1085 | #if HAVE_KSECRETSSERVICE | 1147 | #if HAVE_KSECRETSSERVICE | ||
1086 | if (walletLauncher()->m_useKSecretsService) { | 1148 | if (walletLauncher()->m_useKSecretsService) { | ||
1087 | QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem(oldName); | 1149 | QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem(oldName); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 1219 | if (d->readEntry< QMap< QString, QString> >(label, map)) { | |||
1159 | result = true; | 1221 | result = true; | ||
1160 | } | 1222 | } | ||
1161 | return result; | 1223 | return result; | ||
1162 | } | 1224 | } | ||
1163 | QMap< QString, QMap< QString, QString> > &_value; | 1225 | QMap< QString, QMap< QString, QString> > &_value; | ||
1164 | }; | 1226 | }; | ||
1165 | #endif | 1227 | #endif | ||
1166 | 1228 | | |||
1229 | #if KWALLET_BUILD_DEPRECATED_SINCE(5, 70) | ||||
1167 | int Wallet::readMapList(const QString &key, QMap<QString, QMap<QString, QString> > &value) | 1230 | int Wallet::readMapList(const QString &key, QMap<QString, QMap<QString, QString> > &value) | ||
1168 | { | 1231 | { | ||
1169 | int rc = -1; | 1232 | int rc = -1; | ||
1170 | 1233 | | |||
1171 | #if HAVE_KSECRETSSERVICE | 1234 | #if HAVE_KSECRETSSERVICE | ||
1172 | if (walletLauncher()->m_useKSecretsService) { | 1235 | if (walletLauncher()->m_useKSecretsService) { | ||
1173 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoMapList(value)); | 1236 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoMapList(value)); | ||
1174 | } else { | 1237 | } else { | ||
Show All 20 Lines | 1247 | if (r.isValid()) { | |||
1195 | } | 1258 | } | ||
1196 | } | 1259 | } | ||
1197 | #if HAVE_KSECRETSSERVICE | 1260 | #if HAVE_KSECRETSSERVICE | ||
1198 | } | 1261 | } | ||
1199 | #endif | 1262 | #endif | ||
1200 | 1263 | | |||
1201 | return rc; | 1264 | return rc; | ||
1202 | } | 1265 | } | ||
1266 | #endif | ||||
1267 | | ||||
1268 | int Wallet::mapList(QMap<QString, QMap<QString, QString> > &value) | ||||
1269 | { | ||||
1270 | int rc = -1; | ||||
1271 | | ||||
1272 | #if HAVE_KSECRETSSERVICE | ||||
1273 | if (walletLauncher()->m_useKSecretsService) { | ||||
1274 | rc = d->checkItems(WalletPrivate::InsertIntoMapList(value)); | ||||
1275 | } else { | ||||
1276 | #endif | ||||
1277 | registerTypes(); | ||||
1278 | | ||||
1279 | if (d->handle == -1) { | ||||
1280 | return rc; | ||||
1281 | } | ||||
1282 | | ||||
1283 | QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().mapList(d->handle, d->folder, appid()); | ||||
1284 | if (reply.isValid()) { | ||||
1285 | rc = 0; | ||||
1286 | const QVariantMap val = reply.value(); | ||||
1287 | for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) { | ||||
1288 | QByteArray mapData = it.value().toByteArray(); | ||||
1289 | if (!mapData.isEmpty()) { | ||||
1290 | QDataStream ds(&mapData, QIODevice::ReadOnly); | ||||
1291 | QMap<QString, QString> v; | ||||
1292 | ds >> v; | ||||
1293 | value.insert(it.key(), v); | ||||
1294 | } | ||||
1295 | } | ||||
1296 | } | ||||
1297 | #if HAVE_KSECRETSSERVICE | ||||
1298 | } | ||||
1299 | #endif | ||||
1300 | | ||||
1301 | return rc; | ||||
1302 | } | ||||
1203 | 1303 | | |||
1204 | int Wallet::readPassword(const QString &key, QString &value) | 1304 | int Wallet::readPassword(const QString &key, QString &value) | ||
1205 | { | 1305 | { | ||
1206 | int rc = -1; | 1306 | int rc = -1; | ||
1207 | 1307 | | |||
1208 | #if HAVE_KSECRETSSERVICE | 1308 | #if HAVE_KSECRETSSERVICE | ||
1209 | if (walletLauncher()->m_useKSecretsService) { | 1309 | if (walletLauncher()->m_useKSecretsService) { | ||
1210 | rc = d->readEntry<QString>(key, value); | 1310 | rc = d->readEntry<QString>(key, value); | ||
Show All 27 Lines | 1336 | if (d->readEntry<QString>(label, pwd) == 0) { | |||
1238 | result = true; | 1338 | result = true; | ||
1239 | } | 1339 | } | ||
1240 | return result; | 1340 | return result; | ||
1241 | } | 1341 | } | ||
1242 | QMap< QString, QString > &_value; | 1342 | QMap< QString, QString > &_value; | ||
1243 | }; | 1343 | }; | ||
1244 | #endif | 1344 | #endif | ||
1245 | 1345 | | |||
1346 | #if KWALLET_BUILD_DEPRECATED_SINCE(5, 70) | ||||
1246 | int Wallet::readPasswordList(const QString &key, QMap<QString, QString> &value) | 1347 | int Wallet::readPasswordList(const QString &key, QMap<QString, QString> &value) | ||
1247 | { | 1348 | { | ||
1248 | int rc = -1; | 1349 | int rc = -1; | ||
1249 | 1350 | | |||
1250 | #if HAVE_KSECRETSSERVICE | 1351 | #if HAVE_KSECRETSSERVICE | ||
1251 | if (walletLauncher()->m_useKSecretsService) { | 1352 | if (walletLauncher()->m_useKSecretsService) { | ||
1252 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoPasswordList(value)); | 1353 | rc = d->forEachItemThatMatches(key, WalletPrivate::InsertIntoPasswordList(value)); | ||
1253 | } else { | 1354 | } else { | ||
Show All 13 Lines | 1363 | if (r.isValid()) { | |||
1267 | } | 1368 | } | ||
1268 | } | 1369 | } | ||
1269 | #if HAVE_KSECRETSSERVICE | 1370 | #if HAVE_KSECRETSSERVICE | ||
1270 | } | 1371 | } | ||
1271 | #endif | 1372 | #endif | ||
1272 | 1373 | | |||
1273 | return rc; | 1374 | return rc; | ||
1274 | } | 1375 | } | ||
1376 | #endif | ||||
1377 | | ||||
1378 | int Wallet::passwordList(QMap<QString, QString> &value) | ||||
1379 | { | ||||
1380 | int rc = -1; | ||||
1381 | | ||||
1382 | #if HAVE_KSECRETSSERVICE | ||||
1383 | if (walletLauncher()->m_useKSecretsService) { | ||||
1384 | rc = d->checkItems(WalletPrivate::InsertIntoPasswordList(value)); | ||||
1385 | } else { | ||||
1386 | #endif | ||||
1387 | registerTypes(); | ||||
1388 | | ||||
1389 | if (d->handle == -1) { | ||||
1390 | return rc; | ||||
1391 | } | ||||
1392 | | ||||
1393 | QDBusReply<QVariantMap> reply = walletLauncher()->getInterface().passwordList(d->handle, d->folder, appid()); | ||||
1394 | if (reply.isValid()) { | ||||
1395 | rc = 0; | ||||
1396 | const QVariantMap val = reply.value(); | ||||
1397 | for (QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it) { | ||||
1398 | value.insert(it.key(), it.value().toString()); | ||||
1399 | } | ||||
1400 | } | ||||
1401 | #if HAVE_KSECRETSSERVICE | ||||
1402 | } | ||||
1403 | #endif | ||||
1404 | | ||||
1405 | return rc; | ||||
1406 | } | ||||
1275 | 1407 | | |||
1276 | int Wallet::writeEntry(const QString &key, const QByteArray &value, EntryType entryType) | 1408 | int Wallet::writeEntry(const QString &key, const QByteArray &value, EntryType entryType) | ||
1277 | { | 1409 | { | ||
1278 | int rc = -1; | 1410 | int rc = -1; | ||
1279 | 1411 | | |||
1280 | #if HAVE_KSECRETSSERVICE | 1412 | #if HAVE_KSECRETSSERVICE | ||
1281 | if (walletLauncher()->m_useKSecretsService) { | 1413 | if (walletLauncher()->m_useKSecretsService) { | ||
1282 | rc = d->writeEntry(key, value, entryType); | 1414 | rc = d->writeEntry(key, value, entryType); | ||
▲ Show 20 Lines • Show All 397 Lines • Show Last 20 Lines |
Urgh. This actually calls for async API instead.
But now I'm really confused. HAVE_KSECRETSSERVICE is never set anywhere (except to 0), how does one even compile this code?