From 8c0060fae44a94bdfe978d8d4a66589f5a03a074 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Oct 2008 22:35:13 +0200 Subject: playlist: added support for adding songs not in the music database Clients which have authenticated via unix socket may add local files to the MPD playlist, provided that they own the file. --- src/playlist.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index dfbc3151..0dae1a92 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -521,6 +521,32 @@ static void clearPlayerQueue(void) pc_cancel(); } +enum playlist_result +playlist_append_file(const char *path, int uid, int *added_id) +{ + int ret; + struct stat st; + struct song *song; + + if (uid <= 0) + /* unauthenticated client */ + return PLAYLIST_RESULT_DENIED; + + ret = stat(path, &st); + if (ret < 0) + return PLAYLIST_RESULT_ERRNO; + + if (st.st_uid != (uid_t)uid) + /* client is not owner */ + return PLAYLIST_RESULT_DENIED; + + song = song_file_load(path, NULL); + if (song == NULL) + return PLAYLIST_RESULT_NO_SUCH_SONG; + + return addSongToPlaylist(song, added_id); +} + static struct song * song_by_url(const char *url) { -- cgit v1.2.3