ConfigData: use std::string for config_param::value
This commit is contained in:
parent
e13d0bf656
commit
7de96275dd
@ -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());
|
||||
|
@ -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 *
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
11
src/Main.cxx
11
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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user