diff options
author | Max Kellermann <max@musicpd.org> | 2018-07-18 09:42:56 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-07-18 10:25:02 +0200 |
commit | 49efb6071cbb42384ba8abb7a4696a375c1f8f36 (patch) | |
tree | dd8c6aba8f2ac9fd443ca48619794d220ca88b1d /src/config | |
parent | 8df98932b111bf1cdd219d47f3e418761d38d664 (diff) |
config/Migrate: library to migrate deprecated settings
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/Data.cxx | 15 | ||||
-rw-r--r-- | src/config/Data.hxx | 3 | ||||
-rw-r--r-- | src/config/Global.cxx | 4 | ||||
-rw-r--r-- | src/config/Migrate.cxx | 63 | ||||
-rw-r--r-- | src/config/Migrate.hxx | 31 |
5 files changed, 115 insertions, 1 deletions
diff --git a/src/config/Data.cxx b/src/config/Data.cxx index cd43e7cff..f8518aa3d 100644 --- a/src/config/Data.cxx +++ b/src/config/Data.cxx @@ -180,3 +180,18 @@ ConfigData::FindBlock(ConfigBlockOption option, return nullptr; } + +ConfigBlock & +ConfigData::MakeBlock(ConfigBlockOption option, + const char *key, const char *value) +{ + auto *block = const_cast<ConfigBlock *>(FindBlock(option, key, value)); + if (block == nullptr) { + auto new_block = std::make_unique<ConfigBlock>(); + new_block->AddBlockParam(key, value); + block = new_block.get(); + AddBlock(option, std::move(new_block)); + } + + return *block; +} diff --git a/src/config/Data.hxx b/src/config/Data.hxx index 65ec0af84..d58948489 100644 --- a/src/config/Data.hxx +++ b/src/config/Data.hxx @@ -101,6 +101,9 @@ struct ConfigData { gcc_pure const ConfigBlock *FindBlock(ConfigBlockOption option, const char *key, const char *value) const; + + ConfigBlock &MakeBlock(ConfigBlockOption option, + const char *key, const char *value); }; #endif diff --git a/src/config/Global.cxx b/src/config/Global.cxx index 62c7eb159..fceb5b603 100644 --- a/src/config/Global.cxx +++ b/src/config/Global.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "Global.hxx" +#include "Migrate.hxx" #include "Data.hxx" #include "Block.hxx" #include "File.hxx" @@ -48,7 +49,8 @@ GetGlobalConfig() noexcept void ReadConfigFile(Path path) { - return ReadConfigFile(config_data, path); + ReadConfigFile(config_data, path); + Migrate(config_data); } static void diff --git a/src/config/Migrate.cxx b/src/config/Migrate.cxx new file mode 100644 index 000000000..9c1ebf7df --- /dev/null +++ b/src/config/Migrate.cxx @@ -0,0 +1,63 @@ +/* + * Copyright 2003-2018 The Music Player Daemon Project + * 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" +#include "Migrate.hxx" +#include "Data.hxx" +#include "Block.hxx" + +static void +MigrateParamToBlockParam(ConfigData &config, ConfigOption old_option, + ConfigBlockOption new_block_option, + const char *block_id_key, const char *block_id_value, + const char *block_value_key) noexcept +{ + const auto *param = config.GetParam(old_option); + if (param == nullptr) + return; + + auto &block = config.MakeBlock(new_block_option, + block_id_key, block_id_value); + if (block.GetBlockParam(block_value_key) == nullptr) + block.AddBlockParam(block_value_key, param->value, + param->line); +} + +static void +MigrateCurlProxyConfig(ConfigData &config) noexcept +{ + MigrateParamToBlockParam(config, ConfigOption::HTTP_PROXY_HOST, + ConfigBlockOption::INPUT, "plugin", "curl", + "proxy"); + MigrateParamToBlockParam(config, ConfigOption::HTTP_PROXY_PORT, + ConfigBlockOption::INPUT, "plugin", "curl", + "proxy_port"); + MigrateParamToBlockParam(config, ConfigOption::HTTP_PROXY_USER, + ConfigBlockOption::INPUT, "plugin", "curl", + "proxy_user"); + MigrateParamToBlockParam(config, ConfigOption::HTTP_PROXY_PASSWORD, + ConfigBlockOption::INPUT, "plugin", "curl", + "proxy_password"); +} + +void +Migrate(ConfigData &config) noexcept +{ + MigrateCurlProxyConfig(config); +} diff --git a/src/config/Migrate.hxx b/src/config/Migrate.hxx new file mode 100644 index 000000000..6c0774386 --- /dev/null +++ b/src/config/Migrate.hxx @@ -0,0 +1,31 @@ +/* + * Copyright 2003-2018 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_CONFIG_MIGRATE_HXX +#define MPD_CONFIG_MIGRATE_HXX + +struct ConfigData; + +/** + * Migrate deprecated #Config settings to new-style settings. + */ +void +Migrate(ConfigData &config) noexcept; + +#endif |