2012-08-07 22:26:14 +02:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2012-08-07 22:26:14 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-09-25 12:10:12 +02:00
|
|
|
#include "CommandError.hxx"
|
2014-01-24 16:18:50 +01:00
|
|
|
#include "db/DatabaseError.hxx"
|
2013-01-03 10:33:04 +01:00
|
|
|
#include "protocol/Result.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
|
2012-08-07 22:26:14 +02:00
|
|
|
#include <assert.h>
|
2013-12-15 18:30:25 +01:00
|
|
|
#include <string.h>
|
2012-08-07 22:26:14 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 19:50:54 +02:00
|
|
|
print_playlist_result(Client &client, PlaylistResult result)
|
2012-08-07 22:26:14 +02:00
|
|
|
{
|
|
|
|
switch (result) {
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::SUCCESS:
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::ERRNO:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_SYSTEM, "%s",
|
2013-12-15 18:30:25 +01:00
|
|
|
strerror(errno));
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::DENIED:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_PERMISSION, "Access denied");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::NO_SUCH_SONG:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such song");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::NO_SUCH_LIST:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::LIST_EXISTS:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_EXIST,
|
|
|
|
"Playlist already exists");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::BAD_NAME:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"playlist name is invalid: "
|
|
|
|
"playlist names may not contain slashes,"
|
|
|
|
" newlines or carriage returns");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::BAD_RANGE:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "Bad song index");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::NOT_PLAYING:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::TOO_LARGE:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_PLAYLIST_MAX,
|
|
|
|
"playlist is at the max size");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-10-19 19:50:54 +02:00
|
|
|
case PlaylistResult::DISABLED:
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"stored playlist support is disabled");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
print_error(Client &client, const Error &error)
|
2012-08-07 22:26:14 +02:00
|
|
|
{
|
2013-08-10 18:02:44 +02:00
|
|
|
assert(error.IsDefined());
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-09-27 22:31:24 +02:00
|
|
|
LogError(error);
|
2012-08-07 22:26:14 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
if (error.IsDomain(playlist_domain)) {
|
|
|
|
return print_playlist_result(client,
|
2013-10-19 19:50:54 +02:00
|
|
|
PlaylistResult(error.GetCode()));
|
2013-08-10 18:02:44 +02:00
|
|
|
} else if (error.IsDomain(ack_domain)) {
|
|
|
|
command_error(client, (ack)error.GetCode(),
|
|
|
|
"%s", error.GetMessage());
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2013-08-10 18:02:44 +02:00
|
|
|
} else if (error.IsDomain(db_domain)) {
|
|
|
|
switch ((enum db_error)error.GetCode()) {
|
2012-08-07 22:26:14 +02:00
|
|
|
case DB_DISABLED:
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "%s",
|
2013-08-10 18:02:44 +02:00
|
|
|
error.GetMessage());
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
|
|
|
|
case DB_NOT_FOUND:
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "Not found");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
2013-08-10 18:02:44 +02:00
|
|
|
} else if (error.IsDomain(errno_domain)) {
|
2012-08-07 22:26:14 +02:00
|
|
|
command_error(client, ACK_ERROR_SYSTEM, "%s",
|
2013-12-15 18:30:25 +01:00
|
|
|
strerror(error.GetCode()));
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN, "error");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|