Commit e1bf9667 authored by Max Kellermann's avatar Max Kellermann

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).
parent d1df71eb
...@@ -773,7 +773,15 @@ static int handleRepeat(int fd, mpd_unused int *permission, ...@@ -773,7 +773,15 @@ static int handleRepeat(int fd, mpd_unused int *permission,
if (check_int(fd, &status, argv[1], need_integer) < 0) if (check_int(fd, &status, argv[1], need_integer) < 0)
return -1; 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, static int handleRandom(int fd, mpd_unused int *permission,
...@@ -783,7 +791,15 @@ static int handleRandom(int fd, mpd_unused int *permission, ...@@ -783,7 +791,15 @@ static int handleRandom(int fd, mpd_unused int *permission,
if (check_int(fd, &status, argv[1], need_integer) < 0) if (check_int(fd, &status, argv[1], need_integer) < 0)
return -1; 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, static int handleStats(int fd, mpd_unused int *permission,
......
...@@ -327,9 +327,9 @@ void readPlaylistState(FILE *fp) ...@@ -327,9 +327,9 @@ void readPlaylistState(FILE *fp)
if (strcmp if (strcmp
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]), (&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0) { "1") == 0) {
setPlaylistRepeatStatus(STDERR_FILENO, 1); setPlaylistRepeatStatus(1);
} else } else
setPlaylistRepeatStatus(STDERR_FILENO, 0); setPlaylistRepeatStatus(0);
} else } else
if (strncmp if (strncmp
(buffer, PLAYLIST_STATE_FILE_CROSSFADE, (buffer, PLAYLIST_STATE_FILE_CROSSFADE,
...@@ -348,9 +348,9 @@ void readPlaylistState(FILE *fp) ...@@ -348,9 +348,9 @@ void readPlaylistState(FILE *fp)
(buffer (buffer
[strlen(PLAYLIST_STATE_FILE_RANDOM)]), [strlen(PLAYLIST_STATE_FILE_RANDOM)]),
"1") == 0) { "1") == 0) {
setPlaylistRandomStatus(STDERR_FILENO, 1); setPlaylistRandomStatus(1);
} else } else
setPlaylistRandomStatus(STDERR_FILENO, 0); setPlaylistRandomStatus(0);
} else if (strncmp(buffer, PLAYLIST_STATE_FILE_CURRENT, } else if (strncmp(buffer, PLAYLIST_STATE_FILE_CURRENT,
strlen(PLAYLIST_STATE_FILE_CURRENT)) strlen(PLAYLIST_STATE_FILE_CURRENT))
== 0) { == 0) {
...@@ -1012,21 +1012,14 @@ int getPlaylistRandomStatus(void) ...@@ -1012,21 +1012,14 @@ int getPlaylistRandomStatus(void)
return playlist.random; 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_state == PLAYLIST_STATE_PLAY) {
if (playlist.repeat && !status && playlist.queued == 0) if (playlist.repeat && !status && playlist.queued == 0)
clearPlayerQueue(); clearPlayerQueue();
} }
playlist.repeat = status; playlist.repeat = status;
return 0;
} }
int moveSongInPlaylist(int fd, int from, int to) int moveSongInPlaylist(int fd, int from, int to)
...@@ -1183,15 +1176,10 @@ static void randomizeOrder(int start, int end) ...@@ -1183,15 +1176,10 @@ static void randomizeOrder(int start, int end)
} }
} }
int setPlaylistRandomStatus(int fd, int status) void setPlaylistRandomStatus(int status)
{ {
int statusWas = playlist.random; 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; playlist.random = status;
if (status != statusWas) { if (status != statusWas) {
...@@ -1209,8 +1197,6 @@ int setPlaylistRandomStatus(int fd, int status) ...@@ -1209,8 +1197,6 @@ int setPlaylistRandomStatus(int fd, int status)
} else } else
orderPlaylist(); orderPlaylist();
} }
return 0;
} }
void previousSongInPlaylist(void) void previousSongInPlaylist(void)
......
...@@ -105,11 +105,11 @@ int loadPlaylist(int fd, const char *utf8file); ...@@ -105,11 +105,11 @@ int loadPlaylist(int fd, const char *utf8file);
int getPlaylistRepeatStatus(void); int getPlaylistRepeatStatus(void);
int setPlaylistRepeatStatus(int fd, int status); void setPlaylistRepeatStatus(int status);
int getPlaylistRandomStatus(void); int getPlaylistRandomStatus(void);
int setPlaylistRandomStatus(int fd, int status); void setPlaylistRandomStatus(int status);
int getPlaylistCurrentSong(void); int getPlaylistCurrentSong(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment