2012-08-07 22:26:14 +02:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 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"
|
2015-10-22 09:29:02 +02:00
|
|
|
#include "LocateUri.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "client/Response.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
|
2015-08-06 22:10:25 +02:00
|
|
|
print_playlist_result(Response &r, 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::DENIED:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(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
|
2015-08-06 22:10:25 +02:00
|
|
|
print_error(Response &r, 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)) {
|
2015-08-06 22:10:25 +02:00
|
|
|
return print_playlist_result(r,
|
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)) {
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error((ack)error.GetCode(), error.GetMessage());
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2014-01-30 20:29:48 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_NO_EXIST, 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:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_NO_EXIST, "Not found");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2014-02-26 08:39:44 +01:00
|
|
|
|
|
|
|
case DB_CONFLICT:
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_ARG, "Conflict");
|
2014-02-26 08:39:44 +01:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
2014-01-30 20:29:48 +01:00
|
|
|
#endif
|
2015-10-22 09:29:02 +02:00
|
|
|
} else if (error.IsDomain(locate_uri_domain)) {
|
|
|
|
r.Error(ACK_ERROR_ARG, error.GetMessage());
|
|
|
|
return CommandResult::ERROR;
|
2013-08-10 18:02:44 +02:00
|
|
|
} else if (error.IsDomain(errno_domain)) {
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_SYSTEM, strerror(error.GetCode()));
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_UNKNOWN, "error");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 22:26:14 +02:00
|
|
|
}
|