| 273 | // Therefore it checks only the necessary settings. |
| 274 | |
| 275 | Config* Config::get(const PathName& lookupName) |
| 276 | { |
| 277 | fb_assert(lookupName.hasData()); |
| 278 | |
| 279 | bool reportErrors = DEFAULT_REPORT_ERRORS; |
| 280 | try |
| 281 | { |
| 282 | const PathName filename = |
| 283 | fb_utils::getPrefix(IConfigManager::DIR_CONF, REPLICATION_CFGFILE); |
| 284 | |
| 285 | ConfigFile cfgFile(filename, ConfigFile::HAS_SUB_CONF | |
| 286 | ConfigFile::NATIVE_ORDER | |
| 287 | ConfigFile::CUSTOM_MACROS); |
| 288 | |
| 289 | AutoPtr<Config> config(FB_NEW Config); |
| 290 | |
| 291 | FbLocalStatus localStatus; |
| 292 | bool defaultFound = false, exactMatch = false, replicaSkip = false; |
| 293 | |
| 294 | for (const auto& section : cfgFile.getParameters()) |
| 295 | { |
| 296 | if (section.name != "database") |
| 297 | continue; |
| 298 | |
| 299 | PathName dbName(section.value.c_str()); |
| 300 | |
| 301 | if (dbName.empty()) |
| 302 | { |
| 303 | if (defaultFound) |
| 304 | raiseError("Only one default DATABASE section is allowed"); |
| 305 | |
| 306 | defaultFound = true; |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | PathUtils::fixupSeparators(dbName); |
| 311 | ISC_expand_filename(dbName, true); |
| 312 | |
| 313 | if (dbName != lookupName) |
| 314 | continue; |
| 315 | |
| 316 | config->dbName = dbName; |
| 317 | |
| 318 | exactMatch = true; |
| 319 | } |
| 320 | |
| 321 | if (!section.sub) |
| 322 | continue; |
| 323 | |
| 324 | for (const auto& el : section.sub->getParameters()) |
| 325 | { |
| 326 | const string key(el.name.c_str()); |
| 327 | string value(el.value); |
| 328 | |
| 329 | if (value.isEmpty()) |
| 330 | { |
| 331 | configError(&localStatus, "empty value of key", |
| 332 | exactMatch ? lookupName.c_str() : section.name.c_str(), |
no test coverage detected