From 88bf361e617b8c28b4cfe777c3d42d078d033232 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 24 May 2017 12:52:44 +0300 Subject: [PATCH] Add MXS_MODULE_PARAM_QUOTEDSTRING configuration value type A quoted string is a string enclosed in '"':s. This makes it clear where the string begins and ends, avoiding ambiguity with whitespace. After the config file has been loaded, the '"':s at the beginning and at the end of the string are erased. Querying the config value with config_get_string() will return this de-quoted value. For example, if the config file reads 'my_string="test""', the actual string will be 'test"'. --- include/maxscale/modinfo.h | 3 +++ server/core/config.cc | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/maxscale/modinfo.h b/include/maxscale/modinfo.h index de0fb6c6a..0e7abf9cc 100644 --- a/include/maxscale/modinfo.h +++ b/include/maxscale/modinfo.h @@ -79,6 +79,7 @@ enum mxs_module_param_type MXS_MODULE_PARAM_SIZE, /**< Size in bytes */ MXS_MODULE_PARAM_BOOL, /**< Boolean value */ MXS_MODULE_PARAM_STRING, /**< String value */ + MXS_MODULE_PARAM_QUOTEDSTRING, /**< String enclosed in '"':s */ MXS_MODULE_PARAM_ENUM, /**< Enumeration of string values */ MXS_MODULE_PARAM_PATH, /**< Path to a file or a directory */ MXS_MODULE_PARAM_SERVICE, /**< Service name */ @@ -233,6 +234,8 @@ static inline const char* mxs_module_param_type_to_string(enum mxs_module_param_ return "bool"; case MXS_MODULE_PARAM_STRING: return "string"; + case MXS_MODULE_PARAM_QUOTEDSTRING: + return "quoted string"; case MXS_MODULE_PARAM_ENUM: return "enum"; case MXS_MODULE_PARAM_PATH: diff --git a/server/core/config.cc b/server/core/config.cc index fa65409ca..c9bdad5e6 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -3601,6 +3601,15 @@ void config_fix_param(const MXS_MODULE_PARAM *params, MXS_CONFIG_PARAMETER *p) fix_serverlist(p->value); break; + case MXS_MODULE_PARAM_QUOTEDSTRING: + { // Remove the '"':s from the ends of the string + char* value = p->value; + size_t len = strlen(value); + value[len - 1] = '\0'; + memmove(value, value + 1, len - 1); + } + break; + default: break; } @@ -3697,6 +3706,17 @@ bool config_param_is_valid(const MXS_MODULE_PARAM *params, const char *key, } break; + case MXS_MODULE_PARAM_QUOTEDSTRING: + valid = false; + { + size_t len = strlen(value); + if ((len >= 2) && (value[0] == '"') && (value[len - 1] == '"')) + { + valid = true; + } + } + break; + case MXS_MODULE_PARAM_ENUM: if (params[i].accepted_values) {