aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.c36
-rw-r--r--src/playlist.c20
-rw-r--r--src/playlist.h11
3 files changed, 42 insertions, 25 deletions
diff --git a/src/command.c b/src/command.c
index a00607fce..646f76bf5 100644
--- a/src/command.c
+++ b/src/command.c
@@ -162,7 +162,7 @@ check_int(struct client *client, int *value_r,
}
static bool G_GNUC_PRINTF(5, 6)
-check_range(struct client *client, int *value_r1, int *value_r2,
+check_range(struct client *client, unsigned *value_r1, unsigned *value_r2,
const char *s, const char *fmt, ...)
{
char *test, *test2;
@@ -177,15 +177,21 @@ check_range(struct client *client, int *value_r1, int *value_r2,
return false;
}
-#if LONG_MAX > INT_MAX
- if (value < INT_MIN || value > INT_MAX) {
+ if (value < 0) {
+ command_error(client, ACK_ERROR_ARG,
+ "Number is negative: %s", s);
+ return false;
+ }
+
+#if LONG_MAX > UINT_MAX
+ if (value > UINT_MAX) {
command_error(client, ACK_ERROR_ARG,
"Number too large: %s", s);
return false;
}
#endif
- *value_r1 = (int)value;
+ *value_r1 = (unsigned)value;
if (*test == ':') {
value = strtol(++test, &test2, 10);
@@ -196,14 +202,23 @@ check_range(struct client *client, int *value_r1, int *value_r2,
va_end(args);
return false;
}
-#if LONG_MAX > INT_MAX
- if (value < INT_MIN || value > INT_MAX) {
+
+ if (value < 0) {
+ command_error(client, ACK_ERROR_ARG,
+ "Number is negative: %s", s);
+ return false;
+ }
+
+#if LONG_MAX > UINT_MAX
+ if (value > UINT_MAX) {
command_error(client, ACK_ERROR_ARG,
"Number too large: %s", s);
return false;
}
#endif
- *value_r2 = (int)value;
+ *value_r2 = (unsigned)value;
+ } else {
+ *value_r2 = (unsigned)value + 1;
}
return true;
@@ -743,13 +758,14 @@ handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[
static enum command_return
handle_playlistinfo(struct client *client, int argc, char *argv[])
{
- int song = -1, max = -1;
+ unsigned start = 0, end = UINT_MAX;
enum playlist_result result;
- if (argc == 2 && !check_range(client, &song, &max, argv[1], need_range))
+ if (argc == 2 && !check_range(client, &start, &end,
+ argv[1], need_range))
return COMMAND_RETURN_ERROR;
- result = playlistInfo(client, song, max);
+ result = playlistInfo(client, start, end);
return print_playlist_result(client, result);
}
diff --git a/src/playlist.c b/src/playlist.c
index f2cbf161f..8cffefc5e 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -413,24 +413,16 @@ int playlistChangesPosId(struct client *client, uint32_t version)
return 0;
}
-enum playlist_result playlistInfo(struct client *client, int song, int max)
+enum playlist_result
+playlistInfo(struct client *client, unsigned start, unsigned end)
{
- unsigned begin = 0;
- unsigned end = playlist.length;
+ if (end > playlist.length)
+ end = playlist.length;
- if (song >= 0) {
- begin = song;
- end = song + 1;
- }
- if (song >= (int)playlist.length)
+ if (start > end)
return PLAYLIST_RESULT_BAD_RANGE;
- if (max > 0) {
- end = MIN((unsigned)max, playlist.length);
- if (end <= begin)
- return PLAYLIST_RESULT_BAD_RANGE;
- }
- for (unsigned i = begin; i < end; i++)
+ for (unsigned i = start; i < end; i++)
printPlaylistSongInfo(client, i);
return PLAYLIST_RESULT_SUCCESS;
diff --git a/src/playlist.h b/src/playlist.h
index 87364cb4c..4af4aa82c 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -95,7 +95,16 @@ enum playlist_result deleteFromPlaylist(unsigned song);
enum playlist_result deleteFromPlaylistById(unsigned song);
-enum playlist_result playlistInfo(struct client *client, int song, int max);
+/**
+ * Send detailed information about a range of songs in the playlist to
+ * a client.
+ *
+ * @param client the client which has requested information
+ * @param start the index of the first song (including)
+ * @param end the index of the last song (excluding)
+ */
+enum playlist_result
+playlistInfo(struct client *client, unsigned start, unsigned end);
enum playlist_result playlistId(struct client *client, int song);