Commit 4d117451 authored by Max Kellermann's avatar Max Kellermann

playlist/Plugin: add SupportsSuffix(), SupportsMimeType()

parent 2038620b
/*
* Copyright 2003-2019 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 "PlaylistPlugin.hxx"
#include "util/StringUtil.hxx"
#include "util/StringView.hxx"
bool
PlaylistPlugin::SupportsScheme(StringView scheme) const noexcept
{
return schemes != nullptr &&
StringArrayContainsCase(schemes, scheme);
}
bool
PlaylistPlugin::SupportsSuffix(const char *suffix) const noexcept
{
return suffixes != nullptr &&
StringArrayContainsCase(suffixes, suffix);
}
bool
PlaylistPlugin::SupportsMimeType(StringView mime_type) const noexcept
{
return mime_types != nullptr &&
StringArrayContainsCase(mime_types, mime_type);
}
......@@ -22,9 +22,11 @@
#include "input/Ptr.hxx"
#include "thread/Mutex.hxx"
#include "util/Compiler.h"
struct ConfigBlock;
struct Tag;
struct StringView;
class SongEnumerator;
struct PlaylistPlugin {
......@@ -101,6 +103,24 @@ struct PlaylistPlugin {
copy.mime_types = _mime_types;
return copy;
}
/**
* Does the plugin announce the specified URI scheme?
*/
gcc_pure gcc_nonnull_all
bool SupportsScheme(StringView scheme) const noexcept;
/**
* Does the plugin announce the specified file name suffix?
*/
gcc_pure gcc_nonnull_all
bool SupportsSuffix(const char *suffix) const noexcept;
/**
* Does the plugin announce the specified MIME type?
*/
gcc_pure gcc_nonnull_all
bool SupportsMimeType(StringView mime_type) const noexcept;
};
/**
......
......@@ -33,7 +33,6 @@
#include "plugins/EmbeddedCuePlaylistPlugin.hxx"
#include "input/InputStream.hxx"
#include "util/MimeType.hxx"
#include "util/StringUtil.hxx"
#include "util/StringView.hxx"
#include "util/UriExtract.hxx"
#include "config/Data.hxx"
......@@ -122,8 +121,7 @@ playlist_list_open_uri_scheme(const char *uri, Mutex &mutex,
assert(!tried[i]);
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
plugin->schemes != nullptr &&
StringArrayContainsCase(plugin->schemes, scheme)) {
plugin->SupportsScheme(scheme)) {
auto playlist = plugin->open_uri(uri, mutex);
if (playlist)
return playlist;
......@@ -150,8 +148,8 @@ playlist_list_open_uri_suffix(const char *uri, Mutex &mutex,
const auto *plugin = playlist_plugins[i];
if (playlist_plugins_enabled[i] && !tried[i] &&
plugin->open_uri != nullptr && plugin->suffixes != nullptr &&
StringArrayContainsCase(plugin->suffixes, suffix)) {
plugin->open_uri != nullptr &&
plugin->SupportsSuffix(suffix)) {
auto playlist = plugin->open_uri(uri, mutex);
if (playlist != nullptr)
return playlist;
......@@ -183,8 +181,7 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime)
{
playlist_plugins_for_each_enabled(plugin) {
if (plugin->open_stream != nullptr &&
plugin->mime_types != nullptr &&
StringArrayContainsCase(plugin->mime_types, mime)) {
plugin->SupportsMimeType(mime)) {
/* rewind the stream, so each plugin gets a
fresh start */
try {
......@@ -233,8 +230,7 @@ playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
playlist_plugins_for_each_enabled(plugin) {
if (plugin->open_stream != nullptr &&
plugin->suffixes != nullptr &&
StringArrayContainsCase(plugin->suffixes, suffix)) {
plugin->SupportsSuffix(suffix)) {
/* rewind the stream, so each plugin gets a
fresh start */
try {
......@@ -284,8 +280,7 @@ playlist_suffix_supported(const char *suffix) noexcept
assert(suffix != nullptr);
playlist_plugins_for_each_enabled(plugin) {
if (plugin->suffixes != nullptr &&
StringArrayContainsCase(plugin->suffixes, suffix))
if (plugin->SupportsSuffix(suffix))
return true;
}
......
playlist_api = static_library(
'playlist_api',
'PlaylistPlugin.cxx',
'MemorySongEnumerator.cxx',
include_directories: inc,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment