---------------- * PQsetdbLogin * * establishes a connection to a postgres backend through the postmaster * at the specified host and port. * * returns a PGconn* which is needed for all subsequent libpq calls * * if the status field of the connection returned is CONNECTION_BAD, * then only the errorMessage is likely to be useful. * ---------------- */
| 1581 | * ---------------- |
| 1582 | */ |
| 1583 | PGconn * |
| 1584 | PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, |
| 1585 | const char *pgtty, const char *dbName, const char *login, |
| 1586 | const char *pwd) |
| 1587 | { |
| 1588 | PGconn *conn; |
| 1589 | |
| 1590 | /* |
| 1591 | * Allocate memory for the conn structure. Note that we also expect this |
| 1592 | * to initialize conn->errorMessage to empty. All subsequent steps during |
| 1593 | * connection initialization will only append to that buffer. |
| 1594 | */ |
| 1595 | conn = makeEmptyPGconn(); |
| 1596 | if (conn == NULL) |
| 1597 | return NULL; |
| 1598 | |
| 1599 | /* |
| 1600 | * If the dbName parameter contains what looks like a connection string, |
| 1601 | * parse it into conn struct using connectOptions1. |
| 1602 | */ |
| 1603 | if (dbName && recognized_connection_string(dbName)) |
| 1604 | { |
| 1605 | if (!connectOptions1(conn, dbName)) |
| 1606 | return conn; |
| 1607 | } |
| 1608 | else |
| 1609 | { |
| 1610 | /* |
| 1611 | * Old-style path: first, parse an empty conninfo string in order to |
| 1612 | * set up the same defaults that PQconnectdb() would use. |
| 1613 | */ |
| 1614 | if (!connectOptions1(conn, "")) |
| 1615 | return conn; |
| 1616 | |
| 1617 | /* Insert dbName parameter value into struct */ |
| 1618 | if (dbName && dbName[0] != '\0') |
| 1619 | { |
| 1620 | if (conn->dbName) |
| 1621 | free(conn->dbName); |
| 1622 | conn->dbName = strdup(dbName); |
| 1623 | if (!conn->dbName) |
| 1624 | goto oom_error; |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | /* |
| 1629 | * Insert remaining parameters into struct, overriding defaults (as well |
| 1630 | * as any conflicting data from dbName taken as a conninfo). |
| 1631 | */ |
| 1632 | if (pghost && pghost[0] != '\0') |
| 1633 | { |
| 1634 | if (conn->pghost) |
| 1635 | free(conn->pghost); |
| 1636 | conn->pghost = strdup(pghost); |
| 1637 | if (!conn->pghost) |
| 1638 | goto oom_error; |
| 1639 | } |
| 1640 |