aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-07 13:38:59 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-09 00:55:39 -0700
commit9e53c28046bae4a02387aba5ddaddc74f7bcf246 (patch)
tree190c3bb482e8799da5a5499780a3ce0128449a42
parentff06a92213c0d430f93552188cc569a5fa506e18 (diff)
downloadmpd-9e53c28046bae4a02387aba5ddaddc74f7bcf246.tar.gz
mpd-9e53c28046bae4a02387aba5ddaddc74f7bcf246.tar.xz
mpd-9e53c28046bae4a02387aba5ddaddc74f7bcf246.zip
playlist: moved "repeat" and "random" value checks to command.c
Client's input values should be validated by the command implementation, and the core libraries shouldn't talk to the client directly if possible. Thus, setPlaylistRepeatStatus() and setPlaylistRandomStatus() don't get the file descriptor, and cannot fail (return void).
Diffstat (limited to '')
-rw-r--r--src/command.c20
-rw-r--r--src/playlist.c26
-rw-r--r--src/playlist.h4
3 files changed, 26 insertions, 24 deletions
diff --git a/src/command.c b/src/command.c
index bc646804e..77548664f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -771,7 +771,15 @@ static int handleRepeat(int fd, mpd_unused int *permission,
if (check_int(fd, &status, argv[1], need_integer) < 0)
return -1;
- return setPlaylistRepeatStatus(fd, status);
+
+ if (status != 0 && status != 1) {
+ commandError(fd, ACK_ERROR_ARG,
+ "\"%i\" is not 0 or 1", status);
+ return -1;
+ }
+
+ setPlaylistRepeatStatus(status);
+ return 0;
}
static int handleRandom(int fd, mpd_unused int *permission,
@@ -781,7 +789,15 @@ static int handleRandom(int fd, mpd_unused int *permission,
if (check_int(fd, &status, argv[1], need_integer) < 0)
return -1;
- return setPlaylistRandomStatus(fd, status);
+
+ if (status != 0 && status != 1) {
+ commandError(fd, ACK_ERROR_ARG,
+ "\"%i\" is not 0 or 1", status);
+ return -1;
+ }
+
+ setPlaylistRandomStatus(status);
+ return 0;
}
static int handleStats(int fd, mpd_unused int *permission,
diff --git a/src/playlist.c b/src/playlist.c
index 1a286f67a..6081f1fde 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -349,9 +349,9 @@ void readPlaylistState(FILE *fp)
if (strcmp
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0) {
- setPlaylistRepeatStatus(STDERR_FILENO, 1);
+ setPlaylistRepeatStatus(1);
} else
- setPlaylistRepeatStatus(STDERR_FILENO, 0);
+ setPlaylistRepeatStatus(0);
} else
if (strncmp
(buffer, PLAYLIST_STATE_FILE_CROSSFADE,
@@ -368,9 +368,9 @@ void readPlaylistState(FILE *fp)
(buffer
[strlen(PLAYLIST_STATE_FILE_RANDOM)]),
"1") == 0) {
- setPlaylistRandomStatus(STDERR_FILENO, 1);
+ setPlaylistRandomStatus(1);
} else
- setPlaylistRandomStatus(STDERR_FILENO, 0);
+ setPlaylistRandomStatus(0);
} else if (strncmp(buffer, PLAYLIST_STATE_FILE_CURRENT,
strlen(PLAYLIST_STATE_FILE_CURRENT))
== 0) {
@@ -1043,21 +1043,14 @@ int getPlaylistRandomStatus(void)
return playlist.random;
}
-int setPlaylistRepeatStatus(int fd, int status)
+void setPlaylistRepeatStatus(int status)
{
- if (status != 0 && status != 1) {
- commandError(fd, ACK_ERROR_ARG, "\"%i\" is not 0 or 1", status);
- return -1;
- }
-
if (playlist_state == PLAYLIST_STATE_PLAY) {
if (playlist.repeat && !status && playlist.queued == 0)
clear_queue();
}
playlist.repeat = status;
-
- return 0;
}
int moveSongInPlaylist(int fd, int from, int to)
@@ -1217,15 +1210,10 @@ static void randomizeOrder(int start, int end)
DEBUG("%s:%d current: %d\n", __func__, __LINE__, playlist.current);
}
-int setPlaylistRandomStatus(int fd, int status)
+void setPlaylistRandomStatus(int status)
{
int statusWas = playlist.random;
- if (status != 0 && status != 1) {
- commandError(fd, ACK_ERROR_ARG, "\"%i\" is not 0 or 1", status);
- return -1;
- }
-
playlist.random = status;
if (status != statusWas) {
@@ -1239,8 +1227,6 @@ int setPlaylistRandomStatus(int fd, int status)
__func__,__LINE__,playlist.queued);
}
}
-
- return 0;
}
void previousSongInPlaylist(void)
diff --git a/src/playlist.h b/src/playlist.h
index 83b02fd08..cae38becf 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -96,11 +96,11 @@ int loadPlaylist(int fd, const char *utf8file);
int getPlaylistRepeatStatus(void);
-int setPlaylistRepeatStatus(int fd, int status);
+void setPlaylistRepeatStatus(int status);
int getPlaylistRandomStatus(void);
-int setPlaylistRandomStatus(int fd, int status);
+void setPlaylistRandomStatus(int status);
int getPlaylistCurrentSong(void);