Commit abf6f483 authored by Bruce Momjian's avatar Bruce Momjian

pgindent fe-connect.c --- done to make IPv6 patch easier to apply.

parent e77443fd
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.215 2002/12/06 04:37:05 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.216 2002/12/19 19:30:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -186,7 +186,7 @@ static int parseServiceInfo(PQconninfoOption *options, ...@@ -186,7 +186,7 @@ static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage); PQExpBuffer errorMessage);
char *pwdfMatchesString(char *buf, char *token); char *pwdfMatchesString(char *buf, char *token);
char *PasswordFromFile(char *hostname, char *port, char *dbname, char *PasswordFromFile(char *hostname, char *port, char *dbname,
char *username); char *username);
/* /*
* Connecting to a Database * Connecting to a Database
...@@ -1054,7 +1054,7 @@ static int ...@@ -1054,7 +1054,7 @@ static int
connectDBComplete(PGconn *conn) connectDBComplete(PGconn *conn)
{ {
PostgresPollingStatusType flag = PGRES_POLLING_WRITING; PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
time_t finish_time = ((time_t) -1); time_t finish_time = ((time_t) -1);
if (conn == NULL || conn->status == CONNECTION_BAD) if (conn == NULL || conn->status == CONNECTION_BAD)
return 0; return 0;
...@@ -1064,11 +1064,14 @@ connectDBComplete(PGconn *conn) ...@@ -1064,11 +1064,14 @@ connectDBComplete(PGconn *conn)
*/ */
if (conn->connect_timeout != NULL) if (conn->connect_timeout != NULL)
{ {
int timeout = atoi(conn->connect_timeout); int timeout = atoi(conn->connect_timeout);
if (timeout > 0) if (timeout > 0)
{ {
/* Rounding could cause connection to fail; need at least 2 secs */ /*
* Rounding could cause connection to fail; need at least 2
* secs
*/
if (timeout < 2) if (timeout < 2)
timeout = 2; timeout = 2;
/* calculate the finish time based on start + timeout */ /* calculate the finish time based on start + timeout */
...@@ -1611,143 +1614,149 @@ PQsetenvPoll(PGconn *conn) ...@@ -1611,143 +1614,149 @@ PQsetenvPoll(PGconn *conn)
switch (conn->setenv_state) switch (conn->setenv_state)
{ {
case SETENV_STATE_ENCODINGS_SEND: case SETENV_STATE_ENCODINGS_SEND:
{
const char *env = getenv("PGCLIENTENCODING");
if (!env || *env == '\0')
{
/*
* PGCLIENTENCODING is not specified, so query server
* for it. We must use begin/commit in case autocommit
* is off by default.
*/
if (!PQsendQuery(conn, "begin; select getdatabaseencoding(); commit"))
goto error_return;
conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT;
return PGRES_POLLING_READING;
}
else
{ {
/* otherwise set client encoding in pg_conn struct */ const char *env = getenv("PGCLIENTENCODING");
int encoding = pg_char_to_encoding(env);
if (encoding < 0) if (!env || *env == '\0')
{ {
printfPQExpBuffer(&conn->errorMessage, /*
libpq_gettext("invalid encoding name in PGCLIENTENCODING: %s\n"), * PGCLIENTENCODING is not specified, so query
env); * server for it. We must use begin/commit in
goto error_return; * case autocommit is off by default.
*/
if (!PQsendQuery(conn, "begin; select getdatabaseencoding(); commit"))
goto error_return;
conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT;
return PGRES_POLLING_READING;
} }
conn->client_encoding = encoding; else
{
/* otherwise set client encoding in pg_conn struct */
int encoding = pg_char_to_encoding(env);
/* Move on to setting the environment options */ if (encoding < 0)
conn->setenv_state = SETENV_STATE_OPTION_SEND; {
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("invalid encoding name in PGCLIENTENCODING: %s\n"),
env);
goto error_return;
}
conn->client_encoding = encoding;
/* Move on to setting the environment options */
conn->setenv_state = SETENV_STATE_OPTION_SEND;
}
break;
} }
break;
}
case SETENV_STATE_ENCODINGS_WAIT: case SETENV_STATE_ENCODINGS_WAIT:
{ {
if (PQisBusy(conn)) if (PQisBusy(conn))
return PGRES_POLLING_READING; return PGRES_POLLING_READING;
res = PQgetResult(conn); res = PQgetResult(conn);
if (res) if (res)
{
if (PQresultStatus(res) == PGRES_TUPLES_OK)
{ {
/* set client encoding in pg_conn struct */ if (PQresultStatus(res) == PGRES_TUPLES_OK)
char *encoding; {
/* set client encoding in pg_conn struct */
encoding = PQgetvalue(res, 0, 0); char *encoding;
if (!encoding) /* this should not happen */
conn->client_encoding = PG_SQL_ASCII; encoding = PQgetvalue(res, 0, 0);
else if (!encoding) /* this should not happen */
conn->client_encoding = pg_char_to_encoding(encoding); conn->client_encoding = PG_SQL_ASCII;
else
conn->client_encoding = pg_char_to_encoding(encoding);
}
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
PQclear(res);
goto error_return;
}
PQclear(res);
/* Keep reading until PQgetResult returns NULL */
} }
else if (PQresultStatus(res) != PGRES_COMMAND_OK) else
{ {
PQclear(res); /*
goto error_return; * NULL result indicates that the query is
* finished
*/
/* Move on to setting the environment options */
conn->setenv_state = SETENV_STATE_OPTION_SEND;
} }
PQclear(res); break;
/* Keep reading until PQgetResult returns NULL */
}
else
{
/* NULL result indicates that the query is finished */
/* Move on to setting the environment options */
conn->setenv_state = SETENV_STATE_OPTION_SEND;
} }
break;
}
case SETENV_STATE_OPTION_SEND: case SETENV_STATE_OPTION_SEND:
{
/* Send an Environment Option */
char setQuery[100]; /* note length limits in
* sprintf's below */
if (conn->next_eo->envName)
{ {
const char *val; /* Send an Environment Option */
char setQuery[100]; /* note length limits in
* sprintf's below */
if ((val = getenv(conn->next_eo->envName))) if (conn->next_eo->envName)
{ {
if (strcasecmp(val, "default") == 0) const char *val;
sprintf(setQuery, "SET %s = %.60s",
conn->next_eo->pgName, val); if ((val = getenv(conn->next_eo->envName)))
else {
sprintf(setQuery, "SET %s = '%.60s'", if (strcasecmp(val, "default") == 0)
conn->next_eo->pgName, val); sprintf(setQuery, "SET %s = %.60s",
conn->next_eo->pgName, val);
else
sprintf(setQuery, "SET %s = '%.60s'",
conn->next_eo->pgName, val);
#ifdef CONNECTDEBUG #ifdef CONNECTDEBUG
printf("Use environment variable %s to send %s\n", printf("Use environment variable %s to send %s\n",
conn->next_eo->envName, setQuery); conn->next_eo->envName, setQuery);
#endif #endif
if (!PQsendQuery(conn, setQuery)) if (!PQsendQuery(conn, setQuery))
goto error_return; goto error_return;
conn->setenv_state = SETENV_STATE_OPTION_WAIT; conn->setenv_state = SETENV_STATE_OPTION_WAIT;
}
else
conn->next_eo++;
} }
else else
conn->next_eo++; {
} /* No more options to send, so we are done. */
else conn->setenv_state = SETENV_STATE_IDLE;
{ }
/* No more options to send, so we are done. */ break;
conn->setenv_state = SETENV_STATE_IDLE;
} }
break;
}
case SETENV_STATE_OPTION_WAIT: case SETENV_STATE_OPTION_WAIT:
{ {
if (PQisBusy(conn)) if (PQisBusy(conn))
return PGRES_POLLING_READING; return PGRES_POLLING_READING;
res = PQgetResult(conn); res = PQgetResult(conn);
if (res) if (res)
{
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
PQclear(res);
goto error_return;
}
PQclear(res); PQclear(res);
goto error_return; /* Keep reading until PQgetResult returns NULL */
} }
PQclear(res); else
/* Keep reading until PQgetResult returns NULL */ {
} /*
else * NULL result indicates that the query is
{ * finished
/* NULL result indicates that the query is finished */ */
/* Send the next option */ /* Send the next option */
conn->next_eo++; conn->next_eo++;
conn->setenv_state = SETENV_STATE_OPTION_SEND; conn->setenv_state = SETENV_STATE_OPTION_SEND;
}
break;
} }
break;
}
case SETENV_STATE_IDLE: case SETENV_STATE_IDLE:
return PGRES_POLLING_OK; return PGRES_POLLING_OK;
...@@ -1755,7 +1764,7 @@ PQsetenvPoll(PGconn *conn) ...@@ -1755,7 +1764,7 @@ PQsetenvPoll(PGconn *conn)
default: default:
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("invalid state %c, " libpq_gettext("invalid state %c, "
"probably indicative of memory corruption\n"), "probably indicative of memory corruption\n"),
conn->setenv_state); conn->setenv_state);
goto error_return; goto error_return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment