PlaylistAny.cxx 1.89 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"
24
#include "PlaylistError.hxx"
Max Kellermann's avatar
Max Kellermann committed
25
#include "util/UriUtil.hxx"
26
#include "util/Error.hxx"
27
#include "InputStream.hxx"
28
#include "Log.hxx"
29

30 31
#include <assert.h>

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

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

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

50
		return nullptr;
51 52
	}

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

	*is_r = is;
	return playlist;
}

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