From 5432045b37571996e3e11e35c3f1c793bb2cb416 Mon Sep 17 00:00:00 2001 From: arjen Date: Fri, 6 Dec 2002 22:30:50 +0000 Subject: [PATCH] Added new arguments to gnucomo_config::Database(): user and password. If empty, default values are taken from the config file. --- src/include/gnucomo_config.h | 14 +++++++----- src/lib/gnucomo_config.cpp | 45 ++++++++++++++++++++++++++++---------- src/phpclasses/gnucomo_config.php | 30 ++++++++++++++++++------- src/web/classes/gnucomo_config.php | 30 ++++++++++++++++++------- 4 files changed, 86 insertions(+), 33 deletions(-) diff --git a/src/include/gnucomo_config.h b/src/include/gnucomo_config.h index ade6ac3..68558f7 100644 --- a/src/include/gnucomo_config.h +++ b/src/include/gnucomo_config.h @@ -8,7 +8,7 @@ *********************** ** FILE NAME : gnucomo.h ** SYSTEM NAME : -** VERSION NUMBER : $Revision: 1.2 $ +** VERSION NUMBER : $Revision: 1.3 $ ** ** DESCRIPTION : ** @@ -26,7 +26,11 @@ /***************************** $Log: gnucomo_config.h,v $ - Revision 1.2 2002-11-09 08:04:27 arjen + Revision 1.3 2002-12-06 22:30:50 arjen + Added new arguments to gnucomo_config::Database(): user and password. + If empty, default values are taken from the config file. + + Revision 1.2 2002/11/09 08:04:27 arjen Added a reference to the GPL Revision 1.1 2002/10/05 10:25:49 arjen @@ -34,7 +38,7 @@ *****************************/ -/* static const char *RCSID = "$Id: gnucomo_config.h,v 1.2 2002-11-09 08:04:27 arjen Exp $"; */ +/* static const char *RCSID = "$Id: gnucomo_config.h,v 1.3 2002-12-06 22:30:50 arjen Exp $"; */ #include @@ -50,7 +54,7 @@ // // RELATIONS : // SEE ALSO : -// LAST MODIFIED : +// LAST MODIFIED : Nov 21, 2002 /////////////////////////////////////////////////////////////////////////// */ @@ -59,6 +63,6 @@ class gnucomo_config : public configuration public: - String Database(); // Return the database access string. + String Database(String usr="", String pw=""); // Return the database access string. }; diff --git a/src/lib/gnucomo_config.cpp b/src/lib/gnucomo_config.cpp index 4e45b82..f1cb57d 100644 --- a/src/lib/gnucomo_config.cpp +++ b/src/lib/gnucomo_config.cpp @@ -8,7 +8,7 @@ *********************** ** FILE NAME : gnucomo_config.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.3 $ +** VERSION NUMBER : $Revision: 1.4 $ ** ** DESCRIPTION : Implementation of the gnucomo_config class. ** @@ -26,7 +26,11 @@ /***************************** $Log: gnucomo_config.cpp,v $ - Revision 1.3 2002-11-09 08:04:27 arjen + Revision 1.4 2002-12-06 22:32:11 arjen + Added new arguments to gnucomo_config::Database(): user and password. + If empty, default values are taken from the config file. + + Revision 1.3 2002/11/09 08:04:27 arjen Added a reference to the GPL Revision 1.2 2002/11/04 10:13:36 arjen @@ -37,7 +41,7 @@ *****************************/ -static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.3 2002-11-09 08:04:27 arjen Exp $"; +static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.4 2002-12-06 22:32:11 arjen Exp $"; #include "gnucomo_config.h" @@ -49,17 +53,19 @@ static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.3 2002-11-09 08:04:27 ar ** PARAMETERS : ** RETURN VALUE : The database access string ** -** DESCRIPTION : +** DESCRIPTION : If the parameters 'usr' and 'pw' are empty, the +** username and password from the configuration file +** are used. ** ** VARS USED : ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : Nov 02, 2002 +** LAST MODIFIED : Nov 21, 2002 **========================================================================= */ -String gnucomo_config::Database() +String gnucomo_config::Database(String usr, String pw) { String param; String access_string(""); @@ -70,15 +76,30 @@ String gnucomo_config::Database() access_string += "dbname=" + param; } - param = find_parameter("database", "user"); - if (param != "") + if (usr == "") { - access_string += " user=" + param; + param = find_parameter("database", "user"); + if (param != "") + { + access_string += " user=" + param; + } } - param = find_parameter("database", "password"); - if (param != "") + else + { + access_string += " user=" + usr; + } + + if (pw == "") + { + param = find_parameter("database", "password"); + if (param != "") + { + access_string += " password=" + param; + } + } + else { - access_string += " password=" + param; + access_string += " password=" + pw; } param = find_parameter("database", "host"); diff --git a/src/phpclasses/gnucomo_config.php b/src/phpclasses/gnucomo_config.php index 8453adb..507a462 100644 --- a/src/phpclasses/gnucomo_config.php +++ b/src/phpclasses/gnucomo_config.php @@ -19,7 +19,7 @@ require_once('configuration.class.php'); // // RELATIONS : // SEE ALSO : -// LAST MODIFIED : Sep 26, 2002 +// LAST MODIFIED : Nov 21, 2002 /////////////////////////////////////////////////////////////////////////// */ @@ -28,7 +28,7 @@ class gnucomo_config extends configuration // Return the database access string. - function Database() + function Database($usr = "", $pw = "") { $access_string = ""; @@ -38,16 +38,30 @@ class gnucomo_config extends configuration $access_string .= "dbname=" . $param; } - $param = $this->find_parameter("database", "user"); - if ($param != "") + if ($usr == "") + { + $param = $this->find_parameter("database", "user"); + if ($param != "") + { + $access_string .= " user=" . $param; + } + } + else { - $access_string .= " user=" . $param; + $access_string .= " user=" . $usr; } - $param = $this->find_parameter("database", "password"); - if ($param != "") + if ($pw == "") + { + $param = $this->find_parameter("database", "password"); + if ($param != "") + { + $access_string .= " password=" . $param; + } + } + else { - $access_string .= " password=" . $param; + $access_string .= " password=" . $pw; } $param = $this->find_parameter("database", "host"); diff --git a/src/web/classes/gnucomo_config.php b/src/web/classes/gnucomo_config.php index 8453adb..507a462 100644 --- a/src/web/classes/gnucomo_config.php +++ b/src/web/classes/gnucomo_config.php @@ -19,7 +19,7 @@ require_once('configuration.class.php'); // // RELATIONS : // SEE ALSO : -// LAST MODIFIED : Sep 26, 2002 +// LAST MODIFIED : Nov 21, 2002 /////////////////////////////////////////////////////////////////////////// */ @@ -28,7 +28,7 @@ class gnucomo_config extends configuration // Return the database access string. - function Database() + function Database($usr = "", $pw = "") { $access_string = ""; @@ -38,16 +38,30 @@ class gnucomo_config extends configuration $access_string .= "dbname=" . $param; } - $param = $this->find_parameter("database", "user"); - if ($param != "") + if ($usr == "") + { + $param = $this->find_parameter("database", "user"); + if ($param != "") + { + $access_string .= " user=" . $param; + } + } + else { - $access_string .= " user=" . $param; + $access_string .= " user=" . $usr; } - $param = $this->find_parameter("database", "password"); - if ($param != "") + if ($pw == "") + { + $param = $this->find_parameter("database", "password"); + if ($param != "") + { + $access_string .= " password=" . $param; + } + } + else { - $access_string .= " password=" . $param; + $access_string .= " password=" . $pw; } $param = $this->find_parameter("database", "host"); -- 2.11.0