Global.cxx 2.22 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
21
#include "Global.hxx"
22
#include "Migrate.hxx"
23
#include "Data.hxx"
24
#include "Block.hxx"
25 26 27
#include "File.hxx"
#include "Path.hxx"
#include "Domain.hxx"
28
#include "fs/Path.hxx"
29
#include "util/RuntimeError.hxx"
30
#include "Log.hxx"
31 32 33 34 35

static ConfigData config_data;

void config_global_finish(void)
{
36
	config_data.Clear();
37 38 39 40 41 42
}

void config_global_init(void)
{
}

43 44 45 46 47 48
const ConfigData &
GetGlobalConfig() noexcept
{
	return config_data;
}

49 50
void
ReadConfigFile(Path path)
51
{
52 53
	ReadConfigFile(config_data, path);
	Migrate(config_data);
54 55 56
}

static void
57
Check(const ConfigBlock &block)
58
{
59 60
	if (!block.used)
		/* this whole block was not queried at all -
61 62 63 64
		   the feature might be disabled at compile time?
		   Silently ignore it here. */
		return;

65
	for (const auto &i : block.block_params) {
66
		if (!i.used)
67 68 69
			FormatWarning(config_domain,
				      "option '%s' on line %i was not recognized",
				      i.name.c_str(), i.line);
70 71 72 73 74
	}
}

void config_global_check(void)
{
75 76 77
	for (const auto &list : config_data.blocks)
		for (const auto &block : list)
			Check(block);
78 79 80
}

const char *
81
config_get_string(ConfigOption option, const char *default_value) noexcept
82
{
83
	return config_data.GetString(option, default_value);
84 85 86 87 88
}

unsigned
config_get_positive(ConfigOption option, unsigned default_value)
{
89
	return config_data.GetPositive(option, default_value);
90 91 92 93 94
}

bool
config_get_bool(ConfigOption option, bool default_value)
{
95
	return config_data.GetBool(option, default_value);
96
}