input/icy: support "charset" parameter in URI fragment

Closes https://github.com/MusicPlayerDaemon/MPD/issues/616
This commit is contained in:
Max Kellermann
2019-08-09 15:44:09 +02:00
parent 4a47bbd816
commit cf9ee33928
4 changed files with 38 additions and 2 deletions

View File

@@ -20,11 +20,27 @@
#include "IcyInputStream.hxx"
#include "IcyMetaDataParser.hxx"
#include "tag/Tag.hxx"
#include "util/UriExtract.hxx"
#include "util/UriQueryParser.hxx"
#include "util/StringView.hxx"
#include <string>
IcyInputStream::IcyInputStream(InputStreamPtr _input,
std::shared_ptr<IcyMetaDataParser> _parser) noexcept
std::shared_ptr<IcyMetaDataParser> _parser)
:ProxyInputStream(std::move(_input)), parser(std::move(_parser))
{
#ifdef HAVE_ICU_CONVERTER
const char *fragment = uri_get_fragment(GetURI());
if (fragment != nullptr) {
const auto charset = UriFindRawQueryParameter(fragment,
"charset");
if (charset != nullptr) {
const std::string copy(charset.data, charset.size);
parser->SetCharset(copy.c_str());
}
}
#endif
}
IcyInputStream::~IcyInputStream() noexcept = default;

View File

@@ -52,9 +52,12 @@ public:
* with our input; it needs to be shared because our input
* needs to feed parameters (e.g. from the "icy-metaint"
* header) into it
*
* Throws on error (e.g. if the charset converter specified by
* the URI fragment fails to initialize).
*/
IcyInputStream(InputStreamPtr _input,
std::shared_ptr<IcyMetaDataParser> _parser) noexcept;
std::shared_ptr<IcyMetaDataParser> _parser);
virtual ~IcyInputStream() noexcept;
IcyInputStream(const IcyInputStream &) = delete;