Commit cf4d80fc authored by Max Kellermann's avatar Max Kellermann

command: convert command_return to to a strictly-typed enum

parent 8118bc93
...@@ -54,7 +54,6 @@ src_mpd_LDADD = \ ...@@ -54,7 +54,6 @@ src_mpd_LDADD = \
mpd_headers = \ mpd_headers = \
src/check.h \ src/check.h \
src/command.h \
src/gerror.h \ src/gerror.h \
src/TextInputStream.hxx \ src/TextInputStream.hxx \
src/AudioCompress/config.h \ src/AudioCompress/config.h \
...@@ -79,6 +78,7 @@ src_mpd_SOURCES = \ ...@@ -79,6 +78,7 @@ src_mpd_SOURCES = \
src/protocol/Ack.cxx src/protocol/Ack.hxx \ src/protocol/Ack.cxx src/protocol/Ack.hxx \
src/protocol/ArgParser.cxx src/protocol/ArgParser.hxx \ src/protocol/ArgParser.cxx src/protocol/ArgParser.hxx \
src/protocol/Result.cxx src/protocol/Result.hxx \ src/protocol/Result.cxx src/protocol/Result.hxx \
src/CommandResult.hxx \
src/CommandError.cxx src/CommandError.hxx \ src/CommandError.cxx src/CommandError.hxx \
src/AllCommands.cxx src/AllCommands.hxx \ src/AllCommands.cxx src/AllCommands.hxx \
src/QueueCommands.cxx src/QueueCommands.hxx \ src/QueueCommands.cxx src/QueueCommands.hxx \
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "config.h" #include "config.h"
#include "AllCommands.hxx" #include "AllCommands.hxx"
#include "command.h"
#include "QueueCommands.hxx" #include "QueueCommands.hxx"
#include "PlayerCommands.hxx" #include "PlayerCommands.hxx"
#include "PlaylistCommands.hxx" #include "PlaylistCommands.hxx"
...@@ -56,14 +55,14 @@ struct command { ...@@ -56,14 +55,14 @@ struct command {
unsigned permission; unsigned permission;
int min; int min;
int max; int max;
enum command_return (*handler)(Client &client, int argc, char **argv); CommandResult (*handler)(Client &client, int argc, char **argv);
}; };
/* don't be fooled, this is the command handler for "commands" command */ /* don't be fooled, this is the command handler for "commands" command */
static enum command_return static CommandResult
handle_commands(Client &client, int argc, char *argv[]); handle_commands(Client &client, int argc, char *argv[]);
static enum command_return static CommandResult
handle_not_commands(Client &client, int argc, char *argv[]); handle_not_commands(Client &client, int argc, char *argv[]);
/** /**
...@@ -178,7 +177,7 @@ command_available(gcc_unused const struct command *cmd) ...@@ -178,7 +177,7 @@ command_available(gcc_unused const struct command *cmd)
} }
/* don't be fooled, this is the command handler for "commands" command */ /* don't be fooled, this is the command handler for "commands" command */
static enum command_return static CommandResult
handle_commands(Client &client, handle_commands(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -193,10 +192,10 @@ handle_commands(Client &client, ...@@ -193,10 +192,10 @@ handle_commands(Client &client,
client_printf(client, "command: %s\n", cmd->cmd); client_printf(client, "command: %s\n", cmd->cmd);
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
static enum command_return static CommandResult
handle_not_commands(Client &client, handle_not_commands(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -210,7 +209,7 @@ handle_not_commands(Client &client, ...@@ -210,7 +209,7 @@ handle_not_commands(Client &client,
client_printf(client, "command: %s\n", cmd->cmd); client_printf(client, "command: %s\n", cmd->cmd);
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
void command_init(void) void command_init(void)
...@@ -308,13 +307,13 @@ command_checked_lookup(Client &client, unsigned permission, ...@@ -308,13 +307,13 @@ command_checked_lookup(Client &client, unsigned permission,
return cmd; return cmd;
} }
enum command_return CommandResult
command_process(Client &client, unsigned num, char *line) command_process(Client &client, unsigned num, char *line)
{ {
Error error; Error error;
char *argv[COMMAND_ARGV_MAX] = { nullptr }; char *argv[COMMAND_ARGV_MAX] = { nullptr };
const struct command *cmd; const struct command *cmd;
enum command_return ret = COMMAND_RETURN_ERROR; CommandResult ret = CommandResult::ERROR;
command_list_num = num; command_list_num = num;
...@@ -333,7 +332,7 @@ command_process(Client &client, unsigned num, char *line) ...@@ -333,7 +332,7 @@ command_process(Client &client, unsigned num, char *line)
current_command = nullptr; current_command = nullptr;
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
unsigned argc = 1; unsigned argc = 1;
...@@ -353,13 +352,13 @@ command_process(Client &client, unsigned num, char *line) ...@@ -353,13 +352,13 @@ command_process(Client &client, unsigned num, char *line)
if (argc >= COMMAND_ARGV_MAX) { if (argc >= COMMAND_ARGV_MAX) {
command_error(client, ACK_ERROR_ARG, "Too many arguments"); command_error(client, ACK_ERROR_ARG, "Too many arguments");
current_command = nullptr; current_command = nullptr;
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
if (!tokenizer.IsEnd()) { if (!tokenizer.IsEnd()) {
command_error(client, ACK_ERROR_ARG, "%s", error.GetMessage()); command_error(client, ACK_ERROR_ARG, "%s", error.GetMessage());
current_command = nullptr; current_command = nullptr;
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
/* look up and invoke the command handler */ /* look up and invoke the command handler */
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#ifndef MPD_ALL_COMMANDS_HXX #ifndef MPD_ALL_COMMANDS_HXX
#define MPD_ALL_COMMANDS_HXX #define MPD_ALL_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
...@@ -28,7 +28,7 @@ void command_init(void); ...@@ -28,7 +28,7 @@ void command_init(void);
void command_finish(void); void command_finish(void);
enum command_return CommandResult
command_process(Client &client, unsigned num, char *line); command_process(Client &client, unsigned num, char *line);
#endif #endif
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "check.h" #include "check.h"
#include "Client.hxx" #include "Client.hxx"
#include "command.h" #include "CommandResult.hxx"
enum { enum {
CLIENT_MAX_SUBSCRIPTIONS = 16, CLIENT_MAX_SUBSCRIPTIONS = 16,
...@@ -35,7 +35,7 @@ extern int client_timeout; ...@@ -35,7 +35,7 @@ extern int client_timeout;
extern size_t client_max_command_list_size; extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size; extern size_t client_max_output_buffer_size;
enum command_return CommandResult
client_process_line(Client &client, char *line); client_process_line(Client &client, char *line);
#endif #endif
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin" #define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define CLIENT_LIST_MODE_END "command_list_end" #define CLIENT_LIST_MODE_END "command_list_end"
static enum command_return static CommandResult
client_process_command_list(Client &client, bool list_ok, client_process_command_list(Client &client, bool list_ok,
std::list<std::string> &&list) std::list<std::string> &&list)
{ {
enum command_return ret = COMMAND_RETURN_OK; CommandResult ret = CommandResult::OK;
unsigned num = 0; unsigned num = 0;
for (auto &&i : list) { for (auto &&i : list) {
...@@ -42,7 +42,7 @@ client_process_command_list(Client &client, bool list_ok, ...@@ -42,7 +42,7 @@ client_process_command_list(Client &client, bool list_ok,
FormatDebug(client_domain, "process command \"%s\"", cmd); FormatDebug(client_domain, "process command \"%s\"", cmd);
ret = command_process(client, num++, cmd); ret = command_process(client, num++, cmd);
FormatDebug(client_domain, "command returned %i", ret); FormatDebug(client_domain, "command returned %i", ret);
if (ret != COMMAND_RETURN_OK || client.IsExpired()) if (ret != CommandResult::OK || client.IsExpired())
break; break;
else if (list_ok) else if (list_ok)
client_puts(client, "list_OK\n"); client_puts(client, "list_OK\n");
...@@ -51,10 +51,10 @@ client_process_command_list(Client &client, bool list_ok, ...@@ -51,10 +51,10 @@ client_process_command_list(Client &client, bool list_ok,
return ret; return ret;
} }
enum command_return CommandResult
client_process_line(Client &client, char *line) client_process_line(Client &client, char *line)
{ {
enum command_return ret; CommandResult ret;
if (strcmp(line, "noidle") == 0) { if (strcmp(line, "noidle") == 0) {
if (client.idle_waiting) { if (client.idle_waiting) {
...@@ -67,14 +67,14 @@ client_process_line(Client &client, char *line) ...@@ -67,14 +67,14 @@ client_process_line(Client &client, char *line)
has already received the full idle response from has already received the full idle response from
client_idle_notify(), which he can now evaluate */ client_idle_notify(), which he can now evaluate */
return COMMAND_RETURN_OK; return CommandResult::OK;
} else if (client.idle_waiting) { } else if (client.idle_waiting) {
/* during idle mode, clients must not send anything /* during idle mode, clients must not send anything
except "noidle" */ except "noidle" */
FormatWarning(client_domain, FormatWarning(client_domain,
"[%u] command \"%s\" during idle", "[%u] command \"%s\" during idle",
client.num, line); client.num, line);
return COMMAND_RETURN_CLOSE; return CommandResult::CLOSE;
} }
if (client.cmd_list.IsActive()) { if (client.cmd_list.IsActive()) {
...@@ -92,11 +92,11 @@ client_process_line(Client &client, char *line) ...@@ -92,11 +92,11 @@ client_process_line(Client &client, char *line)
"[%u] process command " "[%u] process command "
"list returned %i", client.num, ret); "list returned %i", client.num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == CommandResult::CLOSE ||
client.IsExpired()) client.IsExpired())
return COMMAND_RETURN_CLOSE; return CommandResult::CLOSE;
if (ret == COMMAND_RETURN_OK) if (ret == CommandResult::OK)
command_success(client); command_success(client);
client.cmd_list.Reset(); client.cmd_list.Reset();
...@@ -107,18 +107,18 @@ client_process_line(Client &client, char *line) ...@@ -107,18 +107,18 @@ client_process_line(Client &client, char *line)
"is larger than the max (%lu)", "is larger than the max (%lu)",
client.num, client.num,
(unsigned long)client_max_command_list_size); (unsigned long)client_max_command_list_size);
return COMMAND_RETURN_CLOSE; return CommandResult::CLOSE;
} }
ret = COMMAND_RETURN_OK; ret = CommandResult::OK;
} }
} else { } else {
if (strcmp(line, CLIENT_LIST_MODE_BEGIN) == 0) { if (strcmp(line, CLIENT_LIST_MODE_BEGIN) == 0) {
client.cmd_list.Begin(false); client.cmd_list.Begin(false);
ret = COMMAND_RETURN_OK; ret = CommandResult::OK;
} else if (strcmp(line, CLIENT_LIST_OK_MODE_BEGIN) == 0) { } else if (strcmp(line, CLIENT_LIST_OK_MODE_BEGIN) == 0) {
client.cmd_list.Begin(true); client.cmd_list.Begin(true);
ret = COMMAND_RETURN_OK; ret = CommandResult::OK;
} else { } else {
FormatDebug(client_domain, FormatDebug(client_domain,
"[%u] process command \"%s\"", "[%u] process command \"%s\"",
...@@ -128,11 +128,11 @@ client_process_line(Client &client, char *line) ...@@ -128,11 +128,11 @@ client_process_line(Client &client, char *line)
"[%u] command returned %i", "[%u] command returned %i",
client.num, ret); client.num, ret);
if (ret == COMMAND_RETURN_CLOSE || if (ret == CommandResult::CLOSE ||
client.IsExpired()) client.IsExpired())
return COMMAND_RETURN_CLOSE; return CommandResult::CLOSE;
if (ret == COMMAND_RETURN_OK) if (ret == CommandResult::OK)
command_success(client); command_success(client);
} }
} }
......
...@@ -40,19 +40,19 @@ Client::OnSocketInput(void *data, size_t length) ...@@ -40,19 +40,19 @@ Client::OnSocketInput(void *data, size_t length)
BufferedSocket::ConsumeInput(newline + 1 - p); BufferedSocket::ConsumeInput(newline + 1 - p);
enum command_return result = client_process_line(*this, p); CommandResult result = client_process_line(*this, p);
switch (result) { switch (result) {
case COMMAND_RETURN_OK: case CommandResult::OK:
case COMMAND_RETURN_IDLE: case CommandResult::IDLE:
case COMMAND_RETURN_ERROR: case CommandResult::ERROR:
break; break;
case COMMAND_RETURN_KILL: case CommandResult::KILL:
Close(); Close();
main_loop->Break(); main_loop->Break();
return InputResult::CLOSED; return InputResult::CLOSED;
case COMMAND_RETURN_CLOSE: case CommandResult::CLOSE:
Close(); Close();
return InputResult::CLOSED; return InputResult::CLOSED;
} }
......
...@@ -29,66 +29,66 @@ ...@@ -29,66 +29,66 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
enum command_return CommandResult
print_playlist_result(Client &client, PlaylistResult result) print_playlist_result(Client &client, PlaylistResult result)
{ {
switch (result) { switch (result) {
case PlaylistResult::SUCCESS: case PlaylistResult::SUCCESS:
return COMMAND_RETURN_OK; return CommandResult::OK;
case PlaylistResult::ERRNO: case PlaylistResult::ERRNO:
command_error(client, ACK_ERROR_SYSTEM, "%s", command_error(client, ACK_ERROR_SYSTEM, "%s",
g_strerror(errno)); g_strerror(errno));
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::DENIED: case PlaylistResult::DENIED:
command_error(client, ACK_ERROR_PERMISSION, "Access denied"); command_error(client, ACK_ERROR_PERMISSION, "Access denied");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::NO_SUCH_SONG: case PlaylistResult::NO_SUCH_SONG:
command_error(client, ACK_ERROR_NO_EXIST, "No such song"); command_error(client, ACK_ERROR_NO_EXIST, "No such song");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::NO_SUCH_LIST: case PlaylistResult::NO_SUCH_LIST:
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist"); command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::LIST_EXISTS: case PlaylistResult::LIST_EXISTS:
command_error(client, ACK_ERROR_EXIST, command_error(client, ACK_ERROR_EXIST,
"Playlist already exists"); "Playlist already exists");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::BAD_NAME: case PlaylistResult::BAD_NAME:
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"playlist name is invalid: " "playlist name is invalid: "
"playlist names may not contain slashes," "playlist names may not contain slashes,"
" newlines or carriage returns"); " newlines or carriage returns");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::BAD_RANGE: case PlaylistResult::BAD_RANGE:
command_error(client, ACK_ERROR_ARG, "Bad song index"); command_error(client, ACK_ERROR_ARG, "Bad song index");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::NOT_PLAYING: case PlaylistResult::NOT_PLAYING:
command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing"); command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::TOO_LARGE: case PlaylistResult::TOO_LARGE:
command_error(client, ACK_ERROR_PLAYLIST_MAX, command_error(client, ACK_ERROR_PLAYLIST_MAX,
"playlist is at the max size"); "playlist is at the max size");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case PlaylistResult::DISABLED: case PlaylistResult::DISABLED:
command_error(client, ACK_ERROR_UNKNOWN, command_error(client, ACK_ERROR_UNKNOWN,
"stored playlist support is disabled"); "stored playlist support is disabled");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
assert(0); assert(0);
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
enum command_return CommandResult
print_error(Client &client, const Error &error) print_error(Client &client, const Error &error)
{ {
assert(error.IsDefined()); assert(error.IsDefined());
...@@ -101,24 +101,24 @@ print_error(Client &client, const Error &error) ...@@ -101,24 +101,24 @@ print_error(Client &client, const Error &error)
} else if (error.IsDomain(ack_domain)) { } else if (error.IsDomain(ack_domain)) {
command_error(client, (ack)error.GetCode(), command_error(client, (ack)error.GetCode(),
"%s", error.GetMessage()); "%s", error.GetMessage());
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} else if (error.IsDomain(db_domain)) { } else if (error.IsDomain(db_domain)) {
switch ((enum db_error)error.GetCode()) { switch ((enum db_error)error.GetCode()) {
case DB_DISABLED: case DB_DISABLED:
command_error(client, ACK_ERROR_NO_EXIST, "%s", command_error(client, ACK_ERROR_NO_EXIST, "%s",
error.GetMessage()); error.GetMessage());
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case DB_NOT_FOUND: case DB_NOT_FOUND:
command_error(client, ACK_ERROR_NO_EXIST, "Not found"); command_error(client, ACK_ERROR_NO_EXIST, "Not found");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} else if (error.IsDomain(errno_domain)) { } else if (error.IsDomain(errno_domain)) {
command_error(client, ACK_ERROR_SYSTEM, "%s", command_error(client, ACK_ERROR_SYSTEM, "%s",
g_strerror(error.GetCode())); g_strerror(error.GetCode()));
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
command_error(client, ACK_ERROR_UNKNOWN, "error"); command_error(client, ACK_ERROR_UNKNOWN, "error");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
...@@ -20,19 +20,19 @@ ...@@ -20,19 +20,19 @@
#ifndef MPD_COMMAND_ERROR_HXX #ifndef MPD_COMMAND_ERROR_HXX
#define MPD_COMMAND_ERROR_HXX #define MPD_COMMAND_ERROR_HXX
#include "command.h" #include "CommandResult.hxx"
#include "PlaylistError.hxx" #include "PlaylistError.hxx"
class Client; class Client;
class Error; class Error;
enum command_return CommandResult
print_playlist_result(Client &client, PlaylistResult result); print_playlist_result(Client &client, PlaylistResult result);
/** /**
* Send the #Error to the client. * Send the #Error to the client.
*/ */
enum command_return CommandResult
print_error(Client &client, const Error &error); print_error(Client &client, const Error &error);
#endif #endif
...@@ -17,37 +17,45 @@ ...@@ -17,37 +17,45 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_COMMAND_H #ifndef MPD_COMMAND_RESULT_HXX
#define MPD_COMMAND_H #define MPD_COMMAND_RESULT_HXX
enum command_return { #ifdef WIN32
#include <windows.h>
/* damn you, windows.h! */
#ifdef ERROR
#undef ERROR
#endif
#endif
enum class CommandResult {
/** /**
* The command has succeeded, but the "OK" response was not * The command has succeeded, but the "OK" response was not
* yet sent to the client. * yet sent to the client.
*/ */
COMMAND_RETURN_OK, OK,
/** /**
* The connection is now in "idle" mode, and no response shall * The connection is now in "idle" mode, and no response shall
* be generated. * be generated.
*/ */
COMMAND_RETURN_IDLE, IDLE,
/** /**
* There was an error. The "ACK" response was sent to the * There was an error. The "ACK" response was sent to the
* client. * client.
*/ */
COMMAND_RETURN_ERROR, ERROR,
/** /**
* The connection to this client shall be closed. * The connection to this client shall be closed.
*/ */
COMMAND_RETURN_CLOSE, CLOSE,
/** /**
* The MPD process shall be shut down. * The MPD process shall be shut down.
*/ */
COMMAND_RETURN_KILL, KILL,
}; };
#endif #endif
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
enum command_return CommandResult
handle_lsinfo2(Client &client, int argc, char *argv[]) handle_lsinfo2(Client &client, int argc, char *argv[])
{ {
const char *uri; const char *uri;
...@@ -51,67 +51,67 @@ handle_lsinfo2(Client &client, int argc, char *argv[]) ...@@ -51,67 +51,67 @@ handle_lsinfo2(Client &client, int argc, char *argv[])
if (!db_selection_print(client, selection, true, error)) if (!db_selection_print(client, selection, true, error))
return print_error(client, error); return print_error(client, error);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
static enum command_return static CommandResult
handle_match(Client &client, int argc, char *argv[], bool fold_case) handle_match(Client &client, int argc, char *argv[], bool fold_case)
{ {
SongFilter filter; SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, fold_case)) { if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
const DatabaseSelection selection("", true, &filter); const DatabaseSelection selection("", true, &filter);
Error error; Error error;
return db_selection_print(client, selection, true, error) return db_selection_print(client, selection, true, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_find(Client &client, int argc, char *argv[]) handle_find(Client &client, int argc, char *argv[])
{ {
return handle_match(client, argc, argv, false); return handle_match(client, argc, argv, false);
} }
enum command_return CommandResult
handle_search(Client &client, int argc, char *argv[]) handle_search(Client &client, int argc, char *argv[])
{ {
return handle_match(client, argc, argv, true); return handle_match(client, argc, argv, true);
} }
static enum command_return static CommandResult
handle_match_add(Client &client, int argc, char *argv[], bool fold_case) handle_match_add(Client &client, int argc, char *argv[], bool fold_case)
{ {
SongFilter filter; SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, fold_case)) { if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
const DatabaseSelection selection("", true, &filter); const DatabaseSelection selection("", true, &filter);
Error error; Error error;
return AddFromDatabase(client.partition, selection, error) return AddFromDatabase(client.partition, selection, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_findadd(Client &client, int argc, char *argv[]) handle_findadd(Client &client, int argc, char *argv[])
{ {
return handle_match_add(client, argc, argv, false); return handle_match_add(client, argc, argv, false);
} }
enum command_return CommandResult
handle_searchadd(Client &client, int argc, char *argv[]) handle_searchadd(Client &client, int argc, char *argv[])
{ {
return handle_match_add(client, argc, argv, true); return handle_match_add(client, argc, argv, true);
} }
enum command_return CommandResult
handle_searchaddpl(Client &client, int argc, char *argv[]) handle_searchaddpl(Client &client, int argc, char *argv[])
{ {
const char *playlist = argv[1]; const char *playlist = argv[1];
...@@ -119,31 +119,31 @@ handle_searchaddpl(Client &client, int argc, char *argv[]) ...@@ -119,31 +119,31 @@ handle_searchaddpl(Client &client, int argc, char *argv[])
SongFilter filter; SongFilter filter;
if (!filter.Parse(argc - 2, argv + 2, true)) { if (!filter.Parse(argc - 2, argv + 2, true)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
Error error; Error error;
return search_add_to_playlist("", playlist, &filter, error) return search_add_to_playlist("", playlist, &filter, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_count(Client &client, int argc, char *argv[]) handle_count(Client &client, int argc, char *argv[])
{ {
SongFilter filter; SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, false)) { if (!filter.Parse(argc - 1, argv + 1, false)) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
Error error; Error error;
return searchStatsForSongsIn(client, "", &filter, error) return searchStatsForSongsIn(client, "", &filter, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_listall(Client &client, gcc_unused int argc, char *argv[]) handle_listall(Client &client, gcc_unused int argc, char *argv[])
{ {
const char *directory = ""; const char *directory = "";
...@@ -153,24 +153,24 @@ handle_listall(Client &client, gcc_unused int argc, char *argv[]) ...@@ -153,24 +153,24 @@ handle_listall(Client &client, gcc_unused int argc, char *argv[])
Error error; Error error;
return printAllIn(client, directory, error) return printAllIn(client, directory, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_list(Client &client, int argc, char *argv[]) handle_list(Client &client, int argc, char *argv[])
{ {
unsigned tagType = locate_parse_type(argv[1]); unsigned tagType = locate_parse_type(argv[1]);
if (tagType == TAG_NUM_OF_ITEM_TYPES) { if (tagType == TAG_NUM_OF_ITEM_TYPES) {
command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]); command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]);
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
if (tagType == LOCATE_TAG_ANY_TYPE) { if (tagType == LOCATE_TAG_ANY_TYPE) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"\"any\" is not a valid return tag type"); "\"any\" is not a valid return tag type");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
/* for compatibility with < 0.12.0 */ /* for compatibility with < 0.12.0 */
...@@ -180,7 +180,7 @@ handle_list(Client &client, int argc, char *argv[]) ...@@ -180,7 +180,7 @@ handle_list(Client &client, int argc, char *argv[])
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"should be \"%s\" for 3 arguments", "should be \"%s\" for 3 arguments",
tag_item_names[TAG_ALBUM]); tag_item_names[TAG_ALBUM]);
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
filter = new SongFilter((unsigned)TAG_ARTIST, argv[2]); filter = new SongFilter((unsigned)TAG_ARTIST, argv[2]);
...@@ -190,15 +190,15 @@ handle_list(Client &client, int argc, char *argv[]) ...@@ -190,15 +190,15 @@ handle_list(Client &client, int argc, char *argv[])
delete filter; delete filter;
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"not able to parse args"); "not able to parse args");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} else } else
filter = nullptr; filter = nullptr;
Error error; Error error;
enum command_return ret = CommandResult ret =
listAllUniqueTags(client, tagType, filter, error) listAllUniqueTags(client, tagType, filter, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
delete filter; delete filter;
...@@ -206,7 +206,7 @@ handle_list(Client &client, int argc, char *argv[]) ...@@ -206,7 +206,7 @@ handle_list(Client &client, int argc, char *argv[])
return ret; return ret;
} }
enum command_return CommandResult
handle_listallinfo(Client &client, gcc_unused int argc, char *argv[]) handle_listallinfo(Client &client, gcc_unused int argc, char *argv[])
{ {
const char *directory = ""; const char *directory = "";
...@@ -216,6 +216,6 @@ handle_listallinfo(Client &client, gcc_unused int argc, char *argv[]) ...@@ -216,6 +216,6 @@ handle_listallinfo(Client &client, gcc_unused int argc, char *argv[])
Error error; Error error;
return printInfoForAllIn(client, directory, error) return printInfoForAllIn(client, directory, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
...@@ -20,38 +20,38 @@ ...@@ -20,38 +20,38 @@
#ifndef MPD_DATABASE_COMMANDS_HXX #ifndef MPD_DATABASE_COMMANDS_HXX
#define MPD_DATABASE_COMMANDS_HXX #define MPD_DATABASE_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_lsinfo2(Client &client, int argc, char *argv[]); handle_lsinfo2(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_find(Client &client, int argc, char *argv[]); handle_find(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_findadd(Client &client, int argc, char *argv[]); handle_findadd(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_search(Client &client, int argc, char *argv[]); handle_search(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_searchadd(Client &client, int argc, char *argv[]); handle_searchadd(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_searchaddpl(Client &client, int argc, char *argv[]); handle_searchaddpl(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_count(Client &client, int argc, char *argv[]); handle_count(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_listall(Client &client, int argc, char *argv[]); handle_listall(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_list(Client &client, int argc, char *argv[]); handle_list(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_listallinfo(Client &client, int argc, char *argv[]); handle_listallinfo(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -31,29 +31,29 @@ ...@@ -31,29 +31,29 @@
#include <assert.h> #include <assert.h>
enum command_return CommandResult
handle_subscribe(Client &client, gcc_unused int argc, char *argv[]) handle_subscribe(Client &client, gcc_unused int argc, char *argv[])
{ {
assert(argc == 2); assert(argc == 2);
switch (client.Subscribe(argv[1])) { switch (client.Subscribe(argv[1])) {
case Client::SubscribeResult::OK: case Client::SubscribeResult::OK:
return COMMAND_RETURN_OK; return CommandResult::OK;
case Client::SubscribeResult::INVALID: case Client::SubscribeResult::INVALID:
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"invalid channel name"); "invalid channel name");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case Client::SubscribeResult::ALREADY: case Client::SubscribeResult::ALREADY:
command_error(client, ACK_ERROR_EXIST, command_error(client, ACK_ERROR_EXIST,
"already subscribed to this channel"); "already subscribed to this channel");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
case Client::SubscribeResult::FULL: case Client::SubscribeResult::FULL:
command_error(client, ACK_ERROR_EXIST, command_error(client, ACK_ERROR_EXIST,
"subscription list is full"); "subscription list is full");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
/* unreachable */ /* unreachable */
...@@ -61,21 +61,21 @@ handle_subscribe(Client &client, gcc_unused int argc, char *argv[]) ...@@ -61,21 +61,21 @@ handle_subscribe(Client &client, gcc_unused int argc, char *argv[])
gcc_unreachable(); gcc_unreachable();
} }
enum command_return CommandResult
handle_unsubscribe(Client &client, gcc_unused int argc, char *argv[]) handle_unsubscribe(Client &client, gcc_unused int argc, char *argv[])
{ {
assert(argc == 2); assert(argc == 2);
if (client.Unsubscribe(argv[1])) if (client.Unsubscribe(argv[1]))
return COMMAND_RETURN_OK; return CommandResult::OK;
else { else {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"not subscribed to this channel"); "not subscribed to this channel");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
enum command_return CommandResult
handle_channels(Client &client, handle_channels(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -89,10 +89,10 @@ handle_channels(Client &client, ...@@ -89,10 +89,10 @@ handle_channels(Client &client,
for (const auto &channel : channels) for (const auto &channel : channels)
client_printf(client, "channel: %s\n", channel.c_str()); client_printf(client, "channel: %s\n", channel.c_str());
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_read_messages(Client &client, handle_read_messages(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -106,10 +106,10 @@ handle_read_messages(Client &client, ...@@ -106,10 +106,10 @@ handle_read_messages(Client &client,
client.messages.pop_front(); client.messages.pop_front();
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_send_message(Client &client, handle_send_message(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -118,7 +118,7 @@ handle_send_message(Client &client, ...@@ -118,7 +118,7 @@ handle_send_message(Client &client,
if (!client_message_valid_channel_name(argv[1])) { if (!client_message_valid_channel_name(argv[1])) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"invalid channel name"); "invalid channel name");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
bool sent = false; bool sent = false;
...@@ -128,10 +128,10 @@ handle_send_message(Client &client, ...@@ -128,10 +128,10 @@ handle_send_message(Client &client,
sent = true; sent = true;
if (sent) if (sent)
return COMMAND_RETURN_OK; return CommandResult::OK;
else { else {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"nobody is subscribed to this channel"); "nobody is subscribed to this channel");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
...@@ -20,23 +20,23 @@ ...@@ -20,23 +20,23 @@
#ifndef MPD_MESSAGE_COMMANDS_HXX #ifndef MPD_MESSAGE_COMMANDS_HXX
#define MPD_MESSAGE_COMMANDS_HXX #define MPD_MESSAGE_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_subscribe(Client &client, int argc, char *argv[]); handle_subscribe(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_unsubscribe(Client &client, int argc, char *argv[]); handle_unsubscribe(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_channels(Client &client, int argc, char *argv[]); handle_channels(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_read_messages(Client &client, int argc, char *argv[]); handle_read_messages(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_send_message(Client &client, int argc, char *argv[]); handle_send_message(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -63,47 +63,47 @@ print_spl_list(Client &client, const PlaylistVector &list) ...@@ -63,47 +63,47 @@ print_spl_list(Client &client, const PlaylistVector &list)
} }
} }
enum command_return CommandResult
handle_urlhandlers(Client &client, handle_urlhandlers(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
if (client.IsLocal()) if (client.IsLocal())
client_puts(client, "handler: file://\n"); client_puts(client, "handler: file://\n");
print_supported_uri_schemes(client); print_supported_uri_schemes(client);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_decoders(Client &client, handle_decoders(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
decoder_list_print(client); decoder_list_print(client);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_tagtypes(Client &client, handle_tagtypes(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
tag_print_types(client); tag_print_types(client);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_kill(gcc_unused Client &client, handle_kill(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
return COMMAND_RETURN_KILL; return CommandResult::KILL;
} }
enum command_return CommandResult
handle_close(gcc_unused Client &client, handle_close(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
return COMMAND_RETURN_CLOSE; return CommandResult::CLOSE;
} }
enum command_return CommandResult
handle_lsinfo(Client &client, int argc, char *argv[]) handle_lsinfo(Client &client, int argc, char *argv[])
{ {
const char *uri; const char *uri;
...@@ -122,7 +122,7 @@ handle_lsinfo(Client &client, int argc, char *argv[]) ...@@ -122,7 +122,7 @@ handle_lsinfo(Client &client, int argc, char *argv[])
if (path_fs.IsNull()) { if (path_fs.IsNull()) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"unsupported file name"); "unsupported file name");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
Error error; Error error;
...@@ -133,16 +133,16 @@ handle_lsinfo(Client &client, int argc, char *argv[]) ...@@ -133,16 +133,16 @@ handle_lsinfo(Client &client, int argc, char *argv[])
if (song == NULL) { if (song == NULL) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"No such file"); "No such file");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
song_print_info(client, *song); song_print_info(client, *song);
song->Free(); song->Free();
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return result = handle_lsinfo2(client, argc, argv); CommandResult result = handle_lsinfo2(client, argc, argv);
if (result != COMMAND_RETURN_OK) if (result != CommandResult::OK)
return result; return result;
if (isRootDirectory(uri)) { if (isRootDirectory(uri)) {
...@@ -151,10 +151,10 @@ handle_lsinfo(Client &client, int argc, char *argv[]) ...@@ -151,10 +151,10 @@ handle_lsinfo(Client &client, int argc, char *argv[])
print_spl_list(client, list); print_spl_list(client, list);
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_update(Client &client, gcc_unused int argc, char *argv[]) handle_update(Client &client, gcc_unused int argc, char *argv[])
{ {
const char *path = ""; const char *path = "";
...@@ -170,22 +170,22 @@ handle_update(Client &client, gcc_unused int argc, char *argv[]) ...@@ -170,22 +170,22 @@ handle_update(Client &client, gcc_unused int argc, char *argv[])
else if (!uri_safe_local(path)) { else if (!uri_safe_local(path)) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"Malformed path"); "Malformed path");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
ret = update_enqueue(path, false); ret = update_enqueue(path, false);
if (ret > 0) { if (ret > 0) {
client_printf(client, "updating_db: %i\n", ret); client_printf(client, "updating_db: %i\n", ret);
return COMMAND_RETURN_OK; return CommandResult::OK;
} else { } else {
command_error(client, ACK_ERROR_UPDATE_ALREADY, command_error(client, ACK_ERROR_UPDATE_ALREADY,
"already updating"); "already updating");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
enum command_return CommandResult
handle_rescan(Client &client, gcc_unused int argc, char *argv[]) handle_rescan(Client &client, gcc_unused int argc, char *argv[])
{ {
const char *path = ""; const char *path = "";
...@@ -198,93 +198,93 @@ handle_rescan(Client &client, gcc_unused int argc, char *argv[]) ...@@ -198,93 +198,93 @@ handle_rescan(Client &client, gcc_unused int argc, char *argv[])
if (!uri_safe_local(path)) { if (!uri_safe_local(path)) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"Malformed path"); "Malformed path");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
ret = update_enqueue(path, true); ret = update_enqueue(path, true);
if (ret > 0) { if (ret > 0) {
client_printf(client, "updating_db: %i\n", ret); client_printf(client, "updating_db: %i\n", ret);
return COMMAND_RETURN_OK; return CommandResult::OK;
} else { } else {
command_error(client, ACK_ERROR_UPDATE_ALREADY, command_error(client, ACK_ERROR_UPDATE_ALREADY,
"already updating"); "already updating");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
enum command_return CommandResult
handle_setvol(Client &client, gcc_unused int argc, char *argv[]) handle_setvol(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned level; unsigned level;
bool success; bool success;
if (!check_unsigned(client, &level, argv[1])) if (!check_unsigned(client, &level, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
if (level > 100) { if (level > 100) {
command_error(client, ACK_ERROR_ARG, "Invalid volume value"); command_error(client, ACK_ERROR_ARG, "Invalid volume value");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
success = volume_level_change(level); success = volume_level_change(level);
if (!success) { if (!success) {
command_error(client, ACK_ERROR_SYSTEM, command_error(client, ACK_ERROR_SYSTEM,
"problems setting volume"); "problems setting volume");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_stats(Client &client, handle_stats(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
stats_print(client); stats_print(client);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_ping(gcc_unused Client &client, handle_ping(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_password(Client &client, gcc_unused int argc, char *argv[]) handle_password(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned permission = 0; unsigned permission = 0;
if (getPermissionFromPassword(argv[1], &permission) < 0) { if (getPermissionFromPassword(argv[1], &permission) < 0) {
command_error(client, ACK_ERROR_PASSWORD, "incorrect password"); command_error(client, ACK_ERROR_PASSWORD, "incorrect password");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
client.SetPermission(permission); client.SetPermission(permission);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_config(Client &client, handle_config(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
if (!client.IsLocal()) { if (!client.IsLocal()) {
command_error(client, ACK_ERROR_PERMISSION, command_error(client, ACK_ERROR_PERMISSION,
"Command only permitted to local clients"); "Command only permitted to local clients");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
const char *path = mapper_get_music_directory_utf8(); const char *path = mapper_get_music_directory_utf8();
if (path != NULL) if (path != NULL)
client_printf(client, "music_directory: %s\n", path); client_printf(client, "music_directory: %s\n", path);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_idle(Client &client, handle_idle(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -311,5 +311,5 @@ handle_idle(Client &client, ...@@ -311,5 +311,5 @@ handle_idle(Client &client,
/* enable "idle" mode on this client */ /* enable "idle" mode on this client */
client.IdleWait(flags); client.IdleWait(flags);
return COMMAND_RETURN_IDLE; return CommandResult::IDLE;
} }
...@@ -20,50 +20,50 @@ ...@@ -20,50 +20,50 @@
#ifndef MPD_OTHER_COMMANDS_HXX #ifndef MPD_OTHER_COMMANDS_HXX
#define MPD_OTHER_COMMANDS_HXX #define MPD_OTHER_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_urlhandlers(Client &client, int argc, char *argv[]); handle_urlhandlers(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_decoders(Client &client, int argc, char *argv[]); handle_decoders(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_tagtypes(Client &client, int argc, char *argv[]); handle_tagtypes(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_kill(Client &client, int argc, char *argv[]); handle_kill(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_close(Client &client, int argc, char *argv[]); handle_close(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_lsinfo(Client &client, int argc, char *argv[]); handle_lsinfo(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_update(Client &client, int argc, char *argv[]); handle_update(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_rescan(Client &client, int argc, char *argv[]); handle_rescan(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_setvol(Client &client, int argc, char *argv[]); handle_setvol(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_stats(Client &client, int argc, char *argv[]); handle_stats(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_ping(Client &client, int argc, char *argv[]); handle_ping(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_password(Client &client, int argc, char *argv[]); handle_password(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_config(Client &client, int argc, char *argv[]); handle_config(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_idle(Client &client, int argc, char *argv[]); handle_idle(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -26,65 +26,65 @@ ...@@ -26,65 +26,65 @@
#include <string.h> #include <string.h>
enum command_return CommandResult
handle_enableoutput(Client &client, gcc_unused int argc, char *argv[]) handle_enableoutput(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned device; unsigned device;
bool ret; bool ret;
if (!check_unsigned(client, &device, argv[1])) if (!check_unsigned(client, &device, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
ret = audio_output_enable_index(device); ret = audio_output_enable_index(device);
if (!ret) { if (!ret) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"No such audio output"); "No such audio output");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_disableoutput(Client &client, gcc_unused int argc, char *argv[]) handle_disableoutput(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned device; unsigned device;
bool ret; bool ret;
if (!check_unsigned(client, &device, argv[1])) if (!check_unsigned(client, &device, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
ret = audio_output_disable_index(device); ret = audio_output_disable_index(device);
if (!ret) { if (!ret) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"No such audio output"); "No such audio output");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_toggleoutput(Client &client, gcc_unused int argc, char *argv[]) handle_toggleoutput(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned device; unsigned device;
if (!check_unsigned(client, &device, argv[1])) if (!check_unsigned(client, &device, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
if (!audio_output_toggle_index(device)) { if (!audio_output_toggle_index(device)) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"No such audio output"); "No such audio output");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_devices(Client &client, handle_devices(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
printAudioDevices(client); printAudioDevices(client);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
...@@ -20,20 +20,20 @@ ...@@ -20,20 +20,20 @@
#ifndef MPD_OUTPUT_COMMANDS_HXX #ifndef MPD_OUTPUT_COMMANDS_HXX
#define MPD_OUTPUT_COMMANDS_HXX #define MPD_OUTPUT_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_enableoutput(Client &client, int argc, char *argv[]); handle_enableoutput(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_disableoutput(Client &client, int argc, char *argv[]); handle_disableoutput(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_toggleoutput(Client &client, int argc, char *argv[]); handle_toggleoutput(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_devices(Client &client, int argc, char *argv[]); handle_devices(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -52,62 +52,62 @@ ...@@ -52,62 +52,62 @@
#define COMMAND_STATUS_AUDIO "audio" #define COMMAND_STATUS_AUDIO "audio"
#define COMMAND_STATUS_UPDATING_DB "updating_db" #define COMMAND_STATUS_UPDATING_DB "updating_db"
enum command_return CommandResult
handle_play(Client &client, int argc, char *argv[]) handle_play(Client &client, int argc, char *argv[])
{ {
int song = -1; int song = -1;
if (argc == 2 && !check_int(client, &song, argv[1])) if (argc == 2 && !check_int(client, &song, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
PlaylistResult result = client.partition.PlayPosition(song); PlaylistResult result = client.partition.PlayPosition(song);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_playid(Client &client, int argc, char *argv[]) handle_playid(Client &client, int argc, char *argv[])
{ {
int id = -1; int id = -1;
if (argc == 2 && !check_int(client, &id, argv[1])) if (argc == 2 && !check_int(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
PlaylistResult result = client.partition.PlayId(id); PlaylistResult result = client.partition.PlayId(id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_stop(Client &client, handle_stop(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
client.partition.Stop(); client.partition.Stop();
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_currentsong(Client &client, handle_currentsong(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
playlist_print_current(client, client.playlist); playlist_print_current(client, client.playlist);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_pause(Client &client, handle_pause(Client &client,
int argc, char *argv[]) int argc, char *argv[])
{ {
if (argc == 2) { if (argc == 2) {
bool pause_flag; bool pause_flag;
if (!check_bool(client, &pause_flag, argv[1])) if (!check_bool(client, &pause_flag, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.player_control.SetPause(pause_flag); client.player_control.SetPause(pause_flag);
} else } else
client.player_control.Pause(); client.player_control.Pause();
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_status(Client &client, handle_status(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -202,10 +202,10 @@ handle_status(Client &client, ...@@ -202,10 +202,10 @@ handle_status(Client &client,
song, playlist.PositionToId(song)); song, playlist.PositionToId(song));
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_next(Client &client, handle_next(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -219,170 +219,170 @@ handle_next(Client &client, ...@@ -219,170 +219,170 @@ handle_next(Client &client,
client.partition.PlayNext(); client.partition.PlayNext();
playlist.queue.single = single; playlist.queue.single = single;
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_previous(Client &client, handle_previous(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
client.partition.PlayPrevious(); client.partition.PlayPrevious();
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_repeat(Client &client, gcc_unused int argc, char *argv[]) handle_repeat(Client &client, gcc_unused int argc, char *argv[])
{ {
bool status; bool status;
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.partition.SetRepeat(status); client.partition.SetRepeat(status);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_single(Client &client, gcc_unused int argc, char *argv[]) handle_single(Client &client, gcc_unused int argc, char *argv[])
{ {
bool status; bool status;
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.partition.SetSingle(status); client.partition.SetSingle(status);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_consume(Client &client, gcc_unused int argc, char *argv[]) handle_consume(Client &client, gcc_unused int argc, char *argv[])
{ {
bool status; bool status;
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.partition.SetConsume(status); client.partition.SetConsume(status);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_random(Client &client, gcc_unused int argc, char *argv[]) handle_random(Client &client, gcc_unused int argc, char *argv[])
{ {
bool status; bool status;
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.partition.SetRandom(status); client.partition.SetRandom(status);
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.partition.GetRandom())); audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.partition.GetRandom()));
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_clearerror(gcc_unused Client &client, handle_clearerror(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
client.player_control.ClearError(); client.player_control.ClearError();
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_seek(Client &client, gcc_unused int argc, char *argv[]) handle_seek(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned song, seek_time; unsigned song, seek_time;
if (!check_unsigned(client, &song, argv[1])) if (!check_unsigned(client, &song, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
PlaylistResult result = PlaylistResult result =
client.partition.SeekSongPosition(song, seek_time); client.partition.SeekSongPosition(song, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_seekid(Client &client, gcc_unused int argc, char *argv[]) handle_seekid(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned id, seek_time; unsigned id, seek_time;
if (!check_unsigned(client, &id, argv[1])) if (!check_unsigned(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
PlaylistResult result = PlaylistResult result =
client.partition.SeekSongId(id, seek_time); client.partition.SeekSongId(id, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_seekcur(Client &client, gcc_unused int argc, char *argv[]) handle_seekcur(Client &client, gcc_unused int argc, char *argv[])
{ {
const char *p = argv[1]; const char *p = argv[1];
bool relative = *p == '+' || *p == '-'; bool relative = *p == '+' || *p == '-';
int seek_time; int seek_time;
if (!check_int(client, &seek_time, p)) if (!check_int(client, &seek_time, p))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
PlaylistResult result = PlaylistResult result =
client.partition.SeekCurrent(seek_time, relative); client.partition.SeekCurrent(seek_time, relative);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_crossfade(Client &client, gcc_unused int argc, char *argv[]) handle_crossfade(Client &client, gcc_unused int argc, char *argv[])
{ {
unsigned xfade_time; unsigned xfade_time;
if (!check_unsigned(client, &xfade_time, argv[1])) if (!check_unsigned(client, &xfade_time, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.player_control.SetCrossFade(xfade_time); client.player_control.SetCrossFade(xfade_time);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_mixrampdb(Client &client, gcc_unused int argc, char *argv[]) handle_mixrampdb(Client &client, gcc_unused int argc, char *argv[])
{ {
float db; float db;
if (!check_float(client, &db, argv[1])) if (!check_float(client, &db, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.player_control.SetMixRampDb(db); client.player_control.SetMixRampDb(db);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_mixrampdelay(Client &client, gcc_unused int argc, char *argv[]) handle_mixrampdelay(Client &client, gcc_unused int argc, char *argv[])
{ {
float delay_secs; float delay_secs;
if (!check_float(client, &delay_secs, argv[1])) if (!check_float(client, &delay_secs, argv[1]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
client.player_control.SetMixRampDelay(delay_secs); client.player_control.SetMixRampDelay(delay_secs);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_replay_gain_mode(Client &client, handle_replay_gain_mode(Client &client,
gcc_unused int argc, char *argv[]) gcc_unused int argc, char *argv[])
{ {
if (!replay_gain_set_mode_string(argv[1])) { if (!replay_gain_set_mode_string(argv[1])) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"Unrecognized replay gain mode"); "Unrecognized replay gain mode");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.playlist.queue.random)); audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.playlist.queue.random));
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
enum command_return CommandResult
handle_replay_gain_status(Client &client, handle_replay_gain_status(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
client_printf(client, "replay_gain_mode: %s\n", client_printf(client, "replay_gain_mode: %s\n",
replay_gain_get_mode_string()); replay_gain_get_mode_string());
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
...@@ -20,71 +20,71 @@ ...@@ -20,71 +20,71 @@
#ifndef MPD_PLAYER_COMMANDS_HXX #ifndef MPD_PLAYER_COMMANDS_HXX
#define MPD_PLAYER_COMMANDS_HXX #define MPD_PLAYER_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_play(Client &client, int argc, char *argv[]); handle_play(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playid(Client &client, int argc, char *argv[]); handle_playid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_stop(Client &client, int argc, char *argv[]); handle_stop(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_currentsong(Client &client, int argc, char *argv[]); handle_currentsong(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_pause(Client &client, int argc, char *argv[]); handle_pause(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_status(Client &client, int argc, char *argv[]); handle_status(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_next(Client &client, int argc, char *argv[]); handle_next(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_previous(Client &client, int argc, char *avg[]); handle_previous(Client &client, int argc, char *avg[]);
enum command_return CommandResult
handle_repeat(Client &client, int argc, char *argv[]); handle_repeat(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_single(Client &client, int argc, char *argv[]); handle_single(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_consume(Client &client, int argc, char *argv[]); handle_consume(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_random(Client &client, int argc, char *argv[]); handle_random(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_clearerror(Client &client, int argc, char *argv[]); handle_clearerror(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_seek(Client &client, int argc, char *argv[]); handle_seek(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_seekid(Client &client, int argc, char *argv[]); handle_seekid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_seekcur(Client &client, int argc, char *argv[]); handle_seekcur(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_crossfade(Client &client, int argc, char *argv[]); handle_crossfade(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_mixrampdb(Client &client, int argc, char *argv[]); handle_mixrampdb(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_mixrampdelay(Client &client, int argc, char *argv[]); handle_mixrampdelay(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_replay_gain_mode(Client &client, int argc, char *argv[]); handle_replay_gain_mode(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_replay_gain_status(Client &client, int argc, char *argv[]); handle_replay_gain_status(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -49,14 +49,14 @@ print_spl_list(Client &client, const PlaylistVector &list) ...@@ -49,14 +49,14 @@ print_spl_list(Client &client, const PlaylistVector &list)
} }
} }
enum command_return CommandResult
handle_save(Client &client, gcc_unused int argc, char *argv[]) handle_save(Client &client, gcc_unused int argc, char *argv[])
{ {
PlaylistResult result = spl_save_playlist(argv[1], client.playlist); PlaylistResult result = spl_save_playlist(argv[1], client.playlist);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return CommandResult
handle_load(Client &client, int argc, char *argv[]) handle_load(Client &client, int argc, char *argv[])
{ {
unsigned start_index, end_index; unsigned start_index, end_index;
...@@ -65,7 +65,7 @@ handle_load(Client &client, int argc, char *argv[]) ...@@ -65,7 +65,7 @@ handle_load(Client &client, int argc, char *argv[])
start_index = 0; start_index = 0;
end_index = unsigned(-1); end_index = unsigned(-1);
} else if (!check_range(client, &start_index, &end_index, argv[2])) } else if (!check_range(client, &start_index, &end_index, argv[2]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
const PlaylistResult result = const PlaylistResult result =
playlist_open_into_queue(argv[1], playlist_open_into_queue(argv[1],
...@@ -79,7 +79,7 @@ handle_load(Client &client, int argc, char *argv[]) ...@@ -79,7 +79,7 @@ handle_load(Client &client, int argc, char *argv[])
if (playlist_load_spl(client.playlist, client.player_control, if (playlist_load_spl(client.playlist, client.player_control,
argv[1], start_index, end_index, argv[1], start_index, end_index,
error)) error))
return COMMAND_RETURN_OK; return CommandResult::OK;
if (error.IsDomain(playlist_domain) && if (error.IsDomain(playlist_domain) &&
PlaylistResult(error.GetCode()) == PlaylistResult::BAD_NAME) { PlaylistResult(error.GetCode()) == PlaylistResult::BAD_NAME) {
...@@ -95,91 +95,91 @@ handle_load(Client &client, int argc, char *argv[]) ...@@ -95,91 +95,91 @@ handle_load(Client &client, int argc, char *argv[])
return print_error(client, error); return print_error(client, error);
} }
enum command_return CommandResult
handle_listplaylist(Client &client, gcc_unused int argc, char *argv[]) handle_listplaylist(Client &client, gcc_unused int argc, char *argv[])
{ {
if (playlist_file_print(client, argv[1], false)) if (playlist_file_print(client, argv[1], false))
return COMMAND_RETURN_OK; return CommandResult::OK;
Error error; Error error;
return spl_print(client, argv[1], false, error) return spl_print(client, argv[1], false, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_listplaylistinfo(Client &client, handle_listplaylistinfo(Client &client,
gcc_unused int argc, char *argv[]) gcc_unused int argc, char *argv[])
{ {
if (playlist_file_print(client, argv[1], true)) if (playlist_file_print(client, argv[1], true))
return COMMAND_RETURN_OK; return CommandResult::OK;
Error error; Error error;
return spl_print(client, argv[1], true, error) return spl_print(client, argv[1], true, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_rm(Client &client, gcc_unused int argc, char *argv[]) handle_rm(Client &client, gcc_unused int argc, char *argv[])
{ {
Error error; Error error;
return spl_delete(argv[1], error) return spl_delete(argv[1], error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_rename(Client &client, gcc_unused int argc, char *argv[]) handle_rename(Client &client, gcc_unused int argc, char *argv[])
{ {
Error error; Error error;
return spl_rename(argv[1], argv[2], error) return spl_rename(argv[1], argv[2], error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_playlistdelete(Client &client, handle_playlistdelete(Client &client,
gcc_unused int argc, char *argv[]) { gcc_unused int argc, char *argv[]) {
char *playlist = argv[1]; char *playlist = argv[1];
unsigned from; unsigned from;
if (!check_unsigned(client, &from, argv[2])) if (!check_unsigned(client, &from, argv[2]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
Error error; Error error;
return spl_remove_index(playlist, from, error) return spl_remove_index(playlist, from, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_playlistmove(Client &client, gcc_unused int argc, char *argv[]) handle_playlistmove(Client &client, gcc_unused int argc, char *argv[])
{ {
char *playlist = argv[1]; char *playlist = argv[1];
unsigned from, to; unsigned from, to;
if (!check_unsigned(client, &from, argv[2])) if (!check_unsigned(client, &from, argv[2]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
if (!check_unsigned(client, &to, argv[3])) if (!check_unsigned(client, &to, argv[3]))
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
Error error; Error error;
return spl_move_index(playlist, from, to, error) return spl_move_index(playlist, from, to, error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_playlistclear(Client &client, gcc_unused int argc, char *argv[]) handle_playlistclear(Client &client, gcc_unused int argc, char *argv[])
{ {
Error error; Error error;
return spl_clear(argv[1], error) return spl_clear(argv[1], error)
? COMMAND_RETURN_OK ? CommandResult::OK
: print_error(client, error); : print_error(client, error);
} }
enum command_return CommandResult
handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
{ {
char *playlist = argv[1]; char *playlist = argv[1];
...@@ -191,7 +191,7 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) ...@@ -191,7 +191,7 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
if (!uri_supported_scheme(uri)) { if (!uri_supported_scheme(uri)) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"unsupported URI scheme"); "unsupported URI scheme");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
success = spl_append_uri(uri, playlist, error); success = spl_append_uri(uri, playlist, error);
...@@ -202,13 +202,13 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) ...@@ -202,13 +202,13 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
if (!success && !error.IsDefined()) { if (!success && !error.IsDefined()) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found"); "directory or file not found");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return success ? COMMAND_RETURN_OK : print_error(client, error); return success ? CommandResult::OK : print_error(client, error);
} }
enum command_return CommandResult
handle_listplaylists(Client &client, handle_listplaylists(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])
{ {
...@@ -218,5 +218,5 @@ handle_listplaylists(Client &client, ...@@ -218,5 +218,5 @@ handle_listplaylists(Client &client,
return print_error(client, error); return print_error(client, error);
print_spl_list(client, list); print_spl_list(client, list);
return COMMAND_RETURN_OK; return CommandResult::OK;
} }
...@@ -20,41 +20,41 @@ ...@@ -20,41 +20,41 @@
#ifndef MPD_PLAYLIST_COMMANDS_HXX #ifndef MPD_PLAYLIST_COMMANDS_HXX
#define MPD_PLAYLIST_COMMANDS_HXX #define MPD_PLAYLIST_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_save(Client &client, int argc, char *argv[]); handle_save(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_load(Client &client, int argc, char *argv[]); handle_load(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_listplaylist(Client &client, int argc, char *argv[]); handle_listplaylist(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_listplaylistinfo(Client &client, int argc, char *argv[]); handle_listplaylistinfo(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_rm(Client &client, int argc, char *argv[]); handle_rm(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_rename(Client &client, int argc, char *argv[]); handle_rename(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistdelete(Client &client, int argc, char *argv[]); handle_playlistdelete(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistmove(Client &client, int argc, char *argv[]); handle_playlistmove(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistclear(Client &client, int argc, char *argv[]); handle_playlistclear(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistadd(Client &client, int argc, char *argv[]); handle_playlistadd(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_listplaylists(Client &client, int argc, char *argv[]); handle_listplaylists(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -20,65 +20,65 @@ ...@@ -20,65 +20,65 @@
#ifndef MPD_QUEUE_COMMANDS_HXX #ifndef MPD_QUEUE_COMMANDS_HXX
#define MPD_QUEUE_COMMANDS_HXX #define MPD_QUEUE_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_add(Client &client, int argc, char *argv[]); handle_add(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_addid(Client &client, int argc, char *argv[]); handle_addid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_delete(Client &client, int argc, char *argv[]); handle_delete(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_deleteid(Client &client, int argc, char *argv[]); handle_deleteid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlist(Client &client, int argc, char *argv[]); handle_playlist(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_shuffle(Client &client, int argc, char *argv[]); handle_shuffle(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_clear(Client &client, int argc, char *argv[]); handle_clear(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_plchanges(Client &client, int argc, char *argv[]); handle_plchanges(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_plchangesposid(Client &client, int argc, char *argv[]); handle_plchangesposid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistinfo(Client &client, int argc, char *argv[]); handle_playlistinfo(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistid(Client &client, int argc, char *argv[]); handle_playlistid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistfind(Client &client, int argc, char *argv[]); handle_playlistfind(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_playlistsearch(Client &client, int argc, char *argv[]); handle_playlistsearch(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_prio(Client &client, int argc, char *argv[]); handle_prio(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_prioid(Client &client, int argc, char *argv[]); handle_prioid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_move(Client &client, int argc, char *argv[]); handle_move(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_moveid(Client &client, int argc, char *argv[]); handle_moveid(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_swap(Client &client, int argc, char *argv[]); handle_swap(Client &client, int argc, char *argv[]);
enum command_return CommandResult
handle_swapid(Client &client, int argc, char *argv[]); handle_swapid(Client &client, int argc, char *argv[]);
#endif #endif
...@@ -51,7 +51,7 @@ sticker_song_find_print_cb(Song &song, const char *value, ...@@ -51,7 +51,7 @@ sticker_song_find_print_cb(Song &song, const char *value,
sticker_print_value(data->client, data->name, value); sticker_print_value(data->client, data->name, value);
} }
static enum command_return static CommandResult
handle_sticker_song(Client &client, int argc, char *argv[]) handle_sticker_song(Client &client, int argc, char *argv[])
{ {
Error error; Error error;
...@@ -70,12 +70,12 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -70,12 +70,12 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (value.empty()) { if (value.empty()) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"no such sticker"); "no such sticker");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
sticker_print_value(client, argv[4], value.c_str()); sticker_print_value(client, argv[4], value.c_str());
return COMMAND_RETURN_OK; return CommandResult::OK;
/* list song song_id */ /* list song song_id */
} else if (argc == 4 && strcmp(argv[1], "list") == 0) { } else if (argc == 4 && strcmp(argv[1], "list") == 0) {
Song *song = db->GetSong(argv[3], error); Song *song = db->GetSong(argv[3], error);
...@@ -89,7 +89,7 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -89,7 +89,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
sticker_free(sticker); sticker_free(sticker);
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
/* set song song_id id key */ /* set song song_id id key */
} else if (argc == 6 && strcmp(argv[1], "set") == 0) { } else if (argc == 6 && strcmp(argv[1], "set") == 0) {
Song *song = db->GetSong(argv[3], error); Song *song = db->GetSong(argv[3], error);
...@@ -101,10 +101,10 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -101,10 +101,10 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (!ret) { if (!ret) {
command_error(client, ACK_ERROR_SYSTEM, command_error(client, ACK_ERROR_SYSTEM,
"failed to set sticker value"); "failed to set sticker value");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
/* delete song song_id [key] */ /* delete song song_id [key] */
} else if ((argc == 4 || argc == 5) && } else if ((argc == 4 || argc == 5) &&
strcmp(argv[1], "delete") == 0) { strcmp(argv[1], "delete") == 0) {
...@@ -119,10 +119,10 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -119,10 +119,10 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (!ret) { if (!ret) {
command_error(client, ACK_ERROR_SYSTEM, command_error(client, ACK_ERROR_SYSTEM,
"no such sticker"); "no such sticker");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
/* find song dir key */ /* find song dir key */
} else if (argc == 5 && strcmp(argv[1], "find") == 0) { } else if (argc == 5 && strcmp(argv[1], "find") == 0) {
/* "sticker find song a/directory name" */ /* "sticker find song a/directory name" */
...@@ -138,7 +138,7 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -138,7 +138,7 @@ handle_sticker_song(Client &client, int argc, char *argv[])
db_unlock(); db_unlock();
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"no such directory"); "no such directory");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
success = sticker_song_find(*directory, data.name, success = sticker_song_find(*directory, data.name,
...@@ -147,17 +147,17 @@ handle_sticker_song(Client &client, int argc, char *argv[]) ...@@ -147,17 +147,17 @@ handle_sticker_song(Client &client, int argc, char *argv[])
if (!success) { if (!success) {
command_error(client, ACK_ERROR_SYSTEM, command_error(client, ACK_ERROR_SYSTEM,
"failed to set search sticker database"); "failed to set search sticker database");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
return COMMAND_RETURN_OK; return CommandResult::OK;
} else { } else {
command_error(client, ACK_ERROR_ARG, "bad request"); command_error(client, ACK_ERROR_ARG, "bad request");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
enum command_return CommandResult
handle_sticker(Client &client, int argc, char *argv[]) handle_sticker(Client &client, int argc, char *argv[])
{ {
assert(argc >= 4); assert(argc >= 4);
...@@ -165,7 +165,7 @@ handle_sticker(Client &client, int argc, char *argv[]) ...@@ -165,7 +165,7 @@ handle_sticker(Client &client, int argc, char *argv[])
if (!sticker_enabled()) { if (!sticker_enabled()) {
command_error(client, ACK_ERROR_UNKNOWN, command_error(client, ACK_ERROR_UNKNOWN,
"sticker database is disabled"); "sticker database is disabled");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
if (strcmp(argv[2], "song") == 0) if (strcmp(argv[2], "song") == 0)
...@@ -173,6 +173,6 @@ handle_sticker(Client &client, int argc, char *argv[]) ...@@ -173,6 +173,6 @@ handle_sticker(Client &client, int argc, char *argv[])
else { else {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"unknown sticker domain"); "unknown sticker domain");
return COMMAND_RETURN_ERROR; return CommandResult::ERROR;
} }
} }
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
#ifndef MPD_STICKER_COMMANDS_HXX #ifndef MPD_STICKER_COMMANDS_HXX
#define MPD_STICKER_COMMANDS_HXX #define MPD_STICKER_COMMANDS_HXX
#include "command.h" #include "CommandResult.hxx"
class Client; class Client;
enum command_return CommandResult
handle_sticker(Client &client, int argc, char *argv[]); handle_sticker(Client &client, int argc, char *argv[]);
#endif #endif
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