2002-06-04 14:57:05 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: JRD Access Method
|
|
|
|
* MODULE: db_alias.cpp
|
|
|
|
* DESCRIPTION: Server-side database aliases
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*
|
|
|
|
* 2002.06.04 Dmitry Yemanov - Server-side database alias management.
|
|
|
|
*/
|
2003-02-17 11:38:48 +01:00
|
|
|
#include "firebird.h"
|
2002-06-04 14:57:05 +02:00
|
|
|
|
2002-08-26 09:51:31 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2002-11-06 16:13:02 +01:00
|
|
|
#include "../common/config/config.h"
|
|
|
|
#include "../common/config/config_file.h"
|
2002-08-26 09:51:31 +02:00
|
|
|
#include "../jrd/os/path_utils.h"
|
2003-01-16 18:47:10 +01:00
|
|
|
#include "../jrd/gds_proto.h"
|
2002-06-04 14:57:05 +02:00
|
|
|
|
2002-11-06 16:13:02 +01:00
|
|
|
typedef Firebird::string string;
|
|
|
|
|
|
|
|
const char* ALIAS_FILE = "aliases.conf";
|
2002-09-06 10:57:51 +02:00
|
|
|
|
2002-06-12 09:03:02 +02:00
|
|
|
bool ResolveDatabaseAlias(const char* alias, char* database)
|
2002-06-04 14:57:05 +02:00
|
|
|
{
|
2002-09-06 10:57:51 +02:00
|
|
|
TEXT alias_filename[MAXPATHLEN];
|
2002-11-06 16:13:02 +01:00
|
|
|
gds__prefix(alias_filename, const_cast<char*>(ALIAS_FILE));
|
2003-04-19 18:46:24 +02:00
|
|
|
ConfigFile aliasConfig(false);
|
2002-09-06 10:57:51 +02:00
|
|
|
aliasConfig.setConfigFile(alias_filename);
|
2002-08-26 09:51:31 +02:00
|
|
|
|
|
|
|
const char correct_dir_sep = PathUtils::dir_sep;
|
|
|
|
const char incorrect_dir_sep = (correct_dir_sep == '/') ? '\\' : '/';
|
2002-11-06 16:13:02 +01:00
|
|
|
string corrected_alias = alias;
|
2002-08-26 09:51:31 +02:00
|
|
|
std::replace(corrected_alias.begin(), corrected_alias.end(), incorrect_dir_sep, correct_dir_sep);
|
|
|
|
|
2002-11-06 16:13:02 +01:00
|
|
|
string value = aliasConfig.getString(corrected_alias);
|
2002-08-26 09:51:31 +02:00
|
|
|
|
2002-06-04 14:57:05 +02:00
|
|
|
if (!value.empty())
|
|
|
|
{
|
2002-08-26 09:51:31 +02:00
|
|
|
std::replace(value.begin(), value.end(), incorrect_dir_sep, correct_dir_sep);
|
2002-06-04 14:57:05 +02:00
|
|
|
strcpy(database, value.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2002-11-06 16:13:02 +01:00
|
|
|
|
2002-06-04 14:57:05 +02:00
|
|
|
return false;
|
|
|
|
}
|