1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*-------------------------------------------------------------------------
*
* FILE
* PgEnv.cc
*
* DESCRIPTION
* PgEnv is the environment for setting up a connection to a
* postgres backend, captures the host, port, tty, options and
* authentication type.
*
* NOTES
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.3 1997/02/13 10:00:33 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include "pgenv.h"
#define DefaultAuth DEFAULT_CLIENT_AUTHSVC
#define DefaultPort POSTPORT
// ****************************************************************
//
// PgEnv Implementation
//
// ****************************************************************
// Default constructor for PgEnv
// checks the environment variables
PgEnv::PgEnv()
{
SetValues(getenv(ENV_DEFAULT_AUTH), getenv(ENV_DEFAULT_HOST),
getenv(ENV_DEFAULT_PORT), getenv(ENV_DEFAULT_OPTION),
getenv(ENV_DEFAULT_TTY));
}
// constructor for given environment
PgEnv::PgEnv(const string& auth, const string& host, const string& port,
const string& option, const string& tty)
{
SetValues(auth, host, port, option, tty);
}
// allocate memory and set internal structures to match
// required environment
void PgEnv::SetValues(const string& auth, const string& host, const string& port,
const string& option, const string& tty)
{
Auth( auth );
Host( host );
Port( port );
Option( option );
TTY( tty );
}
// read a string from the environment and convert it to string
string PgEnv::getenv(const char* name)
{
char* env = ::getenv(name);
return (env ? env : "");
}
|