| 52 | |
| 53 | |
| 54 | void PluginDatabases::getInstance(IPluginConfig* pluginConfig, CachedSecurityDatabase::Instance& instance) |
| 55 | { |
| 56 | // Determine sec.db name based on existing config |
| 57 | PathName secDbName; |
| 58 | { // config scope |
| 59 | FbLocalStatus s; |
| 60 | RefPtr<IFirebirdConf> config(REF_NO_INCR, pluginConfig->getFirebirdConf(&s)); |
| 61 | check(&s); |
| 62 | |
| 63 | static GlobalPtr<ConfigKeys> keys; |
| 64 | unsigned int secDbKey = keys->getKey(config, "SecurityDatabase"); |
| 65 | const char* tmp = config->asString(secDbKey); |
| 66 | if (!tmp) |
| 67 | Arg::Gds(isc_secdb_name).raise(); |
| 68 | |
| 69 | secDbName = tmp; |
| 70 | } |
| 71 | |
| 72 | { // guard scope |
| 73 | MutexLockGuard g(arrayMutex, FB_FUNCTION); |
| 74 | for (unsigned int i = 0; i < dbArray.getCount(); ) |
| 75 | { |
| 76 | if (secDbName == dbArray[i]->secureDbName) |
| 77 | { |
| 78 | CachedSecurityDatabase* fromCache = dbArray[i]; |
| 79 | // if element is just created or test passed we can use it |
| 80 | if ((!fromCache->secDb) || fromCache->secDb->test()) |
| 81 | { |
| 82 | instance.set(fromCache); |
| 83 | break; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | dbArray.remove(i); |
| 88 | continue; |
| 89 | } |
| 90 | } |
| 91 | ++i; |
| 92 | } |
| 93 | |
| 94 | if (!instance) |
| 95 | { |
| 96 | instance.set(FB_NEW CachedSecurityDatabase(this, secDbName)); |
| 97 | secDbName.copyTo(instance->secureDbName, sizeof(instance->secureDbName)); |
| 98 | dbArray.add(instance); |
| 99 | instance->addRef(); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | int PluginDatabases::shutdown() |
| 105 | { |