ls.cxx 1.82 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20
#include "config.h"
Max Kellermann's avatar
Max Kellermann committed
21
#include "ls.hxx"
22 23
#include "input/Registry.hxx"
#include "input/InputPlugin.hxx"
24
#include "client/Response.hxx"
Max Kellermann's avatar
Max Kellermann committed
25
#include "util/UriExtract.hxx"
Max Kellermann's avatar
Max Kellermann committed
26

27
#include <cassert>
28

29 30
#include <string>

31 32 33
void print_supported_uri_schemes_to_fp(FILE *fp)
{
#ifdef HAVE_UN
34
	fprintf(fp, " file://");
35
#endif
36
	std::set<std::string> protocols;
37
	input_plugins_for_each(plugin)
38 39 40
		plugin->ForeachSupportedUri([&](const char* uri) {
			protocols.emplace(uri);
		});
Max Kellermann's avatar
Max Kellermann committed
41

42
	for (const auto& protocol : protocols) {
43 44
		fprintf(fp, " %s", protocol.c_str());
	}
45
	fprintf(fp,"\n");
46 47
}

48 49
void
print_supported_uri_schemes(Response &r)
Avuton Olrich's avatar
Avuton Olrich committed
50
{
51
	std::set<std::string> protocols;
52
	input_plugins_for_each_enabled(plugin)
53 54 55 56
		plugin->ForeachSupportedUri([&](const char* uri) {
			protocols.emplace(uri);
		});

57
	for (const auto& protocol : protocols) {
58 59
		r.Format("handler: %s\n", protocol.c_str());
	}
60 61
}

62 63
bool
uri_supported_scheme(const char *uri) noexcept
Avuton Olrich's avatar
Avuton Olrich committed
64
{
65 66
	assert(uri_has_scheme(uri));

67
	input_plugins_for_each_enabled(plugin)
68 69
		if (plugin->SupportsUri(uri))
			return true;
70

Max Kellermann's avatar
Max Kellermann committed
71
	return false;
72
}