* Conninfo array parser routine * * If successful, a malloc'd PQconninfoOption array is returned. * If not successful, NULL is returned and an error message is * appended to errorMessage. * Defaults are supplied (from a service file, environment variables, etc) * for unspecified options, but only if use_defaults is true. * * If expand_dbname is non-zero, and the value passed for the first
| 5870 | * a database, in-tree code first wraps the name in a connection string. |
| 5871 | */ |
| 5872 | static PQconninfoOption * |
| 5873 | conninfo_array_parse(const char *const *keywords, const char *const *values, |
| 5874 | PQExpBuffer errorMessage, bool use_defaults, |
| 5875 | int expand_dbname) |
| 5876 | { |
| 5877 | PQconninfoOption *options; |
| 5878 | PQconninfoOption *dbname_options = NULL; |
| 5879 | PQconninfoOption *option; |
| 5880 | int i = 0; |
| 5881 | |
| 5882 | /* |
| 5883 | * If expand_dbname is non-zero, check keyword "dbname" to see if val is |
| 5884 | * actually a recognized connection string. |
| 5885 | */ |
| 5886 | while (expand_dbname && keywords[i]) |
| 5887 | { |
| 5888 | const char *pname = keywords[i]; |
| 5889 | const char *pvalue = values[i]; |
| 5890 | |
| 5891 | /* first find "dbname" if any */ |
| 5892 | if (strcmp(pname, "dbname") == 0 && pvalue) |
| 5893 | { |
| 5894 | /* |
| 5895 | * If value is a connection string, parse it, but do not use |
| 5896 | * defaults here -- those get picked up later. We only want to |
| 5897 | * override for those parameters actually passed. |
| 5898 | */ |
| 5899 | if (recognized_connection_string(pvalue)) |
| 5900 | { |
| 5901 | dbname_options = parse_connection_string(pvalue, errorMessage, false); |
| 5902 | if (dbname_options == NULL) |
| 5903 | return NULL; |
| 5904 | } |
| 5905 | break; |
| 5906 | } |
| 5907 | ++i; |
| 5908 | } |
| 5909 | |
| 5910 | /* Make a working copy of PQconninfoOptions */ |
| 5911 | options = conninfo_init(errorMessage); |
| 5912 | if (options == NULL) |
| 5913 | { |
| 5914 | PQconninfoFree(dbname_options); |
| 5915 | return NULL; |
| 5916 | } |
| 5917 | |
| 5918 | /* Parse the keywords/values arrays */ |
| 5919 | i = 0; |
| 5920 | while (keywords[i]) |
| 5921 | { |
| 5922 | const char *pname = keywords[i]; |
| 5923 | const char *pvalue = values[i]; |
| 5924 | |
| 5925 | if (pvalue != NULL && pvalue[0] != '\0') |
| 5926 | { |
| 5927 | /* Search for the param record */ |
| 5928 | for (option = options; option->keyword != NULL; option++) |
| 5929 | { |
no test coverage detected