ls.cxx 2.31 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 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
#include "client/Response.hxx"
23
#include "util/ASCII.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "util/UriUtil.hxx"
Max Kellermann's avatar
Max Kellermann committed
25

26
#include <assert.h>
27 28 29 30 31 32

/**
  * file:// is not included in remoteUrlPrefixes, the connection method
  * is detected at runtime and displayed as a urlhandler if the client is
  * connected by IPC socket.
  */
33
static const char *const remoteUrlPrefixes[] = {
34
#if defined(ENABLE_CURL)
Avuton Olrich's avatar
Avuton Olrich committed
35
	"http://",
Ales Guzik's avatar
Ales Guzik committed
36
	"https://",
37 38 39 40 41 42
#endif
#ifdef ENABLE_MMS
	"mms://",
	"mmsh://",
	"mmst://",
	"mmsu://",
43
#endif
44
#ifdef ENABLE_FFMPEG
45 46 47 48 49 50
	"gopher://",
	"rtp://",
	"rtsp://",
	"rtmp://",
	"rtmpt://",
	"rtmps://",
51
#endif
52 53 54
#ifdef ENABLE_SMBCLIENT
	"smb://",
#endif
55 56 57
#ifdef ENABLE_NFS
	"nfs://",
#endif
58 59
#ifdef ENABLE_CDIO_PARANOIA
	"cdda://",
60
#endif
61
#ifdef ENABLE_ALSA
62
	"alsa://",
63
#endif
64 65 66
#ifdef ENABLE_QOBUZ
	"qobuz://",
#endif
67 68
#ifdef ENABLE_TIDAL
	"tidal://",
Max Kellermann's avatar
Max Kellermann committed
69
#endif
70 71 72
	NULL
};

73 74
void print_supported_uri_schemes_to_fp(FILE *fp)
{
75
	const char *const*prefixes = remoteUrlPrefixes;
76 77

#ifdef HAVE_UN
78
	fprintf(fp, " file://");
79 80
#endif
	while (*prefixes) {
81
		fprintf(fp, " %s", *prefixes);
82 83
		prefixes++;
	}
84
	fprintf(fp,"\n");
85 86
}

87 88
void
print_supported_uri_schemes(Response &r)
Avuton Olrich's avatar
Avuton Olrich committed
89
{
90
	const char *const *prefixes = remoteUrlPrefixes;
91

Avuton Olrich's avatar
Avuton Olrich committed
92
	while (*prefixes) {
93
		r.Format("handler: %s\n", *prefixes);
Avuton Olrich's avatar
Avuton Olrich committed
94 95
		prefixes++;
	}
96 97
}

98 99
bool
uri_supported_scheme(const char *uri) noexcept
Avuton Olrich's avatar
Avuton Olrich committed
100
{
101
	const char *const*urlPrefixes = remoteUrlPrefixes;
102

103 104
	assert(uri_has_scheme(uri));

Avuton Olrich's avatar
Avuton Olrich committed
105
	while (*urlPrefixes) {
106
		if (StringStartsWithCaseASCII(uri, *urlPrefixes))
Max Kellermann's avatar
Max Kellermann committed
107
			return true;
108
		urlPrefixes++;
109 110
	}

Max Kellermann's avatar
Max Kellermann committed
111
	return false;
112
}