pgpool2.git / summary / log / commit / refs

commit    e277b7852157d2fc47437d0dcd3d2be7cb22d6f1
Author:   Toshihiro Kitagawa <kitagawa at sraoss.co.jp>
Date:     Tue Jun 08 05:39:22 2010 +0000

    Fix pgpool.conf boolean variables to take the same range of string
    values as postgresql.conf.


pool.h | 3 ++ pool_config.l | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/pool.h b/pool.h index 70fcbe311..b14fd873a 100644 --- a/pool.h +++ b/pool.h @@ -547,4 +547,7 @@ extern POOL_STATUS do_command(POOL_CONNECTION *frontend, POOL_CONNECTION *backen extern POOL_STATUS do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major); extern void free_select_result(POOL_SELECT_RESULT *result); +/* pool_config.c */ +extern int eval_logical(char *str); + #endif /* POOL_H */ diff --git a/pool_config.l b/pool_config.l index 4fdddc4ec..3fff0dc4d 100644 --- a/pool_config.l +++ b/pool_config.l @@ -55,7 +55,6 @@ typedef enum { static char *extract_string(char *value, POOL_TOKEN token); static char **extract_string_tokens(char *str, char *delim, int *n); -static int eval_logical(char *str); static void clear_host_entry(int slot); %} @@ -1495,22 +1494,102 @@ static char *extract_string(char *value, POOL_TOKEN token) return ret; } -static int eval_logical(char *str) +/* + * Try to interpret value as boolean value. Valid values are: true, + * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof. + * If the string parses okay, return true, else false. + * If okay and result is not NULL, return the value in *result. + * This function copied from PostgreSQL source code. + */ +static bool parse_bool_with_len(const char *value, size_t len, bool *result) { - int ret; - - if (!strcasecmp(str, "true")) - ret = 1; - else if (!strcasecmp(str, "false")) - ret = 0; - else if (!strcmp(str, "1")) - ret = 1; - else if (!strcmp(str, "0")) - ret = 0; - else - ret = -1; + switch (*value) + { + case 't': + case 'T': + if (strncasecmp(value, "true", len) == 0) + { + if (result) + *result = true; + return true; + } + break; + case 'f': + case 'F': + if (strncasecmp(value, "false", len) == 0) + { + if (result) + *result = false; + return true; + } + break; + case 'y': + case 'Y': + if (strncasecmp(value, "yes", len) == 0) + { + if (result) + *result = true; + return true; + } + break; + case 'n': + case 'N': + if (strncasecmp(value, "no", len) == 0) + { + if (result) + *result = false; + return true; + } + break; + case 'o': + case 'O': + /* 'o' is not unique enough */ + if (strncasecmp(value, "on", (len > 2 ? len : 2)) == 0) + { + if (result) + *result = true; + return true; + } + else if (strncasecmp(value, "off", (len > 2 ? len : 2)) == 0) + { + if (result) + *result = false; + return true; + } + break; + case '1': + if (len == 1) + { + if (result) + *result = true; + return true; + } + break; + case '0': + if (len == 1) + { + if (result) + *result = false; + return true; + } + break; + default: + break; + } - return ret; + if (result) + *result = false; /* suppress compiler warning */ + return false; +} + +int eval_logical(char *str) +{ + bool result; + + if (!parse_bool_with_len(str, strlen(str), &result)) + return -1; + + return (result ? 1 : 0); } /* [parent: eece8b020104]