| 1295 | { } |
| 1296 | |
| 1297 | bool Mapping::ensureCachePresence(RefPtr<Mapping::Cache>& cache, const char* alias, const char* target, |
| 1298 | Mapping::DbHandle& hdb, ICryptKeyCallback* cryptCb, Mapping::Cache* c2) |
| 1299 | { |
| 1300 | fb_assert(!cache); |
| 1301 | fb_assert(authBlock); |
| 1302 | |
| 1303 | if (!(authBlock && authBlock->hasData())) |
| 1304 | return false; |
| 1305 | |
| 1306 | MutexEnsureUnlock g(treeMutex, FB_FUNCTION); |
| 1307 | g.enter(); |
| 1308 | |
| 1309 | // Find cache in the tree or create new one |
| 1310 | locate(cache, alias, target); |
| 1311 | fb_assert(cache); |
| 1312 | |
| 1313 | // If we use self security database no sense performing checks on it twice |
| 1314 | if (cache == c2) |
| 1315 | { |
| 1316 | cache = nullptr; |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | // Required cache(s) are locked somehow - release treeMutex |
| 1321 | g.leave(); |
| 1322 | |
| 1323 | // Std safe check for data presence in cache |
| 1324 | if (cache->dataFlag) |
| 1325 | return false; |
| 1326 | MutexLockGuard g2(cache->populateMutex, FB_FUNCTION); |
| 1327 | if (cache->dataFlag) |
| 1328 | return false; |
| 1329 | |
| 1330 | // Create db attachment if missing it and populate cache from it |
| 1331 | bool down = hdb.attach(alias, cryptCb) || cache->populate(hdb); |
| 1332 | if (down) |
| 1333 | cache = nullptr; |
| 1334 | return down; |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | void Mapping::needAuthMethod(Firebird::string& method) |