PlaylistAny.cxx 1.87 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "config.h"
21 22
#include "PlaylistAny.hxx"
#include "PlaylistMapper.hxx"
23
#include "PlaylistRegistry.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "util/UriUtil.hxx"
25
#include "util/Error.hxx"
26
#include "InputStream.hxx"
27
#include "Log.hxx"
28

29 30
#include <assert.h>

31
static SongEnumerator *
32
playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
33
		     InputStream **is_r)
34 35 36
{
	assert(uri_has_scheme(uri));

37
	SongEnumerator *playlist = playlist_list_open_uri(uri, mutex, cond);
38 39
	if (playlist != nullptr) {
		*is_r = nullptr;
40 41 42
		return playlist;
	}

43
	Error error;
44
	InputStream *is = InputStream::OpenReady(uri, mutex, cond, error);
45
	if (is == nullptr) {
46
		if (error.IsDefined())
47
			FormatError(error, "Failed to open %s", uri);
48

49
		return nullptr;
50 51
	}

52
	playlist = playlist_list_open_stream(*is, uri);
53
	if (playlist == nullptr) {
54
		is->Close();
55
		return nullptr;
56 57 58 59 60 61
	}

	*is_r = is;
	return playlist;
}

62
SongEnumerator *
63
playlist_open_any(const char *uri, Mutex &mutex, Cond &cond,
64
		  InputStream **is_r)
65 66
{
	return uri_has_scheme(uri)
67 68
		? playlist_open_remote(uri, mutex, cond, is_r)
		: playlist_mapper_open(uri, mutex, cond, is_r);
69
}