Commit 7de96275 authored by Max Kellermann's avatar Max Kellermann

ConfigData: use std::string for config_param::value

parent e13d0bf6
...@@ -45,7 +45,7 @@ void initAudioConfig(void) ...@@ -45,7 +45,7 @@ void initAudioConfig(void)
return; return;
Error error; Error error;
if (!audio_format_parse(configured_audio_format, param->value, if (!audio_format_parse(configured_audio_format, param->value.c_str(),
true, error)) true, error))
FormatFatalError("error parsing line %i: %s", FormatFatalError("error parsing line %i: %s",
param->line, error.GetMessage()); param->line, error.GetMessage());
......
...@@ -58,12 +58,11 @@ block_param::GetBoolValue() const ...@@ -58,12 +58,11 @@ block_param::GetBoolValue() const
} }
config_param::config_param(const char *_value, int _line) 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() config_param::~config_param()
{ {
delete next; delete next;
g_free(value);
} }
const block_param * const block_param *
......
...@@ -59,7 +59,8 @@ struct config_param { ...@@ -59,7 +59,8 @@ struct config_param {
*/ */
struct config_param *next; struct config_param *next;
char *value; std::string value;
unsigned int line; unsigned int line;
std::vector<block_param> block_params; std::vector<block_param> block_params;
...@@ -71,7 +72,7 @@ struct config_param { ...@@ -71,7 +72,7 @@ struct config_param {
bool used; bool used;
config_param(int _line=-1) config_param(int _line=-1)
:next(nullptr), value(nullptr), line(_line), used(false) {} :next(nullptr), line(_line), used(false) {}
gcc_nonnull_all gcc_nonnull_all
config_param(const char *_value, int _line=-1); config_param(const char *_value, int _line=-1);
......
...@@ -93,7 +93,7 @@ config_get_string(ConfigOption option, const char *default_value) ...@@ -93,7 +93,7 @@ config_get_string(ConfigOption option, const char *default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
return param->value; return param->value.c_str();
} }
Path Path
...@@ -109,7 +109,7 @@ config_get_path(ConfigOption option, Error &error) ...@@ -109,7 +109,7 @@ config_get_path(ConfigOption option, Error &error)
Path Path
config_parse_path(const struct config_param *param, Error & error) 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())) if (gcc_unlikely(path.IsNull()))
error.FormatPrefix("Invalid path at line %i: ", error.FormatPrefix("Invalid path at line %i: ",
param->line); param->line);
...@@ -127,7 +127,7 @@ config_get_unsigned(ConfigOption option, unsigned default_value) ...@@ -127,7 +127,7 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
value = strtol(param->value, &endptr, 0); value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0 || value < 0) if (*endptr != 0 || value < 0)
FormatFatalError("Not a valid non-negative number in line %i", FormatFatalError("Not a valid non-negative number in line %i",
param->line); param->line);
...@@ -145,7 +145,7 @@ config_get_positive(ConfigOption option, unsigned default_value) ...@@ -145,7 +145,7 @@ config_get_positive(ConfigOption option, unsigned default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
value = strtol(param->value, &endptr, 0); value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0) if (*endptr != 0)
FormatFatalError("Not a valid number in line %i", param->line); FormatFatalError("Not a valid number in line %i", param->line);
...@@ -165,7 +165,7 @@ config_get_bool(ConfigOption option, bool default_value) ...@@ -165,7 +165,7 @@ config_get_bool(ConfigOption option, bool default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
success = get_bool(param->value, &value); success = get_bool(param->value.c_str(), &value);
if (!success) if (!success)
FormatFatalError("Expected boolean value (yes, true, 1) or " FormatFatalError("Expected boolean value (yes, true, 1) or "
"(no, false, 0) on line %i\n", "(no, false, 0) on line %i\n",
......
...@@ -66,13 +66,14 @@ listen_add_config_param(unsigned int port, ...@@ -66,13 +66,14 @@ listen_add_config_param(unsigned int port,
{ {
assert(param != NULL); assert(param != NULL);
if (0 == strcmp(param->value, "any")) { if (0 == strcmp(param->value.c_str(), "any")) {
return listen_socket->AddPort(port, error_r); return listen_socket->AddPort(port, error_r);
} else if (param->value[0] == '/' || param->value[0] == '~') { } else if (param->value[0] == '/' || param->value[0] == '~') {
Path path = config_parse_path(param, error_r); Path path = config_parse_path(param, error_r);
return !path.IsNull() && listen_socket->AddPath(path.c_str(), error_r); return !path.IsNull() && listen_socket->AddPath(path.c_str(), error_r);
} else { } 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) ...@@ -126,7 +127,8 @@ listen_global_init(Error &error)
if (!listen_add_config_param(port, param, error)) { if (!listen_add_config_param(port, param, error)) {
delete listen_socket; delete listen_socket;
error.FormatPrefix("Failed to listen on %s (line %i): ", error.FormatPrefix("Failed to listen on %s (line %i): ",
param->value, param->line); param->value.c_str(),
param->line);
return false; return false;
} }
......
...@@ -253,7 +253,8 @@ log_init(bool verbose, bool use_stdout, Error &error) ...@@ -253,7 +253,8 @@ log_init(bool verbose, bool use_stdout, Error &error)
if (verbose) if (verbose)
log_threshold = G_LOG_LEVEL_DEBUG; log_threshold = G_LOG_LEVEL_DEBUG;
else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL) 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) { if (use_stdout) {
log_init_stdout(); log_init_stdout();
...@@ -272,7 +273,7 @@ log_init(bool verbose, bool use_stdout, Error &error) ...@@ -272,7 +273,7 @@ log_init(bool verbose, bool use_stdout, Error &error)
return false; return false;
#endif #endif
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
} else if (strcmp(param->value, "syslog") == 0) { } else if (strcmp(param->value.c_str(), "syslog") == 0) {
log_init_syslog(); log_init_syslog();
return true; return true;
#endif #endif
......
...@@ -176,7 +176,8 @@ glue_db_init_and_load(void) ...@@ -176,7 +176,8 @@ glue_db_init_and_load(void)
if (param == nullptr && path != nullptr) { if (param == nullptr && path != nullptr) {
allocated = new config_param("database", path->line); 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; param = allocated;
} }
...@@ -261,11 +262,11 @@ initialize_decoder_and_player(void) ...@@ -261,11 +262,11 @@ initialize_decoder_and_player(void)
param = config_get_param(CONF_AUDIO_BUFFER_SIZE); param = config_get_param(CONF_AUDIO_BUFFER_SIZE);
if (param != nullptr) { 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) if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
FormatFatalError("buffer size \"%s\" is not a " FormatFatalError("buffer size \"%s\" is not a "
"positive integer, line %i", "positive integer, line %i",
param->value, param->line); param->value.c_str(), param->line);
buffer_size = tmp; buffer_size = tmp;
} else } else
buffer_size = DEFAULT_BUFFER_SIZE; buffer_size = DEFAULT_BUFFER_SIZE;
...@@ -280,12 +281,12 @@ initialize_decoder_and_player(void) ...@@ -280,12 +281,12 @@ initialize_decoder_and_player(void)
param = config_get_param(CONF_BUFFER_BEFORE_PLAY); param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
if (param != nullptr) { if (param != nullptr) {
perc = strtod(param->value, &test); perc = strtod(param->value.c_str(), &test);
if (*test != '%' || perc < 0 || perc > 100) { if (*test != '%' || perc < 0 || perc > 100) {
FormatFatalError("buffered before play \"%s\" is not " FormatFatalError("buffered before play \"%s\" is not "
"a positive percentage and less " "a positive percentage and less "
"than 100 percent, line %i", "than 100 percent, line %i",
param->value, param->line); param->value.c_str(), param->line);
} }
} else } else
perc = DEFAULT_BUFFER_BEFORE_PLAY; perc = DEFAULT_BUFFER_BEFORE_PLAY;
......
...@@ -88,15 +88,17 @@ void initPermissions(void) ...@@ -88,15 +88,17 @@ void initPermissions(void)
do { do {
const char *separator = const char *separator =
strchr(param->value, PERMISSION_PASSWORD_CHAR); strchr(param->value.c_str(),
PERMISSION_PASSWORD_CHAR);
if (separator == NULL) if (separator == NULL)
FormatFatalError("\"%c\" not found in password string " FormatFatalError("\"%c\" not found in password string "
"\"%s\", line %i", "\"%s\", line %i",
PERMISSION_PASSWORD_CHAR, 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); permission = parsePermissions(separator + 1);
...@@ -108,7 +110,7 @@ void initPermissions(void) ...@@ -108,7 +110,7 @@ void initPermissions(void)
param = config_get_param(CONF_DEFAULT_PERMS); param = config_get_param(CONF_DEFAULT_PERMS);
if (param) if (param)
permission_default = parsePermissions(param->value); permission_default = parsePermissions(param->value.c_str());
} }
int getPermissionFromPassword(char const* password, unsigned* permission) int getPermissionFromPassword(char const* password, unsigned* permission)
......
...@@ -85,25 +85,28 @@ void replay_gain_global_init(void) ...@@ -85,25 +85,28 @@ void replay_gain_global_init(void)
{ {
const struct config_param *param = config_get_param(CONF_REPLAYGAIN); 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", 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); param = config_get_param(CONF_REPLAYGAIN_PREAMP);
if (param) { if (param) {
char *test; char *test;
float f = strtod(param->value, &test); float f = strtod(param->value.c_str(), &test);
if (*test != '\0') { if (*test != '\0') {
FormatFatalError("Replaygain preamp \"%s\" is not a number at " 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) { if (f < -15 || f > 15) {
FormatFatalError("Replaygain preamp \"%s\" is not between -15 and" 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); replay_gain_preamp = pow(10, f / 20.0);
...@@ -113,16 +116,18 @@ void replay_gain_global_init(void) ...@@ -113,16 +116,18 @@ void replay_gain_global_init(void)
if (param) { if (param) {
char *test; char *test;
float f = strtod(param->value, &test); float f = strtod(param->value.c_str(), &test);
if (*test != '\0') { if (*test != '\0') {
FormatFatalError("Replaygain missing preamp \"%s\" is not a number at " 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) { if (f < -15 || f > 15) {
FormatFatalError("Replaygain missing preamp \"%s\" is not between -15 and" 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); replay_gain_missing_preamp = pow(10, f / 20.0);
......
...@@ -113,7 +113,7 @@ main(int argc, char **argv) ...@@ -113,7 +113,7 @@ main(int argc, char **argv)
const struct config_param *path = config_get_param(CONF_DB_FILE); const struct config_param *path = config_get_param(CONF_DB_FILE);
config_param param("database", path->line); config_param param("database", path->line);
if (path != nullptr) 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); Database *db = plugin->create(param, error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment