aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/PlaylistCommands.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/PlaylistCommands.cxx')
-rw-r--r--src/command/PlaylistCommands.cxx140
1 files changed, 77 insertions, 63 deletions
diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx
index c2b18064c..625e82055 100644
--- a/src/command/PlaylistCommands.cxx
+++ b/src/command/PlaylistCommands.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,6 +19,7 @@
#include "config.h"
#include "PlaylistCommands.hxx"
+#include "Request.hxx"
#include "db/DatabasePlaylist.hxx"
#include "CommandError.hxx"
#include "PlaylistPrint.hxx"
@@ -32,143 +33,157 @@
#include "queue/Playlist.hxx"
#include "TimePrint.hxx"
#include "client/Client.hxx"
-#include "protocol/ArgParser.hxx"
-#include "protocol/Result.hxx"
+#include "client/Response.hxx"
#include "ls.hxx"
+#include "Mapper.hxx"
+#include "fs/AllocatedPath.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
+#include "util/ConstBuffer.hxx"
+
+bool
+playlist_commands_available()
+{
+ return !map_spl_path().IsNull();
+}
static void
-print_spl_list(Client &client, const PlaylistVector &list)
+print_spl_list(Response &r, const PlaylistVector &list)
{
for (const auto &i : list) {
- client_printf(client, "playlist: %s\n", i.name.c_str());
+ r.Format("playlist: %s\n", i.name.c_str());
if (i.mtime > 0)
- time_print(client, "Last-Modified", i.mtime);
+ time_print(r, "Last-Modified", i.mtime);
}
}
CommandResult
-handle_save(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_save(Client &client, Request args, Response &r)
{
- PlaylistResult result = spl_save_playlist(argv[1], client.playlist);
- return print_playlist_result(client, result);
+ Error error;
+ return spl_save_playlist(args.front(), client.playlist, error)
+ ? CommandResult::OK
+ : print_error(r, error);
}
CommandResult
-handle_load(Client &client, unsigned argc, char *argv[])
+handle_load(Client &client, Request args, Response &r)
{
- unsigned start_index, end_index;
-
- if (argc < 3) {
- start_index = 0;
- end_index = unsigned(-1);
- } else if (!check_range(client, &start_index, &end_index, argv[2]))
+ RangeArg range = RangeArg::All();
+ if (!args.ParseOptional(1, range, r))
return CommandResult::ERROR;
const ScopeBulkEdit bulk_edit(client.partition);
Error error;
const SongLoader loader(client);
- if (!playlist_open_into_queue(argv[1],
- start_index, end_index,
+ if (!playlist_open_into_queue(args.front(),
+ range.start, range.end,
client.playlist,
client.player_control, loader, error))
- return print_error(client, error);
+ return print_error(r, error);
return CommandResult::OK;
}
CommandResult
-handle_listplaylist(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_listplaylist(Client &client, Request args, Response &r)
{
- if (playlist_file_print(client, argv[1], false))
+ const char *const name = args.front();
+
+ if (playlist_file_print(r, client.partition, SongLoader(client),
+ name, false))
return CommandResult::OK;
Error error;
- return spl_print(client, argv[1], false, error)
+ return spl_print(r, client.partition, name, false, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_listplaylistinfo(Client &client,
- gcc_unused unsigned argc, char *argv[])
+handle_listplaylistinfo(Client &client, Request args, Response &r)
{
- if (playlist_file_print(client, argv[1], true))
+ const char *const name = args.front();
+
+ if (playlist_file_print(r, client.partition, SongLoader(client),
+ name, true))
return CommandResult::OK;
Error error;
- return spl_print(client, argv[1], true, error)
+ return spl_print(r, client.partition, name, true, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_rm(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_rm(gcc_unused Client &client, Request args, Response &r)
{
+ const char *const name = args.front();
+
Error error;
- return spl_delete(argv[1], error)
+ return spl_delete(name, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_rename(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_rename(gcc_unused Client &client, Request args, Response &r)
{
+ const char *const old_name = args[0];
+ const char *const new_name = args[1];
+
Error error;
- return spl_rename(argv[1], argv[2], error)
+ return spl_rename(old_name, new_name, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_playlistdelete(Client &client,
- gcc_unused unsigned argc, char *argv[]) {
- char *playlist = argv[1];
+handle_playlistdelete(gcc_unused Client &client, Request args, Response &r)
+{
+ const char *const name = args[0];
unsigned from;
-
- if (!check_unsigned(client, &from, argv[2]))
+ if (!args.Parse(1, from, r))
return CommandResult::ERROR;
Error error;
- return spl_remove_index(playlist, from, error)
+ return spl_remove_index(name, from, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_playlistmove(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_playlistmove(gcc_unused Client &client, Request args, Response &r)
{
- char *playlist = argv[1];
+ const char *const name = args.front();
unsigned from, to;
-
- if (!check_unsigned(client, &from, argv[2]))
- return CommandResult::ERROR;
- if (!check_unsigned(client, &to, argv[3]))
+ if (!args.Parse(1, from, r) || !args.Parse(2, to, r))
return CommandResult::ERROR;
Error error;
- return spl_move_index(playlist, from, to, error)
+ return spl_move_index(name, from, to, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_playlistclear(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_playlistclear(gcc_unused Client &client, Request args, Response &r)
{
+ const char *const name = args.front();
+
Error error;
- return spl_clear(argv[1], error)
+ return spl_clear(name, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
-handle_playlistadd(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_playlistadd(Client &client, Request args, Response &r)
{
- char *playlist = argv[1];
- char *uri = argv[2];
+ const char *const playlist = args[0];
+ const char *const uri = args[1];
bool success;
Error error;
@@ -179,7 +194,7 @@ handle_playlistadd(Client &client, gcc_unused unsigned argc, char *argv[])
#ifdef ENABLE_DATABASE
const Database *db = client.GetDatabase(error);
if (db == nullptr)
- return print_error(client, error);
+ return print_error(r, error);
success = search_add_to_playlist(*db, *client.GetStorage(),
uri, playlist, nullptr,
@@ -190,23 +205,22 @@ handle_playlistadd(Client &client, gcc_unused unsigned argc, char *argv[])
}
if (!success && !error.IsDefined()) {
- command_error(client, ACK_ERROR_NO_EXIST,
- "directory or file not found");
+ r.Error(ACK_ERROR_NO_EXIST, "directory or file not found");
return CommandResult::ERROR;
}
- return success ? CommandResult::OK : print_error(client, error);
+ return success ? CommandResult::OK : print_error(r, error);
}
CommandResult
-handle_listplaylists(Client &client,
- gcc_unused unsigned argc, gcc_unused char *argv[])
+handle_listplaylists(gcc_unused Client &client, gcc_unused Request args,
+ Response &r)
{
Error error;
const auto list = ListPlaylistFiles(error);
if (list.empty() && error.IsDefined())
- return print_error(client, error);
+ return print_error(r, error);
- print_spl_list(client, list);
+ print_spl_list(r, list);
return CommandResult::OK;
}