2015-01-21 21:50:02 +01:00
|
|
|
/*
|
2018-07-17 20:39:33 +02:00
|
|
|
* Copyright 2003-2018 The Music Player Daemon Project
|
2015-01-21 21:50:02 +01:00
|
|
|
* 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 "Data.hxx"
|
|
|
|
#include "Param.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "Block.hxx"
|
2018-07-17 21:18:18 +02:00
|
|
|
#include "util/RuntimeError.hxx"
|
2018-07-17 21:14:53 +02:00
|
|
|
#include "util/StringAPI.hxx"
|
2015-01-21 21:50:02 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ConfigData::Clear()
|
|
|
|
{
|
2015-01-21 22:56:20 +01:00
|
|
|
for (auto &i : params) {
|
2015-01-21 21:50:02 +01:00
|
|
|
delete i;
|
2015-01-21 22:56:20 +01:00
|
|
|
i = nullptr;
|
|
|
|
}
|
2015-01-21 22:13:44 +01:00
|
|
|
|
|
|
|
for (auto &i : blocks) {
|
|
|
|
delete i;
|
|
|
|
i = nullptr;
|
|
|
|
}
|
2015-01-21 21:50:02 +01:00
|
|
|
}
|
2018-07-17 21:14:53 +02:00
|
|
|
|
|
|
|
const ConfigBlock *
|
|
|
|
ConfigData::FindBlock(ConfigBlockOption option,
|
2018-07-17 21:18:18 +02:00
|
|
|
const char *key, const char *value) const
|
2018-07-17 21:14:53 +02:00
|
|
|
{
|
|
|
|
for (const auto *block = GetBlock(option);
|
|
|
|
block != nullptr; block = block->next) {
|
|
|
|
const char *value2 = block->GetBlockValue(key);
|
|
|
|
if (value2 == nullptr)
|
2018-07-17 21:18:18 +02:00
|
|
|
throw FormatRuntimeError("block without '%s' in line %d",
|
|
|
|
key, block->line);
|
2018-07-17 21:14:53 +02:00
|
|
|
|
|
|
|
if (StringIsEqual(value2, value))
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|