ls.cxx 2.22 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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/StringCompare.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://",
Max Kellermann's avatar
Max Kellermann committed
63
#endif
64 65 66
	NULL
};

67 68
void print_supported_uri_schemes_to_fp(FILE *fp)
{
69
	const char *const*prefixes = remoteUrlPrefixes;
70 71

#ifdef HAVE_UN
72
	fprintf(fp, " file://");
73 74
#endif
	while (*prefixes) {
75
		fprintf(fp, " %s", *prefixes);
76 77
		prefixes++;
	}
78
	fprintf(fp,"\n");
79 80
}

81 82
void
print_supported_uri_schemes(Response &r)
Avuton Olrich's avatar
Avuton Olrich committed
83
{
84
	const char *const *prefixes = remoteUrlPrefixes;
85

Avuton Olrich's avatar
Avuton Olrich committed
86
	while (*prefixes) {
87
		r.Format("handler: %s\n", *prefixes);
Avuton Olrich's avatar
Avuton Olrich committed
88 89
		prefixes++;
	}
90 91
}

92
bool uri_supported_scheme(const char *uri)
Avuton Olrich's avatar
Avuton Olrich committed
93
{
94
	const char *const*urlPrefixes = remoteUrlPrefixes;
95

96 97
	assert(uri_has_scheme(uri));

Avuton Olrich's avatar
Avuton Olrich committed
98
	while (*urlPrefixes) {
99
		if (StringStartsWith(uri, *urlPrefixes))
Max Kellermann's avatar
Max Kellermann committed
100
			return true;
101
		urlPrefixes++;
102 103
	}

Max Kellermann's avatar
Max Kellermann committed
104
	return false;
105
}