diff options
Diffstat (limited to 'src/interfaces/libpq++/pgenv.cc')
| -rw-r--r-- | src/interfaces/libpq++/pgenv.cc | 101 |
1 files changed, 31 insertions, 70 deletions
diff --git a/src/interfaces/libpq++/pgenv.cc b/src/interfaces/libpq++/pgenv.cc index 7d696cf043..451a4f3fde 100644 --- a/src/interfaces/libpq++/pgenv.cc +++ b/src/interfaces/libpq++/pgenv.cc @@ -1,10 +1,10 @@ /*------------------------------------------------------------------------- * * FILE - * PGenv.cc + * PgEnv.cc * * DESCRIPTION - * PGenv is the environment for setting up a connection to a + * PgEnv is the environment for setting up a connection to a * postgres backend, captures the host, port, tty, options and * authentication type. * @@ -14,94 +14,55 @@ * Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.2 1996/11/18 01:43:55 bryanh Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.3 1997/02/13 10:00:33 scrappy Exp $ * *------------------------------------------------------------------------- */ #include <stdlib.h> -#include "libpq++.H" +#include "pgenv.h" -#define DefaultAuth DEFAULT_CLIENT_AUTHSVC -#define DefaultPort "5432" -// default constructor for PGenv +#define DefaultAuth DEFAULT_CLIENT_AUTHSVC +#define DefaultPort POSTPORT + + +// **************************************************************** +// +// PgEnv Implementation +// +// **************************************************************** +// Default constructor for PgEnv // checks the environment variables -PGenv::PGenv() +PgEnv::PgEnv() { - pgauth = NULL; - pghost = NULL; - pgport = NULL; - pgoption = NULL; - pgtty = NULL; - - setValues(getenv(ENV_DEFAULT_AUTH), getenv(ENV_DEFAULT_HOST), + SetValues(getenv(ENV_DEFAULT_AUTH), getenv(ENV_DEFAULT_HOST), getenv(ENV_DEFAULT_PORT), getenv(ENV_DEFAULT_OPTION), - getenv(ENV_DEFAULT_TTY)); + getenv(ENV_DEFAULT_TTY)); } // constructor for given environment -PGenv::PGenv(char* auth, char* host, char* port, char* option, char* tty) +PgEnv::PgEnv(const string& auth, const string& host, const string& port, + const string& option, const string& tty) { - pgauth = NULL; - pghost = NULL; - pgport = NULL; - pgoption = NULL; - pgtty = NULL; - - setValues(auth, host, port, option, tty); + SetValues(auth, host, port, option, tty); } // allocate memory and set internal structures to match // required environment -void -PGenv::setValues(char* auth, char* host, char* port, char* option, char* tty) +void PgEnv::SetValues(const string& auth, const string& host, const string& port, + const string& option, const string& tty) { - char* temp; - - temp = (auth) ? auth : DefaultAuth; - - if (pgauth) - free(pgauth); - pgauth = strdup(temp); - - temp = (host) ? host : DefaultHost; - - if (pghost) - free(pghost); - pghost = strdup(temp); - - temp = (port) ? port : DefaultPort; - - if (pgport) - free(pgport); - pgport = strdup(temp); - - temp = (option) ? option : DefaultOption; - - if (pgoption) - free(pgoption); - pgoption = strdup(temp); - - temp = (tty) ? tty : DefaultTty; - - if (pgtty) - free(pgtty); - pgtty = strdup(temp); + Auth( auth ); + Host( host ); + Port( port ); + Option( option ); + TTY( tty ); } -// default destrutor -// frees allocated memory for internal structures -PGenv::~PGenv() +// read a string from the environment and convert it to string +string PgEnv::getenv(const char* name) { - if (pgauth) - free(pgauth); - if (pghost) - free(pghost); - if (pgport) - free(pgport); - if (pgoption) - free(pgoption); - if (pgtty) - free(pgtty); + char* env = ::getenv(name); + return (env ? env : ""); } |
