From 83f8c38cf0bff4de522d7754e76e9e55f34b9f9b Mon Sep 17 00:00:00 2001 From: skywalker Date: Mon, 20 Aug 2001 08:15:33 +0000 Subject: [PATCH] Partial change to load RootDirectory from /etc/firebird.conf file plus some more install/compile things --- src/fbutil/FirebirdConfig.cpp | 183 +++---------------------- src/fbutil/FirebirdConfig.h | 31 +++-- src/fbutil/FirebirdConfigFile.cpp | 208 +++++++++++++++++++++++++++++ src/fbutil/FirebirdConfigFile.h | 38 ++++++ src/install/Makefile.in | 6 +- src/install/classic/CSinstall.sh | 13 +- src/jrd/file_params.h | 4 +- src/jrd/gds.cpp | 43 ++++-- src/jrd/isc.cpp | 5 +- src/make.new/Makefile.in.firebird | 11 +- src/make.new/make.defaults | 6 +- src/make.new/make.rules | 6 +- src/make.new/make.shared.variables | 2 +- 13 files changed, 342 insertions(+), 214 deletions(-) create mode 100644 src/fbutil/FirebirdConfigFile.cpp create mode 100644 src/fbutil/FirebirdConfigFile.h diff --git a/src/fbutil/FirebirdConfig.cpp b/src/fbutil/FirebirdConfig.cpp index aac8678b75..7d9010183a 100644 --- a/src/fbutil/FirebirdConfig.cpp +++ b/src/fbutil/FirebirdConfig.cpp @@ -1,74 +1,21 @@ #include "firebird.h" #include "FirebirdConfig.h" +#include "FirebirdConfigFile.h" #ifdef HAVE_STDLIB_H #include #endif + //----------------------------------------------------------------------------- // // The instance of the static class variable. // -FirebirdConfig FirebirdConfig::sysConfig; - - -//----------------------------------------------------------------------------- -// -// -// - -void stripLeadingWhiteSpace(string& s) -{ - if (!s.size()) { - return; - } - - const string::size_type startPos = s.find_first_not_of(" \t"); - if (startPos == string::npos) { - s.erase(); // nothing but air - } else if (startPos) { - s = s.substr(startPos); - } -} - -//----------------------------------------------------------------------------- -// -// -// - -void stripTrailingWhiteSpace(string& s) -{ - if (!s.size()) { - return; - } - - string::size_type endPos = s.find_last_not_of(" \t"); - if (endPos != string::npos) { - // Note that endPos is the index to the last non-ws char - // why we have to inc. it - ++endPos; - s = s.substr(0, endPos); - } -} - -//----------------------------------------------------------------------------- -// -// -// - -void stripComments(string& s) -{ - // Note that this is only a hack. It won't work in case inputLine - // contains hash-marks embedded in quotes! Not that I know if we - // should care about that case. - const string::size_type commentPos = s.find('#'); - if (commentPos != string::npos) { - s = s.substr(0, commentPos); - } -} +static FirebirdConfigFile sysConfig; +//static FirebirdConfigReg sysConfig; // I would expect win32 to have this one. //----------------------------------------------------------------------------- // @@ -93,123 +40,23 @@ int FirebirdConfig::getSysInt(const string& key) { // // // - -string FirebirdConfig::getString(const string& key) { - - mymap_t::iterator lookup; - - lookup = parameters.find(key); - - if (lookup != parameters.end()) { - return lookup->second; - } - - return string(); -} - -//----------------------------------------------------------------------------- -// -// -// - -int FirebirdConfig::getInt(const string& key) { - string data = getString(key); - - if (data.empty()) { - return 0; - } - - return atoi(data.data()); -} - - - -//----------------------------------------------------------------------------- -// -// -// - -string parseKeyFrom(const string& inputLine, string::size_type& endPos) { - - endPos = inputLine.find_first_of("= \t"); - if (endPos == string::npos) { - return inputLine; - } - - return inputLine.substr(0, endPos); -} - - - -//----------------------------------------------------------------------------- -// -// -// - -string parseValueFrom(string inputLine, string::size_type initialPos) { - - if (initialPos == string::npos) { - return string(); - } - - // skip leading white spaces - int startPos = inputLine.find_first_not_of("= \t", initialPos); - if (startPos == string::npos) { - return string(); - } - - stripTrailingWhiteSpace(inputLine); - return inputLine.substr(startPos); - -} - - -//----------------------------------------------------------------------------- -// -// -// - void FirebirdConfig::loadSysConfig() { - sysConfig.loadConfig(); + sysConfig.loadConfig(); } //----------------------------------------------------------------------------- // // // - -void FirebirdConfig::loadConfig() { - - ifstream configFile("/etc/firebird.conf"); - - string inputLine; - - while (!configFile.eof()) { - getline(configFile, inputLine); - - stripComments(inputLine); - stripLeadingWhiteSpace(inputLine); - - if (!inputLine.size()) { - continue; // comment-line or empty line - } - - // cout << "read \"" << inputLine << "\"\n"; - - if (inputLine.find('=') == string::npos) { - cerr << "illegal line \"" << inputLine << "\"" << endl; - continue; - } - - string::size_type endPos; - - string key = parseKeyFrom(inputLine, endPos); - string value = parseValueFrom(inputLine, endPos); - - cout << "adding \"" << key << "\" \"" << value << "\"" << endl; -// parameters.insert(pair(key, value)); -// Just to display yet another template function - parameters.insert(make_pair(key, value)); - } +const string FirebirdConfig::getSysConfigFile() { + return sysConfig.getConfigFile(); +} + +//----------------------------------------------------------------------------- +// +// +// +void FirebirdConfig::setSysConfigFile(const string& newFile) { + sysConfig.setConfigFile(newFile); } diff --git a/src/fbutil/FirebirdConfig.h b/src/fbutil/FirebirdConfig.h index a01202ca5f..33b75d887b 100644 --- a/src/fbutil/FirebirdConfig.h +++ b/src/fbutil/FirebirdConfig.h @@ -4,27 +4,32 @@ #include #include -#include #include class FirebirdConfig { public: - static string getSysString(const string& key); - static int getSysInt(const string& key); - static void loadSysConfig(); - void loadConfig(); - string getString(const string& key); - int getInt(const string& key); + static string getSysString(const string& key); + static int getSysInt(const string& key); + static void loadSysConfig(); + static const string getSysConfigFile(); + static void setSysConfigFile(const string& newFile); -private: - typedef pair mypair; - typedef map mymap_t; - mymap_t parameters; - - static FirebirdConfig sysConfig; + FirebirdConfig() {} + virtual const string getConfigFile()= 0; + virtual void setConfigFile(const string& newFile)= 0; + + virtual bool getIsLoadedFlg()= 0; + virtual void setIsLoadedFlg(bool newFlg)= 0; + + virtual void loadConfig()= 0; + virtual void checkLoadConfig()= 0; + virtual string getString(const string& key) = 0; + virtual int getInt(const string& key) = 0; + + virtual ~FirebirdConfig() {} }; diff --git a/src/fbutil/FirebirdConfigFile.cpp b/src/fbutil/FirebirdConfigFile.cpp new file mode 100644 index 0000000000..282aba769a --- /dev/null +++ b/src/fbutil/FirebirdConfigFile.cpp @@ -0,0 +1,208 @@ +#include "firebird.h" +#include "FirebirdConfigFile.h" + +#ifdef HAVE_STDLIB_H +#include +#endif + + + + + +//----------------------------------------------------------------------------- +// +// +// +FirebirdConfigFile::FirebirdConfigFile() +{ + isLoadedFlg = false; + configFile = "/etc/firebird.conf"; +} + +//----------------------------------------------------------------------------- +// +// +// + +void stripLeadingWhiteSpace(string& s) +{ + if (!s.size()) { + return; + } + + const string::size_type startPos = s.find_first_not_of(" \t"); + if (startPos == string::npos) { + s.erase(); // nothing but air + } else if (startPos) { + s = s.substr(startPos); + } +} + +//----------------------------------------------------------------------------- +// +// +// + +void stripTrailingWhiteSpace(string& s) +{ + if (!s.size()) { + return; + } + + string::size_type endPos = s.find_last_not_of(" \t"); + if (endPos != string::npos) { + // Note that endPos is the index to the last non-ws char + // why we have to inc. it + ++endPos; + s = s.substr(0, endPos); + } +} + +//----------------------------------------------------------------------------- +// +// +// + +void stripComments(string& s) +{ + // Note that this is only a hack. It won't work in case inputLine + // contains hash-marks embedded in quotes! Not that I know if we + // should care about that case. + const string::size_type commentPos = s.find('#'); + if (commentPos != string::npos) { + s = s.substr(0, commentPos); + } +} + + +//----------------------------------------------------------------------------- +// +// +// + +string FirebirdConfigFile::getString(const string& key) { + + checkLoadConfig(); + + mymap_t::iterator lookup; + + lookup = parameters.find(key); + + if (lookup != parameters.end()) { + return lookup->second; + } + + return string(); +} + +//----------------------------------------------------------------------------- +// +// +// + +int FirebirdConfigFile::getInt(const string& key) { + + checkLoadConfig(); + + string data = getString(key); + + if (data.empty()) { + return 0; + } + + return atoi(data.data()); +} + + + +//----------------------------------------------------------------------------- +// +// +// + +string parseKeyFrom(const string& inputLine, string::size_type& endPos) { + + endPos = inputLine.find_first_of("= \t"); + if (endPos == string::npos) { + return inputLine; + } + + return inputLine.substr(0, endPos); +} + + + +//----------------------------------------------------------------------------- +// +// +// + +string parseValueFrom(string inputLine, string::size_type initialPos) { + + if (initialPos == string::npos) { + return string(); + } + + // skip leading white spaces + unsigned int startPos = inputLine.find_first_not_of("= \t", initialPos); + if (startPos == string::npos) { + return string(); + } + + stripTrailingWhiteSpace(inputLine); + return inputLine.substr(startPos); + +} + + +//----------------------------------------------------------------------------- +// +// +// + +void FirebirdConfigFile::checkLoadConfig() { + if (!isLoadedFlg) { + loadConfig(); + } +} + +//----------------------------------------------------------------------------- +// +// +// + +void FirebirdConfigFile::loadConfig() { + + ifstream configFile(configFile.c_str()); + + string inputLine; + + while (!configFile.eof()) { + getline(configFile, inputLine); + + stripComments(inputLine); + stripLeadingWhiteSpace(inputLine); + + if (!inputLine.size()) { + continue; // comment-line or empty line + } + + // cout << "read \"" << inputLine << "\"\n"; + + if (inputLine.find('=') == string::npos) { + cerr << "illegal line \"" << inputLine << "\"" << endl; + continue; + } + + string::size_type endPos; + + string key = parseKeyFrom(inputLine, endPos); + string value = parseValueFrom(inputLine, endPos); + + cout << "adding \"" << key << "\" \"" << value << "\"" << endl; +// parameters.insert(pair(key, value)); +// Just to display yet another template function + parameters.insert(make_pair(key, value)); + } +} + diff --git a/src/fbutil/FirebirdConfigFile.h b/src/fbutil/FirebirdConfigFile.h new file mode 100644 index 0000000000..b140313f7f --- /dev/null +++ b/src/fbutil/FirebirdConfigFile.h @@ -0,0 +1,38 @@ + +#ifndef _FirebirdConfigFile_H +#define _FirebirdConfigFile_H + +#include +#include +#include +#include + +#include "FirebirdConfig.h" + +class FirebirdConfigFile : FirebirdConfig { +public: + + FirebirdConfigFile(); + + const string getConfigFile() { return configFile; } + void setConfigFile(const string& newFile) { configFile = newFile; } + + bool getIsLoadedFlg() { return isLoadedFlg; } + void setIsLoadedFlg(bool newFlg) { isLoadedFlg = newFlg; } + + void loadConfig(); + void checkLoadConfig(); + string getString(const string& key); + int getInt(const string& key); + +private: + string configFile; + bool isLoadedFlg; + typedef pair mypair; + typedef map mymap_t; + + mymap_t parameters; + +}; + +#endif diff --git a/src/install/Makefile.in b/src/install/Makefile.in index 4e414fa8b3..12d47fdffa 100644 --- a/src/install/Makefile.in +++ b/src/install/Makefile.in @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in,v 1.5 2001-08-15 18:10:35 skywalker Exp $ +# $Id: Makefile.in,v 1.6 2001-08-20 08:15:32 skywalker Exp $ # ROOT=../.. @@ -38,11 +38,15 @@ include $(ROOT)/src/make.defaults include $(ROOT)/src/make.platform include $(ROOT)/src/make.shared.variables + FirebirdInstallPrefix=@prefix@ @SET_MAKE@ +FIREBIRD=$(FirebirdInstallPrefix)/firebird +export -n FIREBIRD +export -n INTERBASE .PHONY: all CSrpmscript SSrpmscript ssinstall runclassicinstall \ classicpackages diff --git a/src/install/classic/CSinstall.sh b/src/install/classic/CSinstall.sh index 6110c6bcf1..6b9e798e2e 100755 --- a/src/install/classic/CSinstall.sh +++ b/src/install/classic/CSinstall.sh @@ -87,26 +87,25 @@ cp -f $BuildDir/include/ibase.h /usr/include/ibase.h cp -f $BuildDir/include/ib_util.h /usr/include/ib_util.h - cp $BuildDir/include/gds.f $DestDir/include - cp $BuildDir/include/gds.hxx $DestDir/include +# cp $BuildDir/include/gds.f $DestDir/include +# cp $BuildDir/include/gds.hxx $DestDir/include cp $BuildDir/include/*.h $DestDir/include - cp -f $BuildDir/lib/gds.so /usr/lib/libgds.so.0 + cp -f $BuildDir/lib/libgds.so /usr/lib/libgds.so.0 if [ -L /usr/lib/libgds.so ] then rm -f /usr/lib/libgds.so fi ln -s libgds.so.0 /usr/lib/libgds.so - cp -f $BuildDir/lib/gds.a /usr/lib/libgds.a +# cp -f $BuildDir/lib/gds.a /usr/lib/libgds.a cp -f $BuildDir/lib/ib_util.so /usr/lib/libib_util.so cp $BuildDir/intl/libgdsintl.so $DestDir/intl/ - cp $BuildDir/UDF/ib_udf $DestDir/UDF/ib_udf + cp $BuildDir/UDF/ib_udf.so $DestDir/UDF/ - cp $BuildDir/services.isc $DestDir/services.isc - cp $BuildDir/README $DestDir/README +# cp $BuildDir/README $DestDir/README cp $BuildDir/misc/firebird.xinetd $DestDir/misc/firebird.xinetd diff --git a/src/jrd/file_params.h b/src/jrd/file_params.h index dccc68729a..e9968060b0 100644 --- a/src/jrd/file_params.h +++ b/src/jrd/file_params.h @@ -124,14 +124,14 @@ #ifdef UNIX #define WORKFILE "/tmp/" #ifdef LINUX -#define ISC_PREFIX "/usr/local/interbase/" +#define ISC_PREFIX "/usr/local/firebird/" #else #ifdef DARWIN #define ISC_PREFIX "/all/files/are/in/framework/resources" #define DARWIN_GEN_DIR "var" #define DARWIN_FRAMEWORK_ID "com.firebird.Firebird2" #else -#define ISC_PREFIX "/usr/interbase/" +#define ISC_PREFIX "/usr/local/firebird/" #endif #endif #endif diff --git a/src/jrd/gds.cpp b/src/jrd/gds.cpp index 9beac0c455..27ebf643c4 100644 --- a/src/jrd/gds.cpp +++ b/src/jrd/gds.cpp @@ -97,6 +97,9 @@ #endif /* VMS */ + +#include "fbutil/FirebirdConfig.h" + /* Turn on V4 mutex protection for gds__alloc/free */ #ifdef WIN_NT @@ -608,7 +611,7 @@ static const UCHAR rid[] = { op_word, op_byte, op_line, 0}, rid2[] = { op_word, op_byte, op_literal, op_pad, op_byte, op_line, 0}, union_ops[] = { op_byte, op_byte, op_line, op_union, 0}, - map[] = { op_word, op_line, op_map, 0}, + map[] = { op_word, op_line, op_map, 0}, function[] = { op_byte, op_literal, op_byte, op_line, op_args, 0}, gen_id[] = { op_byte, op_literal, op_line, op_verb, 0}, declare[] = { op_word, op_dtype, op_line, 0}, @@ -2368,7 +2371,7 @@ SLONG API_ROUTINE gds__get_prefix(SSHORT arg_type, TEXT * passed_string) #ifndef VMS -void API_ROUTINE gds__prefix(TEXT * string, TEXT * root) +void API_ROUTINE gds__prefix(TEXT * resultString, TEXT * root) { /************************************** * @@ -2388,15 +2391,13 @@ void API_ROUTINE gds__prefix(TEXT * string, TEXT * root) CFStringRef msgFilePath; #endif - string[0] = 0; + resultString[0] = 0; if (ib_prefix == NULL) { - if ( !(ib_prefix = getenv(ISC_ENV)) || ib_prefix[0] == 0) - { + if ( !(ib_prefix = getenv(ISC_ENV)) || ib_prefix[0] == 0) { #if defined(WIN_NT) ib_prefix = ib_prefix_val; - if (ISC_get_registry_var("RootDirectory", ib_prefix, MAXPATHLEN, 0) != -1) - { + if (ISC_get_registry_var("RootDirectory", ib_prefix, MAXPATHLEN, 0) != -1) { TEXT *p = ib_prefix + strlen(ib_prefix); if (p != ib_prefix) if (p[-1] == '\\') @@ -2436,19 +2437,33 @@ void API_ROUTINE gds__prefix(TEXT * string, TEXT * root) else #endif { - ib_prefix = ISC_PREFIX; - strcat(ib_prefix_val, ib_prefix); - } + // Try and get value from config file. + const string regPrefix = FirebirdConfig::getSysString("RootDirectory"); + int len = regPrefix.length(); + if ( len > 0) { + if (len > sizeof(ib_prefix_val)) { + ib_perror("ib_prefix path size too large - truncated"); + } + strncpy(ib_prefix_val, regPrefix.c_str(), sizeof(ib_prefix_val) -1); + ib_prefix_val[sizeof(ib_prefix_val) -1] = 0; + ib_prefix = ib_prefix_val; + } + else { + ib_prefix = ISC_PREFIX; + strcat(ib_prefix_val, ib_prefix); + } + } #endif ib_prefix = ib_prefix_val; } } - strcat(string, ib_prefix); + strcat(resultString, ib_prefix); + #ifndef NETWARE_386 - if (string[strlen(string) - 1] != '/') - strcat(string, "/"); + if (resultString[strlen(resultString) - 1] != '/') + strcat(resultString, "/"); #endif - strcat(string, root); + strcat(resultString, root); } #endif /* !defined(VMS) */ diff --git a/src/jrd/isc.cpp b/src/jrd/isc.cpp index bb6a5e048f..62352b05fa 100644 --- a/src/jrd/isc.cpp +++ b/src/jrd/isc.cpp @@ -24,7 +24,7 @@ * Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden */ /* -$Id: isc.cpp,v 1.3 2001-07-29 17:42:22 skywalker Exp $ +$Id: isc.cpp,v 1.4 2001-08-20 08:15:33 skywalker Exp $ */ #include "firebird.h" @@ -782,6 +782,7 @@ TEXT *INTERNAL_API_ROUTINE ISC_get_host(TEXT * string, USHORT length) #if !defined(WIN_NT) // implemented in isc_win32.cpp #ifdef PC_PLATFORM #ifndef NETWARE_386 + int INTERNAL_API_ROUTINE ISC_get_user(TEXT* name, int* id, int* group, @@ -897,6 +898,8 @@ int INTERNAL_API_ROUTINE ISC_get_user(TEXT* name, return (euid == 0); } + + #endif diff --git a/src/make.new/Makefile.in.firebird b/src/make.new/Makefile.in.firebird index 2180937673..6d2ad743d5 100644 --- a/src/make.new/Makefile.in.firebird +++ b/src/make.new/Makefile.in.firebird @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: Makefile.in.firebird,v 1.7 2001-08-15 18:10:36 skywalker Exp $ +# $Id: Makefile.in.firebird,v 1.8 2001-08-20 08:15:33 skywalker Exp $ # ROOT=.. @@ -40,6 +40,7 @@ include $(ROOT)/src/make.shared.variables ISC_USER= sysdba ISC_PASSWORD= masterkey +LD_LIBRARY_PATH=/home/odonohue/src/firebird2/gen/firebird/lib export ISC_USER export ISC_PASSWORD @@ -187,7 +188,7 @@ isc4.gdb: gdef isql # build the security database phase3: build_alt_use_main jrdlib_main sysdba_user \ gfix gbak gdef msgs isql $(INTL) locks qli inet_server \ gsplit gstat gds_relay gsec gds_drop gpre \ - extlib msgs_intl includes examples + extlib msgs_intl includes examples otherfiles build_alt_use_main: # alter header file so jrd/alt.cpp DOES use security. $(MAKE) -C jrd $@ # alter utilities to build the security objects @@ -234,6 +235,7 @@ examples: includes $(MAKE) -C v5_examples v5_examples +otherfiles: misc_files script_files @@ -367,6 +369,11 @@ $(BIN)/% :: $(SRC_ROOT)/install/misc/% install: $(MAKE) -C install $@ + +packages: + $(MAKE) -C install $@ + + installclassic: $(SRC_ROOT)/install/classic/CSpreinstall.sh # $(SRC_ROOT)/install/classic/CSinstall.sh diff --git a/src/make.new/make.defaults b/src/make.new/make.defaults index 4b7e254c9c..f2ddada74b 100755 --- a/src/make.new/make.defaults +++ b/src/make.new/make.defaults @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: make.defaults,v 1.7 2001-08-13 08:14:38 skywalker Exp $ +# $Id: make.defaults,v 1.8 2001-08-20 08:15:33 skywalker Exp $ # @@ -89,7 +89,9 @@ LIBGDS_A = $(LIB)/libgds.a ifdef UseSharedLibraries LIBGDS_LA = $(LIBGDS_SO) LIBGDS_DEP = - LIBGDS_LINK = $(LIBGDS_SO) +# LIBGDS_LINK = $(LIBGDS_SO) + LIBGDS_LINK = + LINK_LIBS := -L$(LIB) -lgds $(LINK_LIBS) else LIBGDS_LA = $(LIBGDS_A) LIBGDS_DEP = $(LIBGDS_LA) diff --git a/src/make.new/make.rules b/src/make.new/make.rules index 401d82ea94..15d50b6307 100644 --- a/src/make.new/make.rules +++ b/src/make.new/make.rules @@ -26,7 +26,7 @@ # Contributor(s): # # -# $Id: make.rules,v 1.7 2001-08-14 17:41:39 skywalker Exp $ +# $Id: make.rules,v 1.8 2001-08-20 08:15:33 skywalker Exp $ # #____________________________________________________________________________ @@ -121,8 +121,8 @@ else LIB_LINK= ld -shared STATICLIB_LINK= ar cruvs -# LIB_LINK_OPTIONS = -soname libgds.so -rpath /usr/lib - LIB_LINK_OPTIONS = + LIB_LINK_OPTIONS = -soname libgds.so.2 -rpath /usr/lib +# LIB_LINK_OPTIONS = EXE_LINK = @CC@ STATICEXE_LINK = @CXX@ diff --git a/src/make.new/make.shared.variables b/src/make.new/make.shared.variables index dfc86e3b0e..6160d919d1 100644 --- a/src/make.new/make.shared.variables +++ b/src/make.new/make.shared.variables @@ -133,7 +133,7 @@ SECURITY_SharedObjects = $(SECURITY_Objects:.o=.lo) # # fbutil -FBUTIL_Sources=FirebirdConfig.cpp +FBUTIL_Sources=FirebirdConfig.cpp FirebirdConfigFile.cpp FBUTIL_Objects = $(FBUTIL_Sources:%.cpp=$(GEN_ROOT)/fbutil/%.o) FBUTIL_SharedObjects = $(FBUTIL_Objects:.o=.lo)