conf: convert to C++
This commit is contained in:
parent
c02cc199bc
commit
911411e630
26
Makefile.am
26
Makefile.am
|
@ -183,7 +183,7 @@ src_mpd_SOURCES = \
|
||||||
src/OtherCommands.cxx src/OtherCommands.hxx \
|
src/OtherCommands.cxx src/OtherCommands.hxx \
|
||||||
src/Idle.cxx src/Idle.hxx \
|
src/Idle.cxx src/Idle.hxx \
|
||||||
src/CommandLine.cxx src/CommandLine.hxx \
|
src/CommandLine.cxx src/CommandLine.hxx \
|
||||||
src/conf.c \
|
src/ConfigFile.cxx \
|
||||||
src/CrossFade.cxx src/CrossFade.hxx \
|
src/CrossFade.cxx src/CrossFade.hxx \
|
||||||
src/cue/cue_parser.c src/cue/cue_parser.h \
|
src/cue/cue_parser.c src/cue/cue_parser.h \
|
||||||
src/decoder_error.h \
|
src/decoder_error.h \
|
||||||
|
@ -1034,7 +1034,7 @@ endif
|
||||||
test_read_conf_LDADD = \
|
test_read_conf_LDADD = \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
test_read_conf_SOURCES = test/read_conf.c \
|
test_read_conf_SOURCES = test/read_conf.c \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c
|
||||||
|
|
||||||
test_run_resolver_LDADD = \
|
test_run_resolver_LDADD = \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
|
@ -1056,7 +1056,7 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
|
||||||
src/path.c \
|
src/path.c \
|
||||||
src/SongFilter.cxx \
|
src/SongFilter.cxx \
|
||||||
src/TextFile.cxx \
|
src/TextFile.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c
|
||||||
|
|
||||||
test_run_input_LDADD = \
|
test_run_input_LDADD = \
|
||||||
$(INPUT_LIBS) \
|
$(INPUT_LIBS) \
|
||||||
|
@ -1065,7 +1065,7 @@ test_run_input_LDADD = \
|
||||||
test_run_input_SOURCES = test/run_input.c \
|
test_run_input_SOURCES = test/run_input.c \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c\
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
||||||
src/uri.c \
|
src/uri.c \
|
||||||
src/fd_util.c
|
src/fd_util.c
|
||||||
|
@ -1077,7 +1077,7 @@ test_dump_text_file_LDADD = \
|
||||||
test_dump_text_file_SOURCES = test/dump_text_file.cxx \
|
test_dump_text_file_SOURCES = test/dump_text_file.cxx \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c\
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
||||||
src/text_input_stream.c src/fifo_buffer.c \
|
src/text_input_stream.c src/fifo_buffer.c \
|
||||||
src/uri.c \
|
src/uri.c \
|
||||||
|
@ -1095,7 +1095,7 @@ test_dump_playlist_LDADD = \
|
||||||
test_dump_playlist_SOURCES = test/dump_playlist.cxx \
|
test_dump_playlist_SOURCES = test/dump_playlist.cxx \
|
||||||
$(DECODER_SRC) \
|
$(DECODER_SRC) \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c\
|
||||||
src/uri.c \
|
src/uri.c \
|
||||||
src/Song.cxx src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
src/Song.cxx src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \
|
||||||
src/tag_handler.c src/tag_file.c \
|
src/tag_handler.c src/tag_file.c \
|
||||||
|
@ -1121,7 +1121,7 @@ test_run_decoder_LDADD = \
|
||||||
test_run_decoder_SOURCES = test/run_decoder.cxx \
|
test_run_decoder_SOURCES = test/run_decoder.cxx \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/tag_handler.c \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/tag_handler.c \
|
||||||
src/ReplayGainInfo.cxx \
|
src/ReplayGainInfo.cxx \
|
||||||
src/uri.c \
|
src/uri.c \
|
||||||
|
@ -1143,7 +1143,7 @@ test_read_tags_LDADD = \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
test_read_tags_SOURCES = test/read_tags.cxx \
|
test_read_tags_SOURCES = test/read_tags.cxx \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/tag_handler.c \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx src/tag_handler.c \
|
||||||
src/ReplayGainInfo.cxx \
|
src/ReplayGainInfo.cxx \
|
||||||
src/uri.c \
|
src/uri.c \
|
||||||
|
@ -1170,7 +1170,7 @@ test_run_filter_SOURCES = test/run_filter.c \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/filter_plugin.c \
|
src/filter_plugin.c \
|
||||||
src/filter_registry.c \
|
src/filter_registry.c \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/audio_format.c \
|
src/audio_format.c \
|
||||||
src/audio_parser.c \
|
src/audio_parser.c \
|
||||||
|
@ -1195,7 +1195,7 @@ noinst_PROGRAMS += test/run_encoder
|
||||||
test_run_encoder_SOURCES = test/run_encoder.c \
|
test_run_encoder_SOURCES = test/run_encoder.c \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/fifo_buffer.c src/growing_fifo.c \
|
src/fifo_buffer.c src/growing_fifo.c \
|
||||||
src/conf.c src/tokenizer.c \
|
src/ConfigFile.cxx src/tokenizer.c \
|
||||||
src/utils.c src/string_util.c \
|
src/utils.c src/string_util.c \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
|
@ -1212,7 +1212,7 @@ if ENABLE_VORBIS_ENCODER
|
||||||
noinst_PROGRAMS += test/test_vorbis_encoder
|
noinst_PROGRAMS += test/test_vorbis_encoder
|
||||||
test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.c \
|
test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.c \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/conf.c src/tokenizer.c \
|
src/ConfigFile.cxx src/tokenizer.c \
|
||||||
src/utils.c \
|
src/utils.c \
|
||||||
src/string_util.c \
|
src/string_util.c \
|
||||||
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
src/Tag.cxx src/TagNames.c src/TagPool.cxx \
|
||||||
|
@ -1266,7 +1266,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
|
||||||
test_run_output_SOURCES = test/run_output.cxx \
|
test_run_output_SOURCES = test/run_output.cxx \
|
||||||
test/FakeReplayGainConfig.cxx \
|
test/FakeReplayGainConfig.cxx \
|
||||||
test/stdbin.h \
|
test/stdbin.h \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c \
|
||||||
src/IOThread.cxx \
|
src/IOThread.cxx \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/audio_format.c \
|
src/audio_format.c \
|
||||||
|
@ -1295,7 +1295,7 @@ test_read_mixer_LDADD = \
|
||||||
$(OUTPUT_LIBS) \
|
$(OUTPUT_LIBS) \
|
||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
test_read_mixer_SOURCES = test/read_mixer.c \
|
test_read_mixer_SOURCES = test/read_mixer.c \
|
||||||
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
|
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c \
|
||||||
src/mixer_control.c src/mixer_api.c \
|
src/mixer_control.c src/mixer_api.c \
|
||||||
src/filter_plugin.c \
|
src/filter_plugin.c \
|
||||||
src/filter/volume_filter_plugin.c \
|
src/filter/volume_filter_plugin.c \
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -19,9 +19,13 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "string_util.h"
|
#include "string_util.h"
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
|
}
|
||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
|
|
||||||
|
@ -46,63 +50,68 @@ struct config_entry {
|
||||||
const bool block;
|
const bool block;
|
||||||
|
|
||||||
GSList *params;
|
GSList *params;
|
||||||
|
|
||||||
|
constexpr config_entry(const char *_name,
|
||||||
|
bool _repeatable, bool _block)
|
||||||
|
:name(_name), repeatable(_repeatable), block(_block),
|
||||||
|
params(nullptr) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct config_entry config_entries[] = {
|
static struct config_entry config_entries[] = {
|
||||||
{ .name = CONF_MUSIC_DIR, false, false },
|
{ CONF_MUSIC_DIR, false, false },
|
||||||
{ .name = CONF_PLAYLIST_DIR, false, false },
|
{ CONF_PLAYLIST_DIR, false, false },
|
||||||
{ .name = CONF_FOLLOW_INSIDE_SYMLINKS, false, false },
|
{ CONF_FOLLOW_INSIDE_SYMLINKS, false, false },
|
||||||
{ .name = CONF_FOLLOW_OUTSIDE_SYMLINKS, false, false },
|
{ CONF_FOLLOW_OUTSIDE_SYMLINKS, false, false },
|
||||||
{ .name = CONF_DB_FILE, false, false },
|
{ CONF_DB_FILE, false, false },
|
||||||
{ .name = CONF_STICKER_FILE, false, false },
|
{ CONF_STICKER_FILE, false, false },
|
||||||
{ .name = CONF_LOG_FILE, false, false },
|
{ CONF_LOG_FILE, false, false },
|
||||||
{ .name = CONF_PID_FILE, false, false },
|
{ CONF_PID_FILE, false, false },
|
||||||
{ .name = CONF_STATE_FILE, false, false },
|
{ CONF_STATE_FILE, false, false },
|
||||||
{ .name = "restore_paused", false, false },
|
{ "restore_paused", false, false },
|
||||||
{ .name = CONF_USER, false, false },
|
{ CONF_USER, false, false },
|
||||||
{ .name = CONF_GROUP, false, false },
|
{ CONF_GROUP, false, false },
|
||||||
{ .name = CONF_BIND_TO_ADDRESS, true, false },
|
{ CONF_BIND_TO_ADDRESS, true, false },
|
||||||
{ .name = CONF_PORT, false, false },
|
{ CONF_PORT, false, false },
|
||||||
{ .name = CONF_LOG_LEVEL, false, false },
|
{ CONF_LOG_LEVEL, false, false },
|
||||||
{ .name = CONF_ZEROCONF_NAME, false, false },
|
{ CONF_ZEROCONF_NAME, false, false },
|
||||||
{ .name = CONF_ZEROCONF_ENABLED, false, false },
|
{ CONF_ZEROCONF_ENABLED, false, false },
|
||||||
{ .name = CONF_PASSWORD, true, false },
|
{ CONF_PASSWORD, true, false },
|
||||||
{ .name = CONF_DEFAULT_PERMS, false, false },
|
{ CONF_DEFAULT_PERMS, false, false },
|
||||||
{ .name = CONF_AUDIO_OUTPUT, true, true },
|
{ CONF_AUDIO_OUTPUT, true, true },
|
||||||
{ .name = CONF_AUDIO_OUTPUT_FORMAT, false, false },
|
{ CONF_AUDIO_OUTPUT_FORMAT, false, false },
|
||||||
{ .name = CONF_MIXER_TYPE, false, false },
|
{ CONF_MIXER_TYPE, false, false },
|
||||||
{ .name = CONF_REPLAYGAIN, false, false },
|
{ CONF_REPLAYGAIN, false, false },
|
||||||
{ .name = CONF_REPLAYGAIN_PREAMP, false, false },
|
{ CONF_REPLAYGAIN_PREAMP, false, false },
|
||||||
{ .name = CONF_REPLAYGAIN_MISSING_PREAMP, false, false },
|
{ CONF_REPLAYGAIN_MISSING_PREAMP, false, false },
|
||||||
{ .name = CONF_REPLAYGAIN_LIMIT, false, false },
|
{ CONF_REPLAYGAIN_LIMIT, false, false },
|
||||||
{ .name = CONF_VOLUME_NORMALIZATION, false, false },
|
{ CONF_VOLUME_NORMALIZATION, false, false },
|
||||||
{ .name = CONF_SAMPLERATE_CONVERTER, false, false },
|
{ CONF_SAMPLERATE_CONVERTER, false, false },
|
||||||
{ .name = CONF_AUDIO_BUFFER_SIZE, false, false },
|
{ CONF_AUDIO_BUFFER_SIZE, false, false },
|
||||||
{ .name = CONF_BUFFER_BEFORE_PLAY, false, false },
|
{ CONF_BUFFER_BEFORE_PLAY, false, false },
|
||||||
{ .name = CONF_HTTP_PROXY_HOST, false, false },
|
{ CONF_HTTP_PROXY_HOST, false, false },
|
||||||
{ .name = CONF_HTTP_PROXY_PORT, false, false },
|
{ CONF_HTTP_PROXY_PORT, false, false },
|
||||||
{ .name = CONF_HTTP_PROXY_USER, false, false },
|
{ CONF_HTTP_PROXY_USER, false, false },
|
||||||
{ .name = CONF_HTTP_PROXY_PASSWORD, false, false },
|
{ CONF_HTTP_PROXY_PASSWORD, false, false },
|
||||||
{ .name = CONF_CONN_TIMEOUT, false, false },
|
{ CONF_CONN_TIMEOUT, false, false },
|
||||||
{ .name = CONF_MAX_CONN, false, false },
|
{ CONF_MAX_CONN, false, false },
|
||||||
{ .name = CONF_MAX_PLAYLIST_LENGTH, false, false },
|
{ CONF_MAX_PLAYLIST_LENGTH, false, false },
|
||||||
{ .name = CONF_MAX_COMMAND_LIST_SIZE, false, false },
|
{ CONF_MAX_COMMAND_LIST_SIZE, false, false },
|
||||||
{ .name = CONF_MAX_OUTPUT_BUFFER_SIZE, false, false },
|
{ CONF_MAX_OUTPUT_BUFFER_SIZE, false, false },
|
||||||
{ .name = CONF_FS_CHARSET, false, false },
|
{ CONF_FS_CHARSET, false, false },
|
||||||
{ .name = CONF_ID3V1_ENCODING, false, false },
|
{ CONF_ID3V1_ENCODING, false, false },
|
||||||
{ .name = CONF_METADATA_TO_USE, false, false },
|
{ CONF_METADATA_TO_USE, false, false },
|
||||||
{ .name = CONF_SAVE_ABSOLUTE_PATHS, false, false },
|
{ CONF_SAVE_ABSOLUTE_PATHS, false, false },
|
||||||
{ .name = CONF_DECODER, true, true },
|
{ CONF_DECODER, true, true },
|
||||||
{ .name = CONF_INPUT, true, true },
|
{ CONF_INPUT, true, true },
|
||||||
{ .name = CONF_GAPLESS_MP3_PLAYBACK, false, false },
|
{ CONF_GAPLESS_MP3_PLAYBACK, false, false },
|
||||||
{ .name = CONF_PLAYLIST_PLUGIN, true, true },
|
{ CONF_PLAYLIST_PLUGIN, true, true },
|
||||||
{ .name = CONF_AUTO_UPDATE, false, false },
|
{ CONF_AUTO_UPDATE, false, false },
|
||||||
{ .name = CONF_AUTO_UPDATE_DEPTH, false, false },
|
{ CONF_AUTO_UPDATE_DEPTH, false, false },
|
||||||
{ .name = CONF_DESPOTIFY_USER, false, false },
|
{ CONF_DESPOTIFY_USER, false, false },
|
||||||
{ .name = CONF_DESPOTIFY_PASSWORD, false, false},
|
{ CONF_DESPOTIFY_PASSWORD, false, false},
|
||||||
{ .name = CONF_DESPOTIFY_HIGH_BITRATE, false, false },
|
{ CONF_DESPOTIFY_HIGH_BITRATE, false, false },
|
||||||
{ .name = "filter", true, true },
|
{ "filter", true, true },
|
||||||
{ .name = "database", false, true },
|
{ "database", false, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -162,7 +171,7 @@ config_param_free(struct config_param *param)
|
||||||
static void
|
static void
|
||||||
config_param_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
config_param_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
||||||
{
|
{
|
||||||
struct config_param *param = data;
|
struct config_param *param = (struct config_param *)data;
|
||||||
|
|
||||||
config_param_free(param);
|
config_param_free(param);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +206,7 @@ void config_global_init(void)
|
||||||
static void
|
static void
|
||||||
config_param_check(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
config_param_check(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
||||||
{
|
{
|
||||||
struct config_param *param = data;
|
struct config_param *param = (struct config_param *)data;
|
||||||
|
|
||||||
if (!param->used)
|
if (!param->used)
|
||||||
/* this whole config_param was not queried at all -
|
/* this whole config_param was not queried at all -
|
||||||
|
@ -233,9 +242,10 @@ config_add_block_param(struct config_param * param, const char *name,
|
||||||
|
|
||||||
param->num_block_params++;
|
param->num_block_params++;
|
||||||
|
|
||||||
param->block_params = g_realloc(param->block_params,
|
param->block_params = (struct block_param *)
|
||||||
param->num_block_params *
|
g_realloc(param->block_params,
|
||||||
sizeof(param->block_params[0]));
|
param->num_block_params *
|
||||||
|
sizeof(param->block_params[0]));
|
||||||
|
|
||||||
bp = ¶m->block_params[param->num_block_params - 1];
|
bp = ¶m->block_params[param->num_block_params - 1];
|
||||||
|
|
||||||
|
@ -318,7 +328,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r)
|
||||||
g_set_error(error_r, config_quark(), 0,
|
g_set_error(error_r, config_quark(), 0,
|
||||||
"line %i: Unknown tokens after '}'",
|
"line %i: Unknown tokens after '}'",
|
||||||
*count);
|
*count);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -390,7 +400,7 @@ config_read_file(const char *file, GError **error_r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry->params != NULL && !entry->repeatable) {
|
if (entry->params != NULL && !entry->repeatable) {
|
||||||
param = entry->params->data;
|
param = (struct config_param *)entry->params->data;
|
||||||
g_set_error(error_r, config_quark(), 0,
|
g_set_error(error_r, config_quark(), 0,
|
||||||
"config parameter \"%s\" is first defined "
|
"config parameter \"%s\" is first defined "
|
||||||
"on line %i and redefined on line %i\n",
|
"on line %i and redefined on line %i\n",
|
||||||
|
@ -487,7 +497,7 @@ config_get_next_param(const char *name, const struct config_param * last)
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
param = node->data;
|
param = (struct config_param *)node->data;
|
||||||
param->used = true;
|
param->used = true;
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
Loading…
Reference in New Issue