From 67b46a151da4ca6f81fa63d30e2c629da352ec45 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 2 Jan 2013 18:38:32 +0100 Subject: playlist_{any,song,queue}: convert to C++ --- Makefile.am | 11 ++- src/PlaylistAny.cxx | 74 ++++++++++++++++++++ src/PlaylistAny.hxx | 41 +++++++++++ src/PlaylistCommands.cxx | 4 +- src/PlaylistMapper.cxx | 4 +- src/PlaylistMapper.h | 43 ------------ src/PlaylistMapper.hxx | 39 +++++++++++ src/PlaylistPrint.cxx | 6 +- src/PlaylistQueue.cxx | 98 +++++++++++++++++++++++++++ src/PlaylistQueue.hxx | 61 +++++++++++++++++ src/PlaylistSong.cxx | 173 +++++++++++++++++++++++++++++++++++++++++++++++ src/PlaylistSong.hxx | 37 ++++++++++ src/playlist_any.c | 71 ------------------- src/playlist_any.h | 41 ----------- src/playlist_queue.c | 95 -------------------------- src/playlist_queue.h | 61 ----------------- src/playlist_song.c | 170 ---------------------------------------------- src/playlist_song.h | 37 ---------- 18 files changed, 534 insertions(+), 532 deletions(-) create mode 100644 src/PlaylistAny.cxx create mode 100644 src/PlaylistAny.hxx delete mode 100644 src/PlaylistMapper.h create mode 100644 src/PlaylistMapper.hxx create mode 100644 src/PlaylistQueue.cxx create mode 100644 src/PlaylistQueue.hxx create mode 100644 src/PlaylistSong.cxx create mode 100644 src/PlaylistSong.hxx delete mode 100644 src/playlist_any.c delete mode 100644 src/playlist_any.h delete mode 100644 src/playlist_queue.c delete mode 100644 src/playlist_queue.h delete mode 100644 src/playlist_song.c delete mode 100644 src/playlist_song.h diff --git a/Makefile.am b/Makefile.am index 3f462db45..4f6b82388 100644 --- a/Makefile.am +++ b/Makefile.am @@ -151,9 +151,6 @@ mpd_headers = \ src/playlist_state.h \ src/playlist_plugin.h \ src/playlist_list.h \ - src/playlist_any.h \ - src/playlist_song.h \ - src/playlist_queue.h \ src/playlist_vector.h \ src/playlist_database.h \ src/playlist/extm3u_playlist_plugin.h \ @@ -317,11 +314,11 @@ src_mpd_SOURCES = \ src/playlist_edit.c \ src/PlaylistPrint.cxx src/PlaylistPrint.hxx \ src/PlaylistSave.cxx src/PlaylistSave.hxx \ - src/PlaylistMapper.cxx src/PlaylistMapper.h \ - src/playlist_any.c \ - src/playlist_song.c \ + src/PlaylistMapper.cxx src/PlaylistMapper.hxx \ + src/PlaylistAny.cxx src/PlaylistAny.hxx \ + src/PlaylistSong.cxx src/PlaylistSong.hxx \ src/playlist_state.c \ - src/playlist_queue.c \ + src/PlaylistQueue.cxx src/PlaylistQueue.hxx \ src/playlist_vector.c \ src/playlist_database.c \ src/queue.c \ diff --git a/src/PlaylistAny.cxx b/src/PlaylistAny.cxx new file mode 100644 index 000000000..efa975a1f --- /dev/null +++ b/src/PlaylistAny.cxx @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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" +#include "PlaylistAny.hxx" +#include "PlaylistMapper.hxx" + +extern "C" { +#include "playlist_list.h" +#include "uri.h" +#include "input_stream.h" +} + +#include + +static struct playlist_provider * +playlist_open_remote(const char *uri, GMutex *mutex, GCond *cond, + struct input_stream **is_r) +{ + assert(uri_has_scheme(uri)); + + struct playlist_provider *playlist = + playlist_list_open_uri(uri, mutex, cond); + if (playlist != NULL) { + *is_r = NULL; + return playlist; + } + + GError *error = NULL; + struct input_stream *is = input_stream_open(uri, mutex, cond, &error); + if (is == NULL) { + if (error != NULL) { + g_warning("Failed to open %s: %s", + uri, error->message); + g_error_free(error); + } + + return NULL; + } + + playlist = playlist_list_open_stream(is, uri); + if (playlist == NULL) { + input_stream_close(is); + return NULL; + } + + *is_r = is; + return playlist; +} + +struct playlist_provider * +playlist_open_any(const char *uri, GMutex *mutex, GCond *cond, + struct input_stream **is_r) +{ + return uri_has_scheme(uri) + ? playlist_open_remote(uri, mutex, cond, is_r) + : playlist_mapper_open(uri, mutex, cond, is_r); +} diff --git a/src/PlaylistAny.hxx b/src/PlaylistAny.hxx new file mode 100644 index 000000000..fbc325420 --- /dev/null +++ b/src/PlaylistAny.hxx @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_PLAYLIST_ANY_HXX +#define MPD_PLAYLIST_ANY_HXX + +#include + +struct playlist_provider; +struct input_stream; + +/** + * Opens a playlist from the specified URI, which can be either an + * absolute remote URI (with a scheme) or a relative path to the + * music orplaylist directory. + * + * @param is_r on success, an input_stream object may be returned + * here, which must be closed after the playlist_provider object is + * freed + */ +struct playlist_provider * +playlist_open_any(const char *uri, GMutex *mutex, GCond *cond, + struct input_stream **is_r); + +#endif diff --git a/src/PlaylistCommands.cxx b/src/PlaylistCommands.cxx index 2b5f0b2cf..ed2f47519 100644 --- a/src/PlaylistCommands.cxx +++ b/src/PlaylistCommands.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,12 +24,12 @@ #include "PlaylistPrint.hxx" #include "PlaylistSave.hxx" #include "PlaylistFile.hxx" +#include "PlaylistQueue.hxx" extern "C" { #include "protocol/argparser.h" #include "protocol/result.h" #include "playlist.h" -#include "playlist_queue.h" #include "time_print.h" #include "ls.h" #include "uri.h" diff --git a/src/PlaylistMapper.cxx b/src/PlaylistMapper.cxx index 39ac043e4..f1c9471a7 100644 --- a/src/PlaylistMapper.cxx +++ b/src/PlaylistMapper.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ */ #include "config.h" -#include "PlaylistMapper.h" +#include "PlaylistMapper.hxx" #include "PlaylistFile.hxx" extern "C" { diff --git a/src/PlaylistMapper.h b/src/PlaylistMapper.h deleted file mode 100644 index 829aac988..000000000 --- a/src/PlaylistMapper.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2003-2012 The Music Player Daemon Project - * 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. - */ - -#ifndef MPD_PLAYLIST_MAPPER_H -#define MPD_PLAYLIST_MAPPER_H - -#include - -struct input_stream; - -G_BEGIN_DECLS - -/** - * Opens a playlist from an URI relative to the playlist or music - * directory. - * - * @param is_r on success, an input_stream object may be returned - * here, which must be closed after the playlist_provider object is - * freed - */ -struct playlist_provider * -playlist_mapper_open(const char *uri, GMutex *mutex, GCond *cond, - struct input_stream **is_r); - -G_END_DECLS - -#endif diff --git a/src/PlaylistMapper.hxx b/src/PlaylistMapper.hxx new file mode 100644 index 000000000..dc4e5cce8 --- /dev/null +++ b/src/PlaylistMapper.hxx @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_PLAYLIST_MAPPER_HXX +#define MPD_PLAYLIST_MAPPER_HXX + +#include + +struct input_stream; + +/** + * Opens a playlist from an URI relative to the playlist or music + * directory. + * + * @param is_r on success, an input_stream object may be returned + * here, which must be closed after the playlist_provider object is + * freed + */ +struct playlist_provider * +playlist_mapper_open(const char *uri, GMutex *mutex, GCond *cond, + struct input_stream **is_r); + +#endif diff --git a/src/PlaylistPrint.cxx b/src/PlaylistPrint.cxx index 40b895f80..93970076f 100644 --- a/src/PlaylistPrint.cxx +++ b/src/PlaylistPrint.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -20,13 +20,13 @@ #include "config.h" #include "PlaylistPrint.hxx" #include "PlaylistFile.hxx" +#include "PlaylistAny.hxx" +#include "PlaylistSong.hxx" #include "QueuePrint.hxx" extern "C" { #include "playlist_list.h" #include "playlist_plugin.h" -#include "playlist_any.h" -#include "playlist_song.h" #include "playlist.h" #include "song_print.h" #include "song.h" diff --git a/src/PlaylistQueue.cxx b/src/PlaylistQueue.cxx new file mode 100644 index 000000000..ad9739449 --- /dev/null +++ b/src/PlaylistQueue.cxx @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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" +#include "PlaylistQueue.hxx" +#include "playlist_plugin.h" +#include "PlaylistAny.hxx" +#include "PlaylistSong.hxx" + +extern "C" { +#include "playlist.h" +#include "song.h" +#include "input_stream.h" +} + +enum playlist_result +playlist_load_into_queue(const char *uri, struct playlist_provider *source, + unsigned start_index, unsigned end_index, + struct playlist *dest, struct player_control *pc, + bool secure) +{ + enum playlist_result result; + struct song *song; + char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL; + + for (unsigned i = 0; + i < end_index && (song = playlist_plugin_read(source)) != NULL; + ++i) { + if (i < start_index) { + /* skip songs before the start index */ + song_free(song); + continue; + } + + song = playlist_check_translate_song(song, base_uri, secure); + if (song == NULL) + continue; + + result = playlist_append_song(dest, pc, song, NULL); + song_free(song); + if (result != PLAYLIST_RESULT_SUCCESS) { + g_free(base_uri); + return result; + } + } + + g_free(base_uri); + + return PLAYLIST_RESULT_SUCCESS; +} + +enum playlist_result +playlist_open_into_queue(const char *uri, + unsigned start_index, unsigned end_index, + struct playlist *dest, struct player_control *pc, + bool secure) +{ + GMutex *mutex = g_mutex_new(); + GCond *cond = g_cond_new(); + + struct input_stream *is; + struct playlist_provider *playlist = + playlist_open_any(uri, mutex, cond, &is); + if (playlist == NULL) { + g_cond_free(cond); + g_mutex_free(mutex); + return PLAYLIST_RESULT_NO_SUCH_LIST; + } + + enum playlist_result result = + playlist_load_into_queue(uri, playlist, start_index, end_index, + dest, pc, secure); + playlist_plugin_close(playlist); + + if (is != NULL) + input_stream_close(is); + + g_cond_free(cond); + g_mutex_free(mutex); + + return result; +} diff --git a/src/PlaylistQueue.hxx b/src/PlaylistQueue.hxx new file mode 100644 index 000000000..e1d3bf391 --- /dev/null +++ b/src/PlaylistQueue.hxx @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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. + */ + +/*! \file + * \brief Glue between playlist plugin and the play queue + */ + +#ifndef MPD_PLAYLIST_QUEUE_HXX +#define MPD_PLAYLIST_QUEUE_HXX + +#include "playlist_error.h" + +#include + +struct playlist_provider; +struct playlist; +struct player_control; + +/** + * Loads the contents of a playlist and append it to the specified + * play queue. + * + * @param uri the URI of the playlist, used to resolve relative song + * URIs + * @param start_index the index of the first song + * @param end_index the index of the last song (excluding) + */ +enum playlist_result +playlist_load_into_queue(const char *uri, struct playlist_provider *source, + unsigned start_index, unsigned end_index, + struct playlist *dest, struct player_control *pc, + bool secure); + +/** + * Opens a playlist with a playlist plugin and append to the specified + * play queue. + */ +enum playlist_result +playlist_open_into_queue(const char *uri, + unsigned start_index, unsigned end_index, + struct playlist *dest, struct player_control *pc, + bool secure); + +#endif + diff --git a/src/PlaylistSong.cxx b/src/PlaylistSong.cxx new file mode 100644 index 000000000..03bf5b703 --- /dev/null +++ b/src/PlaylistSong.cxx @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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" +#include "PlaylistSong.hxx" + +extern "C" { +#include "database.h" +#include "mapper.h" +#include "song.h" +#include "uri.h" +#include "path.h" +#include "ls.h" +#include "tag.h" +} + +#include +#include + +static void +merge_song_metadata(struct song *dest, const struct song *base, + const struct song *add) +{ + dest->tag = base->tag != NULL + ? (add->tag != NULL + ? tag_merge(base->tag, add->tag) + : tag_dup(base->tag)) + : (add->tag != NULL + ? tag_dup(add->tag) + : NULL); + + dest->mtime = base->mtime; + dest->start_ms = add->start_ms; + dest->end_ms = add->end_ms; +} + +static struct song * +apply_song_metadata(struct song *dest, const struct song *src) +{ + struct song *tmp; + + assert(dest != NULL); + assert(src != NULL); + + if (src->tag == NULL && src->start_ms == 0 && src->end_ms == 0) + return dest; + + if (song_in_database(dest)) { + char *path_fs = map_song_fs(dest); + if (path_fs == NULL) + return dest; + + char *path_utf8 = fs_charset_to_utf8(path_fs); + if (path_utf8 != NULL) + g_free(path_fs); + else + path_utf8 = path_fs; + + tmp = song_file_new(path_utf8, NULL); + g_free(path_utf8); + + merge_song_metadata(tmp, dest, src); + } else { + tmp = song_file_new(dest->uri, NULL); + merge_song_metadata(tmp, dest, src); + } + + if (dest->tag != NULL && dest->tag->time > 0 && + src->start_ms > 0 && src->end_ms == 0 && + src->start_ms / 1000 < (unsigned)dest->tag->time) + /* the range is open-ended, and the playlist plugin + did not know the total length of the song file + (e.g. last track on a CUE file); fix it up here */ + tmp->tag->time = dest->tag->time - src->start_ms / 1000; + + song_free(dest); + return tmp; +} + +static struct song * +playlist_check_load_song(const struct song *song, const char *uri, bool secure) +{ + struct song *dest; + + if (uri_has_scheme(uri)) { + dest = song_remote_new(uri); + } else if (g_path_is_absolute(uri) && secure) { + dest = song_file_load(uri, NULL); + if (dest == NULL) + return NULL; + } else { + struct song *tmp = db_get_song(uri); + if (tmp == NULL) + /* not found in database */ + return NULL; + + dest = song_dup_detached(tmp); + db_return_song(tmp); + } + + return apply_song_metadata(dest, song); +} + +struct song * +playlist_check_translate_song(struct song *song, const char *base_uri, + bool secure) +{ + if (song_in_database(song)) + /* already ok */ + return song; + + const char *uri = song->uri; + + if (uri_has_scheme(uri)) { + if (uri_supported_scheme(uri)) + /* valid remote song */ + return song; + else { + /* unsupported remote song */ + song_free(song); + return NULL; + } + } + + if (base_uri != NULL && strcmp(base_uri, ".") == 0) + /* g_path_get_dirname() returns "." when there is no + directory name in the given path; clear that now, + because it would break the database lookup + functions */ + base_uri = NULL; + + if (g_path_is_absolute(uri)) { + /* XXX fs_charset vs utf8? */ + const char *suffix = map_to_relative_path(uri); + assert(suffix != NULL); + + if (suffix != uri) + uri = suffix; + else if (!secure) { + /* local files must be relative to the music + directory when "secure" is enabled */ + song_free(song); + return NULL; + } + + base_uri = NULL; + } + + char *allocated = NULL; + if (base_uri != NULL) + uri = allocated = g_build_filename(base_uri, uri, NULL); + + struct song *dest = playlist_check_load_song(song, uri, secure); + song_free(song); + g_free(allocated); + return dest; +} diff --git a/src/PlaylistSong.hxx b/src/PlaylistSong.hxx new file mode 100644 index 000000000..f6959715a --- /dev/null +++ b/src/PlaylistSong.hxx @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_PLAYLIST_SONG_HXX +#define MPD_PLAYLIST_SONG_HXX + +#include + +/** + * Verifies the song, returns NULL if it is unsafe. Translate the + * song to a new song object within the database, if it is a local + * file. The old song object is freed. + * + * @param secure if true, then local files are only allowed if they + * are relative to base_uri + */ +struct song * +playlist_check_translate_song(struct song *song, const char *base_uri, + bool secure); + +#endif diff --git a/src/playlist_any.c b/src/playlist_any.c deleted file mode 100644 index e4017ac0d..000000000 --- a/src/playlist_any.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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" -#include "playlist_any.h" -#include "playlist_list.h" -#include "PlaylistMapper.h" -#include "uri.h" -#include "input_stream.h" - -#include - -static struct playlist_provider * -playlist_open_remote(const char *uri, GMutex *mutex, GCond *cond, - struct input_stream **is_r) -{ - assert(uri_has_scheme(uri)); - - struct playlist_provider *playlist = - playlist_list_open_uri(uri, mutex, cond); - if (playlist != NULL) { - *is_r = NULL; - return playlist; - } - - GError *error = NULL; - struct input_stream *is = input_stream_open(uri, mutex, cond, &error); - if (is == NULL) { - if (error != NULL) { - g_warning("Failed to open %s: %s", - uri, error->message); - g_error_free(error); - } - - return NULL; - } - - playlist = playlist_list_open_stream(is, uri); - if (playlist == NULL) { - input_stream_close(is); - return NULL; - } - - *is_r = is; - return playlist; -} - -struct playlist_provider * -playlist_open_any(const char *uri, GMutex *mutex, GCond *cond, - struct input_stream **is_r) -{ - return uri_has_scheme(uri) - ? playlist_open_remote(uri, mutex, cond, is_r) - : playlist_mapper_open(uri, mutex, cond, is_r); -} diff --git a/src/playlist_any.h b/src/playlist_any.h deleted file mode 100644 index 310913de9..000000000 --- a/src/playlist_any.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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. - */ - -#ifndef MPD_PLAYLIST_ANY_H -#define MPD_PLAYLIST_ANY_H - -#include - -struct playlist_provider; -struct input_stream; - -/** - * Opens a playlist from the specified URI, which can be either an - * absolute remote URI (with a scheme) or a relative path to the - * music orplaylist directory. - * - * @param is_r on success, an input_stream object may be returned - * here, which must be closed after the playlist_provider object is - * freed - */ -struct playlist_provider * -playlist_open_any(const char *uri, GMutex *mutex, GCond *cond, - struct input_stream **is_r); - -#endif diff --git a/src/playlist_queue.c b/src/playlist_queue.c deleted file mode 100644 index 8eb535dbd..000000000 --- a/src/playlist_queue.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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" -#include "playlist_queue.h" -#include "playlist_plugin.h" -#include "playlist_any.h" -#include "playlist_song.h" -#include "playlist.h" -#include "song.h" -#include "input_stream.h" - -enum playlist_result -playlist_load_into_queue(const char *uri, struct playlist_provider *source, - unsigned start_index, unsigned end_index, - struct playlist *dest, struct player_control *pc, - bool secure) -{ - enum playlist_result result; - struct song *song; - char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL; - - for (unsigned i = 0; - i < end_index && (song = playlist_plugin_read(source)) != NULL; - ++i) { - if (i < start_index) { - /* skip songs before the start index */ - song_free(song); - continue; - } - - song = playlist_check_translate_song(song, base_uri, secure); - if (song == NULL) - continue; - - result = playlist_append_song(dest, pc, song, NULL); - song_free(song); - if (result != PLAYLIST_RESULT_SUCCESS) { - g_free(base_uri); - return result; - } - } - - g_free(base_uri); - - return PLAYLIST_RESULT_SUCCESS; -} - -enum playlist_result -playlist_open_into_queue(const char *uri, - unsigned start_index, unsigned end_index, - struct playlist *dest, struct player_control *pc, - bool secure) -{ - GMutex *mutex = g_mutex_new(); - GCond *cond = g_cond_new(); - - struct input_stream *is; - struct playlist_provider *playlist = - playlist_open_any(uri, mutex, cond, &is); - if (playlist == NULL) { - g_cond_free(cond); - g_mutex_free(mutex); - return PLAYLIST_RESULT_NO_SUCH_LIST; - } - - enum playlist_result result = - playlist_load_into_queue(uri, playlist, start_index, end_index, - dest, pc, secure); - playlist_plugin_close(playlist); - - if (is != NULL) - input_stream_close(is); - - g_cond_free(cond); - g_mutex_free(mutex); - - return result; -} diff --git a/src/playlist_queue.h b/src/playlist_queue.h deleted file mode 100644 index 24a851aab..000000000 --- a/src/playlist_queue.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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. - */ - -/*! \file - * \brief Glue between playlist plugin and the play queue - */ - -#ifndef MPD_PLAYLIST_QUEUE_H -#define MPD_PLAYLIST_QUEUE_H - -#include "playlist_error.h" - -#include - -struct playlist_provider; -struct playlist; -struct player_control; - -/** - * Loads the contents of a playlist and append it to the specified - * play queue. - * - * @param uri the URI of the playlist, used to resolve relative song - * URIs - * @param start_index the index of the first song - * @param end_index the index of the last song (excluding) - */ -enum playlist_result -playlist_load_into_queue(const char *uri, struct playlist_provider *source, - unsigned start_index, unsigned end_index, - struct playlist *dest, struct player_control *pc, - bool secure); - -/** - * Opens a playlist with a playlist plugin and append to the specified - * play queue. - */ -enum playlist_result -playlist_open_into_queue(const char *uri, - unsigned start_index, unsigned end_index, - struct playlist *dest, struct player_control *pc, - bool secure); - -#endif - diff --git a/src/playlist_song.c b/src/playlist_song.c deleted file mode 100644 index 2e2870d38..000000000 --- a/src/playlist_song.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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" -#include "playlist_song.h" -#include "database.h" -#include "mapper.h" -#include "song.h" -#include "uri.h" -#include "path.h" -#include "ls.h" -#include "tag.h" - -#include -#include - -static void -merge_song_metadata(struct song *dest, const struct song *base, - const struct song *add) -{ - dest->tag = base->tag != NULL - ? (add->tag != NULL - ? tag_merge(base->tag, add->tag) - : tag_dup(base->tag)) - : (add->tag != NULL - ? tag_dup(add->tag) - : NULL); - - dest->mtime = base->mtime; - dest->start_ms = add->start_ms; - dest->end_ms = add->end_ms; -} - -static struct song * -apply_song_metadata(struct song *dest, const struct song *src) -{ - struct song *tmp; - - assert(dest != NULL); - assert(src != NULL); - - if (src->tag == NULL && src->start_ms == 0 && src->end_ms == 0) - return dest; - - if (song_in_database(dest)) { - char *path_fs = map_song_fs(dest); - if (path_fs == NULL) - return dest; - - char *path_utf8 = fs_charset_to_utf8(path_fs); - if (path_utf8 != NULL) - g_free(path_fs); - else - path_utf8 = path_fs; - - tmp = song_file_new(path_utf8, NULL); - g_free(path_utf8); - - merge_song_metadata(tmp, dest, src); - } else { - tmp = song_file_new(dest->uri, NULL); - merge_song_metadata(tmp, dest, src); - } - - if (dest->tag != NULL && dest->tag->time > 0 && - src->start_ms > 0 && src->end_ms == 0 && - src->start_ms / 1000 < (unsigned)dest->tag->time) - /* the range is open-ended, and the playlist plugin - did not know the total length of the song file - (e.g. last track on a CUE file); fix it up here */ - tmp->tag->time = dest->tag->time - src->start_ms / 1000; - - song_free(dest); - return tmp; -} - -static struct song * -playlist_check_load_song(const struct song *song, const char *uri, bool secure) -{ - struct song *dest; - - if (uri_has_scheme(uri)) { - dest = song_remote_new(uri); - } else if (g_path_is_absolute(uri) && secure) { - dest = song_file_load(uri, NULL); - if (dest == NULL) - return NULL; - } else { - struct song *tmp = db_get_song(uri); - if (tmp == NULL) - /* not found in database */ - return NULL; - - dest = song_dup_detached(tmp); - db_return_song(tmp); - } - - return apply_song_metadata(dest, song); -} - -struct song * -playlist_check_translate_song(struct song *song, const char *base_uri, - bool secure) -{ - if (song_in_database(song)) - /* already ok */ - return song; - - const char *uri = song->uri; - - if (uri_has_scheme(uri)) { - if (uri_supported_scheme(uri)) - /* valid remote song */ - return song; - else { - /* unsupported remote song */ - song_free(song); - return NULL; - } - } - - if (base_uri != NULL && strcmp(base_uri, ".") == 0) - /* g_path_get_dirname() returns "." when there is no - directory name in the given path; clear that now, - because it would break the database lookup - functions */ - base_uri = NULL; - - if (g_path_is_absolute(uri)) { - /* XXX fs_charset vs utf8? */ - const char *suffix = map_to_relative_path(uri); - assert(suffix != NULL); - - if (suffix != uri) - uri = suffix; - else if (!secure) { - /* local files must be relative to the music - directory when "secure" is enabled */ - song_free(song); - return NULL; - } - - base_uri = NULL; - } - - char *allocated = NULL; - if (base_uri != NULL) - uri = allocated = g_build_filename(base_uri, uri, NULL); - - struct song *dest = playlist_check_load_song(song, uri, secure); - song_free(song); - g_free(allocated); - return dest; -} diff --git a/src/playlist_song.h b/src/playlist_song.h deleted file mode 100644 index ea8786912..000000000 --- a/src/playlist_song.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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. - */ - -#ifndef MPD_PLAYLIST_SONG_H -#define MPD_PLAYLIST_SONG_H - -#include - -/** - * Verifies the song, returns NULL if it is unsafe. Translate the - * song to a new song object within the database, if it is a local - * file. The old song object is freed. - * - * @param secure if true, then local files are only allowed if they - * are relative to base_uri - */ -struct song * -playlist_check_translate_song(struct song *song, const char *base_uri, - bool secure); - -#endif -- cgit v1.2.3