Added new arguments to gnucomo_config::Database(): user and password.
[gnucomo.git] / src / lib / gnucomo_config.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : gnucomo_config.cpp
10 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
11 **      VERSION NUMBER : $Revision: 1.4 $
12 **
13 **  DESCRIPTION      :  Implementation of the gnucomo_config class.
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Jul 24, 2002
23 **      LAST UPDATE     : Nov 02, 2002
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: gnucomo_config.cpp,v $
29    Revision 1.4  2002-12-06 22:32:11  arjen
30    Added new arguments to gnucomo_config::Database(): user and password.
31    If empty, default values are taken from the config file.
32
33    Revision 1.3  2002/11/09 08:04:27  arjen
34    Added a reference to the GPL
35
36    Revision 1.2  2002/11/04 10:13:36  arjen
37    Use proper namespace for iostream classes
38
39    Revision 1.1  2002/10/05 10:25:49  arjen
40    Creation of gcm_input and a first approach to a web interface
41
42 *****************************/
43
44 static const char *RCSID = "$Id: gnucomo_config.cpp,v 1.4 2002-12-06 22:32:11 arjen Exp $";
45
46 #include "gnucomo_config.h"
47
48
49
50 /*=========================================================================
51 **  NAME           : Database
52 **  SYNOPSIS       : String gnucomo_config::Database()
53 **  PARAMETERS     : 
54 **  RETURN VALUE   : The database access string
55 **
56 **  DESCRIPTION    : If the parameters 'usr' and 'pw' are empty, the
57 **                   username and password from the configuration file
58 **                   are used.
59 **
60 **  VARS USED      :
61 **  VARS CHANGED   :
62 **  FUNCTIONS USED :
63 **  SEE ALSO       :
64 **  LAST MODIFIED  : Nov 21, 2002
65 **=========================================================================
66 */
67
68 String gnucomo_config::Database(String usr, String pw)
69 {
70    String param;
71    String access_string("");
72
73    param = find_parameter("database", "name");
74    if (param != "")
75    {
76       access_string += "dbname=" + param;
77    }
78
79    if (usr == "")
80    {
81       param = find_parameter("database", "user");
82       if (param != "")
83       {
84          access_string += " user=" + param;
85       }
86    }
87    else
88    {
89       access_string += " user=" + usr;
90    }
91
92    if (pw == "")
93    {
94       param = find_parameter("database", "password");
95       if (param != "")
96       {
97          access_string += " password=" + param;
98       }
99    }
100    else
101    {
102       access_string += " password=" + pw;
103    }
104
105    param = find_parameter("database", "host");
106    if (param != "")
107    {
108       access_string += " host=" + param;
109    }
110    param = find_parameter("database", "port");
111    if (param != "")
112    {
113       access_string += " port=" + param;
114    }
115    return access_string;
116 }