* connectOptions2 * * Compute derived connection options after absorbing all user-supplied info. * * Returns true if OK, false if trouble (in which case errorMessage is set * and so is conn->status). */
| 1093 | * and so is conn->status). |
| 1094 | */ |
| 1095 | static bool |
| 1096 | connectOptions2(PGconn *conn) |
| 1097 | { |
| 1098 | int i; |
| 1099 | |
| 1100 | /* |
| 1101 | * Allocate memory for details about each host to which we might possibly |
| 1102 | * try to connect. For that, count the number of elements in the hostaddr |
| 1103 | * or host options. If neither is given, assume one host. |
| 1104 | */ |
| 1105 | conn->whichhost = 0; |
| 1106 | if (conn->pghostaddr && conn->pghostaddr[0] != '\0') |
| 1107 | conn->nconnhost = count_comma_separated_elems(conn->pghostaddr); |
| 1108 | else if (conn->pghost && conn->pghost[0] != '\0') |
| 1109 | conn->nconnhost = count_comma_separated_elems(conn->pghost); |
| 1110 | else |
| 1111 | conn->nconnhost = 1; |
| 1112 | conn->connhost = (pg_conn_host *) |
| 1113 | calloc(conn->nconnhost, sizeof(pg_conn_host)); |
| 1114 | if (conn->connhost == NULL) |
| 1115 | goto oom_error; |
| 1116 | |
| 1117 | /* |
| 1118 | * We now have one pg_conn_host structure per possible host. Fill in the |
| 1119 | * host and hostaddr fields for each, by splitting the parameter strings. |
| 1120 | */ |
| 1121 | if (conn->pghostaddr != NULL && conn->pghostaddr[0] != '\0') |
| 1122 | { |
| 1123 | char *s = conn->pghostaddr; |
| 1124 | bool more = true; |
| 1125 | |
| 1126 | for (i = 0; i < conn->nconnhost && more; i++) |
| 1127 | { |
| 1128 | conn->connhost[i].hostaddr = parse_comma_separated_list(&s, &more); |
| 1129 | if (conn->connhost[i].hostaddr == NULL) |
| 1130 | goto oom_error; |
| 1131 | } |
| 1132 | |
| 1133 | /* |
| 1134 | * If hostaddr was given, the array was allocated according to the |
| 1135 | * number of elements in the hostaddr list, so it really should be the |
| 1136 | * right size. |
| 1137 | */ |
| 1138 | Assert(!more); |
| 1139 | Assert(i == conn->nconnhost); |
| 1140 | } |
| 1141 | |
| 1142 | if (conn->pghost != NULL && conn->pghost[0] != '\0') |
| 1143 | { |
| 1144 | char *s = conn->pghost; |
| 1145 | bool more = true; |
| 1146 | |
| 1147 | for (i = 0; i < conn->nconnhost && more; i++) |
| 1148 | { |
| 1149 | conn->connhost[i].host = parse_comma_separated_list(&s, &more); |
| 1150 | if (conn->connhost[i].host == NULL) |
| 1151 | goto oom_error; |
| 1152 | } |
no test coverage detected