configure.ac: Don't allow UNIX IPC to be configured for a native Windows build.
[mpd-mk.git] / src / playlist_queue.c
blob4bda90c76d8614cec7a01c5da323ac58632a9a95
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "playlist_queue.h"
22 #include "playlist_list.h"
23 #include "playlist_plugin.h"
24 #include "playlist_mapper.h"
25 #include "playlist_song.h"
26 #include "stored_playlist.h"
27 #include "mapper.h"
28 #include "song.h"
29 #include "uri.h"
30 #include "input_stream.h"
32 enum playlist_result
33 playlist_load_into_queue(const char *uri, struct playlist_provider *source,
34 struct playlist *dest)
36 enum playlist_result result;
37 struct song *song;
38 char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;
40 while ((song = playlist_plugin_read(source)) != NULL) {
41 song = playlist_check_translate_song(song, base_uri);
42 if (song == NULL)
43 continue;
45 result = playlist_append_song(dest, song, NULL);
46 if (result != PLAYLIST_RESULT_SUCCESS) {
47 if (!song_in_database(song))
48 song_free(song);
49 g_free(base_uri);
50 return result;
54 g_free(base_uri);
56 return PLAYLIST_RESULT_SUCCESS;
59 static enum playlist_result
60 playlist_open_remote_into_queue(const char *uri, struct playlist *dest)
62 GError *error = NULL;
63 struct playlist_provider *playlist;
64 struct input_stream *is = NULL;
65 enum playlist_result result;
67 assert(uri_has_scheme(uri));
69 playlist = playlist_list_open_uri(uri);
70 if (playlist == NULL) {
71 is = input_stream_open(uri, &error);
72 if (is == NULL) {
73 if (error != NULL) {
74 g_warning("Failed to open %s: %s",
75 uri, error->message);
76 g_error_free(error);
79 return PLAYLIST_RESULT_NO_SUCH_LIST;
82 playlist = playlist_list_open_stream(is, uri);
83 if (playlist == NULL) {
84 input_stream_close(is);
85 return PLAYLIST_RESULT_NO_SUCH_LIST;
89 result = playlist_load_into_queue(uri, playlist, dest);
90 playlist_plugin_close(playlist);
92 if (is != NULL)
93 input_stream_close(is);
95 return result;
98 enum playlist_result
99 playlist_open_into_queue(const char *uri, struct playlist *dest)
101 if (uri_has_scheme(uri))
102 return playlist_open_remote_into_queue(uri, dest);
104 struct playlist_provider *playlist = playlist_mapper_open(uri);
105 if (playlist != NULL) {
106 enum playlist_result result =
107 playlist_load_into_queue(uri, playlist, dest);
108 playlist_plugin_close(playlist);
109 return result;
112 return PLAYLIST_RESULT_NO_SUCH_LIST;