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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*-------------------------------------------------------------------------
*
* 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.2 1996/11/18 01:43:55 bryanh Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include "libpq++.H"
#define DefaultAuth DEFAULT_CLIENT_AUTHSVC
#define DefaultPort "5432"
// default constructor for PGenv
// checks the environment variables
PGenv::PGenv()
{
pgauth = NULL;
pghost = NULL;
pgport = NULL;
pgoption = NULL;
pgtty = NULL;
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(char* auth, char* host, char* port, char* option, char* tty)
{
pgauth = NULL;
pghost = NULL;
pgport = NULL;
pgoption = NULL;
pgtty = NULL;
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)
{
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);
}
// default destrutor
// frees allocated memory for internal structures
PGenv::~PGenv()
{
if (pgauth)
free(pgauth);
if (pghost)
free(pghost);
if (pgport)
free(pgport);
if (pgoption)
free(pgoption);
if (pgtty)
free(pgtty);
}
|