aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-15 22:32:39 +0200
committerMax Kellermann <max@duempel.org>2013-10-15 22:49:01 +0200
commit7de96275dd6e3b6997e799413e4537561041e199 (patch)
tree4eab0c018168c14eb22f9e086917d16ef3f8f6a8
parente13d0bf65653550c4cfe3f879441139f5242d8b1 (diff)
downloadmpd-7de96275dd6e3b6997e799413e4537561041e199.tar.gz
mpd-7de96275dd6e3b6997e799413e4537561041e199.tar.xz
mpd-7de96275dd6e3b6997e799413e4537561041e199.zip
ConfigData: use std::string for config_param::value
-rw-r--r--src/AudioConfig.cxx2
-rw-r--r--src/ConfigData.cxx3
-rw-r--r--src/ConfigData.hxx5
-rw-r--r--src/ConfigGlobal.cxx10
-rw-r--r--src/Listen.cxx8
-rw-r--r--src/LogInit.cxx5
-rw-r--r--src/Main.cxx11
-rw-r--r--src/Permission.cxx10
-rw-r--r--src/ReplayGainConfig.cxx21
-rw-r--r--test/DumpDatabase.cxx2
10 files changed, 44 insertions, 33 deletions
diff --git a/src/AudioConfig.cxx b/src/AudioConfig.cxx
index aa09c374f..3d6337991 100644
--- a/src/AudioConfig.cxx
+++ b/src/AudioConfig.cxx
@@ -45,7 +45,7 @@ void initAudioConfig(void)
return;
Error error;
- if (!audio_format_parse(configured_audio_format, param->value,
+ if (!audio_format_parse(configured_audio_format, param->value.c_str(),
true, error))
FormatFatalError("error parsing line %i: %s",
param->line, error.GetMessage());
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx
index 611c5b91a..65cb63c97 100644
--- a/src/ConfigData.cxx
+++ b/src/ConfigData.cxx
@@ -58,12 +58,11 @@ block_param::GetBoolValue() const
}
config_param::config_param(const char *_value, int _line)
- :next(nullptr), value(g_strdup(_value)), line(_line) {}
+ :next(nullptr), value(_value), line(_line) {}
config_param::~config_param()
{
delete next;
- g_free(value);
}
const block_param *
diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx
index 85806fb05..48af72732 100644
--- a/src/ConfigData.hxx
+++ b/src/ConfigData.hxx
@@ -59,7 +59,8 @@ struct config_param {
*/
struct config_param *next;
- char *value;
+ std::string value;
+
unsigned int line;
std::vector<block_param> block_params;
@@ -71,7 +72,7 @@ struct config_param {
bool used;
config_param(int _line=-1)
- :next(nullptr), value(nullptr), line(_line), used(false) {}
+ :next(nullptr), line(_line), used(false) {}
gcc_nonnull_all
config_param(const char *_value, int _line=-1);
diff --git a/src/ConfigGlobal.cxx b/src/ConfigGlobal.cxx
index b68a34a38..e23462e94 100644
--- a/src/ConfigGlobal.cxx
+++ b/src/ConfigGlobal.cxx
@@ -93,7 +93,7 @@ config_get_string(ConfigOption option, const char *default_value)
if (param == nullptr)
return default_value;
- return param->value;
+ return param->value.c_str();
}
Path
@@ -109,7 +109,7 @@ config_get_path(ConfigOption option, Error &error)
Path
config_parse_path(const struct config_param *param, Error & error)
{
- Path path = ParsePath(param->value, error);
+ Path path = ParsePath(param->value.c_str(), error);
if (gcc_unlikely(path.IsNull()))
error.FormatPrefix("Invalid path at line %i: ",
param->line);
@@ -127,7 +127,7 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
if (param == nullptr)
return default_value;
- value = strtol(param->value, &endptr, 0);
+ value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0 || value < 0)
FormatFatalError("Not a valid non-negative number in line %i",
param->line);
@@ -145,7 +145,7 @@ config_get_positive(ConfigOption option, unsigned default_value)
if (param == nullptr)
return default_value;
- value = strtol(param->value, &endptr, 0);
+ value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0)
FormatFatalError("Not a valid number in line %i", param->line);
@@ -165,7 +165,7 @@ config_get_bool(ConfigOption option, bool default_value)
if (param == nullptr)
return default_value;
- success = get_bool(param->value, &value);
+ success = get_bool(param->value.c_str(), &value);
if (!success)
FormatFatalError("Expected boolean value (yes, true, 1) or "
"(no, false, 0) on line %i\n",
diff --git a/src/Listen.cxx b/src/Listen.cxx
index 6438d3ed4..7da39dd0e 100644
--- a/src/Listen.cxx
+++ b/src/Listen.cxx
@@ -66,13 +66,14 @@ listen_add_config_param(unsigned int port,
{
assert(param != NULL);
- if (0 == strcmp(param->value, "any")) {
+ if (0 == strcmp(param->value.c_str(), "any")) {
return listen_socket->AddPort(port, error_r);
} else if (param->value[0] == '/' || param->value[0] == '~') {
Path path = config_parse_path(param, error_r);
return !path.IsNull() && listen_socket->AddPath(path.c_str(), error_r);
} else {
- return listen_socket->AddHost(param->value, port, error_r);
+ return listen_socket->AddHost(param->value.c_str(), port,
+ error_r);
}
}
@@ -126,7 +127,8 @@ listen_global_init(Error &error)
if (!listen_add_config_param(port, param, error)) {
delete listen_socket;
error.FormatPrefix("Failed to listen on %s (line %i): ",
- param->value, param->line);
+ param->value.c_str(),
+ param->line);
return false;
}
diff --git a/src/LogInit.cxx b/src/LogInit.cxx
index d5e5c1d1f..433eda51a 100644
--- a/src/LogInit.cxx
+++ b/src/LogInit.cxx
@@ -253,7 +253,8 @@ log_init(bool verbose, bool use_stdout, Error &error)
if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG;
else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
- log_threshold = parse_log_level(param->value, param->line);
+ log_threshold = parse_log_level(param->value.c_str(),
+ param->line);
if (use_stdout) {
log_init_stdout();
@@ -272,7 +273,7 @@ log_init(bool verbose, bool use_stdout, Error &error)
return false;
#endif
#ifdef HAVE_SYSLOG
- } else if (strcmp(param->value, "syslog") == 0) {
+ } else if (strcmp(param->value.c_str(), "syslog") == 0) {
log_init_syslog();
return true;
#endif
diff --git a/src/Main.cxx b/src/Main.cxx
index 8509abcfb..003f7414b 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -176,7 +176,8 @@ glue_db_init_and_load(void)
if (param == nullptr && path != nullptr) {
allocated = new config_param("database", path->line);
- allocated->AddBlockParam("path", path->value, path->line);
+ allocated->AddBlockParam("path", path->value.c_str(),
+ path->line);
param = allocated;
}
@@ -261,11 +262,11 @@ initialize_decoder_and_player(void)
param = config_get_param(CONF_AUDIO_BUFFER_SIZE);
if (param != nullptr) {
- long tmp = strtol(param->value, &test, 10);
+ long tmp = strtol(param->value.c_str(), &test, 10);
if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
FormatFatalError("buffer size \"%s\" is not a "
"positive integer, line %i",
- param->value, param->line);
+ param->value.c_str(), param->line);
buffer_size = tmp;
} else
buffer_size = DEFAULT_BUFFER_SIZE;
@@ -280,12 +281,12 @@ initialize_decoder_and_player(void)
param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
if (param != nullptr) {
- perc = strtod(param->value, &test);
+ perc = strtod(param->value.c_str(), &test);
if (*test != '%' || perc < 0 || perc > 100) {
FormatFatalError("buffered before play \"%s\" is not "
"a positive percentage and less "
"than 100 percent, line %i",
- param->value, param->line);
+ param->value.c_str(), param->line);
}
} else
perc = DEFAULT_BUFFER_BEFORE_PLAY;
diff --git a/src/Permission.cxx b/src/Permission.cxx
index f53465b83..dafa4e00c 100644
--- a/src/Permission.cxx
+++ b/src/Permission.cxx
@@ -88,15 +88,17 @@ void initPermissions(void)
do {
const char *separator =
- strchr(param->value, PERMISSION_PASSWORD_CHAR);
+ strchr(param->value.c_str(),
+ PERMISSION_PASSWORD_CHAR);
if (separator == NULL)
FormatFatalError("\"%c\" not found in password string "
"\"%s\", line %i",
PERMISSION_PASSWORD_CHAR,
- param->value, param->line);
+ param->value.c_str(),
+ param->line);
- std::string password((const char *)param->value, separator);
+ std::string password(param->value.c_str(), separator);
permission = parsePermissions(separator + 1);
@@ -108,7 +110,7 @@ void initPermissions(void)
param = config_get_param(CONF_DEFAULT_PERMS);
if (param)
- permission_default = parsePermissions(param->value);
+ permission_default = parsePermissions(param->value.c_str());
}
int getPermissionFromPassword(char const* password, unsigned* permission)
diff --git a/src/ReplayGainConfig.cxx b/src/ReplayGainConfig.cxx
index 9665c8fcf..840403923 100644
--- a/src/ReplayGainConfig.cxx
+++ b/src/ReplayGainConfig.cxx
@@ -85,25 +85,28 @@ void replay_gain_global_init(void)
{
const struct config_param *param = config_get_param(CONF_REPLAYGAIN);
- if (param != NULL && !replay_gain_set_mode_string(param->value)) {
+ if (param != NULL &&
+ !replay_gain_set_mode_string(param->value.c_str())) {
FormatFatalError("replaygain value \"%s\" at line %i is invalid\n",
- param->value, param->line);
+ param->value.c_str(), param->line);
}
param = config_get_param(CONF_REPLAYGAIN_PREAMP);
if (param) {
char *test;
- float f = strtod(param->value, &test);
+ float f = strtod(param->value.c_str(), &test);
if (*test != '\0') {
FormatFatalError("Replaygain preamp \"%s\" is not a number at "
- "line %i\n", param->value, param->line);
+ "line %i\n",
+ param->value.c_str(), param->line);
}
if (f < -15 || f > 15) {
FormatFatalError("Replaygain preamp \"%s\" is not between -15 and"
- "15 at line %i\n", param->value, param->line);
+ "15 at line %i\n",
+ param->value.c_str(), param->line);
}
replay_gain_preamp = pow(10, f / 20.0);
@@ -113,16 +116,18 @@ void replay_gain_global_init(void)
if (param) {
char *test;
- float f = strtod(param->value, &test);
+ float f = strtod(param->value.c_str(), &test);
if (*test != '\0') {
FormatFatalError("Replaygain missing preamp \"%s\" is not a number at "
- "line %i\n", param->value, param->line);
+ "line %i\n",
+ param->value.c_str(), param->line);
}
if (f < -15 || f > 15) {
FormatFatalError("Replaygain missing preamp \"%s\" is not between -15 and"
- "15 at line %i\n", param->value, param->line);
+ "15 at line %i\n",
+ param->value.c_str(), param->line);
}
replay_gain_missing_preamp = pow(10, f / 20.0);
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index 395ff4f23..21a12d294 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -113,7 +113,7 @@ main(int argc, char **argv)
const struct config_param *path = config_get_param(CONF_DB_FILE);
config_param param("database", path->line);
if (path != nullptr)
- param.AddBlockParam("path", path->value, path->line);
+ param.AddBlockParam("path", path->value.c_str(), path->line);
Database *db = plugin->create(param, error);