Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8c0060fa
Commit
8c0060fa
authored
Oct 15, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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.
parent
0b44cad2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
6 deletions
+59
-6
command.c
src/command.c
+17
-1
mapper.c
src/mapper.c
+5
-2
playlist.c
src/playlist.c
+26
-0
playlist.h
src/playlist.h
+8
-0
song.c
src/song.c
+2
-2
song.h
src/song.h
+1
-1
No files found.
src/command.c
View file @
8c0060fa
...
...
@@ -229,6 +229,10 @@ static int print_playlist_result(struct client *client,
command_error
(
client
,
ACK_ERROR_SYSTEM
,
strerror
(
errno
));
return
-
1
;
case
PLAYLIST_RESULT_DENIED
:
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"Access denied"
);
return
-
1
;
case
PLAYLIST_RESULT_NO_SUCH_SONG
:
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"No such song"
);
return
-
1
;
...
...
@@ -444,6 +448,12 @@ static int handleAdd(struct client *client,
char
*
path
=
argv
[
1
];
enum
playlist_result
result
;
if
(
path
[
0
]
==
'/'
)
{
result
=
playlist_append_file
(
path
,
client_get_uid
(
client
),
NULL
);
return
print_playlist_result
(
client
,
result
);
}
if
(
isRemoteUrl
(
path
))
return
addToPlaylist
(
path
,
NULL
);
...
...
@@ -461,7 +471,13 @@ static int handleAddId(struct client *client,
int
argc
,
char
*
argv
[])
{
int
added_id
;
enum
playlist_result
result
=
addToPlaylist
(
argv
[
1
],
&
added_id
);
enum
playlist_result
result
;
if
(
argv
[
1
][
0
]
==
'/'
)
result
=
playlist_append_file
(
argv
[
1
],
client_get_uid
(
client
),
&
added_id
);
else
result
=
addToPlaylist
(
argv
[
1
],
&
added_id
);
if
(
result
!=
PLAYLIST_RESULT_SUCCESS
)
return
print_playlist_result
(
client
,
result
);
...
...
src/mapper.c
View file @
8c0060fa
...
...
@@ -96,9 +96,12 @@ map_directory_child_fs(const struct directory *directory, const char *name,
const
char
*
map_song_fs
(
const
struct
song
*
song
,
char
*
buffer
)
{
assert
(
song
->
parent
!=
NULL
);
assert
(
song
_is_file
(
song
)
);
return
map_directory_child_fs
(
song
->
parent
,
song
->
url
,
buffer
);
if
(
song_in_database
(
song
))
return
map_directory_child_fs
(
song
->
parent
,
song
->
url
,
buffer
);
else
return
utf8_to_fs_charset
(
buffer
,
song
->
url
);
}
const
char
*
...
...
src/playlist.c
View file @
8c0060fa
...
...
@@ -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
)
{
...
...
src/playlist.h
View file @
8c0060fa
...
...
@@ -32,6 +32,7 @@ struct client;
enum
playlist_result
{
PLAYLIST_RESULT_SUCCESS
,
PLAYLIST_RESULT_ERRNO
,
PLAYLIST_RESULT_DENIED
,
PLAYLIST_RESULT_NO_SUCH_SONG
,
PLAYLIST_RESULT_NO_SUCH_LIST
,
PLAYLIST_RESULT_LIST_EXISTS
,
...
...
@@ -72,6 +73,13 @@ void clearPlaylist(void);
int
clearStoredPlaylist
(
const
char
*
utf8file
);
/**
* Appends a local file (outside the music database) to the playlist,
* but only if the file's owner is equal to the specified uid.
*/
enum
playlist_result
playlist_append_file
(
const
char
*
path
,
int
uid
,
int
*
added_id
);
enum
playlist_result
addToPlaylist
(
const
char
*
file
,
int
*
added_id
);
int
addToStoredPlaylist
(
const
char
*
file
,
const
char
*
utf8file
);
...
...
src/song.c
View file @
8c0060fa
...
...
@@ -54,7 +54,7 @@ song_remote_new(const char *url)
struct
song
*
song_file_new
(
const
char
*
path
,
struct
directory
*
parent
)
{
assert
(
parent
!=
NULL
);
assert
(
(
parent
==
NULL
)
==
(
*
path
==
'/'
)
);
return
song_alloc
(
path
,
parent
);
}
...
...
@@ -65,7 +65,7 @@ song_file_load(const char *path, struct directory *parent)
struct
song
*
song
;
bool
ret
;
assert
(
parent
!=
NULL
);
assert
(
(
parent
==
NULL
)
==
(
*
path
==
'/'
)
);
if
(
strchr
(
path
,
'\n'
))
{
DEBUG
(
"newSong: '%s' is not a valid uri
\n
"
,
path
);
...
...
src/song.h
View file @
8c0060fa
...
...
@@ -76,7 +76,7 @@ song_in_database(const struct song *song)
static
inline
bool
song_is_file
(
const
struct
song
*
song
)
{
return
song_in_database
(
song
);
return
song_in_database
(
song
)
||
song
->
url
[
0
]
==
'/'
;
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment