2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "command.h"
|
2012-02-14 19:13:04 +01:00
|
|
|
#include "protocol/argparser.h"
|
2012-02-14 18:46:30 +01:00
|
|
|
#include "protocol/result.h"
|
2008-08-26 08:44:38 +02:00
|
|
|
#include "player_control.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "playlist.h"
|
2009-01-23 16:34:27 +01:00
|
|
|
#include "playlist_print.h"
|
2009-01-25 14:11:47 +01:00
|
|
|
#include "playlist_save.h"
|
2009-10-13 18:53:33 +02:00
|
|
|
#include "playlist_queue.h"
|
2011-09-11 07:41:25 +02:00
|
|
|
#include "playlist_error.h"
|
2009-01-24 14:52:04 +01:00
|
|
|
#include "queue_print.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "ls.h"
|
2009-02-25 16:44:06 +01:00
|
|
|
#include "uri.h"
|
2009-11-07 15:57:22 +01:00
|
|
|
#include "decoder_print.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "directory.h"
|
2008-10-08 11:07:35 +02:00
|
|
|
#include "database.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
#include "update.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "volume.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "permission.h"
|
2009-07-19 15:15:36 +02:00
|
|
|
#include "tokenizer.h"
|
2008-10-22 17:21:57 +02:00
|
|
|
#include "stored_playlist.h"
|
2008-04-12 06:19:26 +02:00
|
|
|
#include "ack.h"
|
2009-02-11 18:02:45 +01:00
|
|
|
#include "output_command.h"
|
2009-02-10 18:51:42 +01:00
|
|
|
#include "output_print.h"
|
2009-01-24 14:52:05 +01:00
|
|
|
#include "locate.h"
|
2008-08-28 20:01:08 +02:00
|
|
|
#include "dbUtils.h"
|
2011-09-10 19:24:30 +02:00
|
|
|
#include "db_error.h"
|
2011-09-05 23:09:20 +02:00
|
|
|
#include "db_print.h"
|
2011-09-13 21:24:22 +02:00
|
|
|
#include "db_selection.h"
|
2012-01-31 22:12:14 +01:00
|
|
|
#include "db_lock.h"
|
2008-09-06 20:28:31 +02:00
|
|
|
#include "tag.h"
|
2008-08-29 09:36:42 +02:00
|
|
|
#include "client.h"
|
2011-01-29 10:24:30 +01:00
|
|
|
#include "client_idle.h"
|
2009-11-03 21:08:48 +01:00
|
|
|
#include "client_internal.h"
|
2011-01-29 09:26:22 +01:00
|
|
|
#include "client_subscribe.h"
|
2012-03-06 22:01:24 +01:00
|
|
|
#include "client_file.h"
|
2008-09-07 13:28:01 +02:00
|
|
|
#include "tag_print.h"
|
2008-10-06 18:32:27 +02:00
|
|
|
#include "path.h"
|
2010-01-04 20:58:17 +01:00
|
|
|
#include "replay_gain_config.h"
|
2008-11-22 13:26:21 +01:00
|
|
|
#include "idle.h"
|
2012-02-13 19:59:41 +01:00
|
|
|
#include "mapper.h"
|
2012-03-06 21:35:05 +01:00
|
|
|
#include "song.h"
|
|
|
|
#include "song_print.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
#ifdef ENABLE_SQLITE
|
|
|
|
#include "sticker.h"
|
2009-04-01 17:30:56 +02:00
|
|
|
#include "sticker_print.h"
|
2009-01-19 19:09:49 +01:00
|
|
|
#include "song_sticker.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <time.h>
|
2009-01-03 14:52:56 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#define COMMAND_STATUS_STATE "state"
|
|
|
|
#define COMMAND_STATUS_REPEAT "repeat"
|
2009-03-30 00:01:02 +02:00
|
|
|
#define COMMAND_STATUS_SINGLE "single"
|
|
|
|
#define COMMAND_STATUS_CONSUME "consume"
|
2004-02-24 00:41:20 +01:00
|
|
|
#define COMMAND_STATUS_RANDOM "random"
|
|
|
|
#define COMMAND_STATUS_PLAYLIST "playlist"
|
|
|
|
#define COMMAND_STATUS_PLAYLIST_LENGTH "playlistlength"
|
|
|
|
#define COMMAND_STATUS_SONG "song"
|
2004-06-09 04:50:44 +02:00
|
|
|
#define COMMAND_STATUS_SONGID "songid"
|
2009-02-08 06:21:00 +01:00
|
|
|
#define COMMAND_STATUS_NEXTSONG "nextsong"
|
|
|
|
#define COMMAND_STATUS_NEXTSONGID "nextsongid"
|
2004-02-24 00:41:20 +01:00
|
|
|
#define COMMAND_STATUS_TIME "time"
|
|
|
|
#define COMMAND_STATUS_BITRATE "bitrate"
|
|
|
|
#define COMMAND_STATUS_ERROR "error"
|
2004-02-27 02:35:23 +01:00
|
|
|
#define COMMAND_STATUS_CROSSFADE "xfade"
|
2010-03-21 18:21:47 +01:00
|
|
|
#define COMMAND_STATUS_MIXRAMPDB "mixrampdb"
|
|
|
|
#define COMMAND_STATUS_MIXRAMPDELAY "mixrampdelay"
|
2004-02-27 02:35:23 +01:00
|
|
|
#define COMMAND_STATUS_AUDIO "audio"
|
2004-04-11 04:34:26 +02:00
|
|
|
#define COMMAND_STATUS_UPDATING_DB "updating_db"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-10-06 12:33:27 +02:00
|
|
|
/*
|
|
|
|
* The most we ever use is for search/find, and that limits it to the
|
|
|
|
* number of tags we can have. Add one for the command, and one extra
|
|
|
|
* to catch errors clients may send us
|
|
|
|
*/
|
|
|
|
#define COMMAND_ARGV_MAX (2+(TAG_NUM_OF_ITEM_TYPES*2))
|
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
/* if min: -1 don't check args *
|
|
|
|
* if max: -1 no max args */
|
2008-10-22 09:58:13 +02:00
|
|
|
struct command {
|
2008-02-05 11:17:33 +01:00
|
|
|
const char *cmd;
|
2008-10-22 21:40:44 +02:00
|
|
|
unsigned permission;
|
2006-07-20 18:02:40 +02:00
|
|
|
int min;
|
|
|
|
int max;
|
2008-10-22 21:41:49 +02:00
|
|
|
enum command_return (*handler)(struct client *client, int argc, char **argv);
|
2004-04-11 19:37:47 +02:00
|
|
|
};
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
|
|
|
print_playlist_result(struct client *client,
|
|
|
|
enum playlist_result result)
|
2008-09-07 13:39:31 +02:00
|
|
|
{
|
|
|
|
switch (result) {
|
|
|
|
case PLAYLIST_RESULT_SUCCESS:
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_ERRNO:
|
2012-03-06 22:06:08 +01:00
|
|
|
command_error(client, ACK_ERROR_SYSTEM, "%s",
|
|
|
|
g_strerror(errno));
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2008-10-15 22:35:13 +02:00
|
|
|
case PLAYLIST_RESULT_DENIED:
|
2012-03-06 21:35:30 +01:00
|
|
|
command_error(client, ACK_ERROR_PERMISSION, "Access denied");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-15 22:35:13 +02:00
|
|
|
|
2008-09-07 13:39:31 +02:00
|
|
|
case PLAYLIST_RESULT_NO_SUCH_SONG:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such song");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_NO_SUCH_LIST:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_LIST_EXISTS:
|
2008-10-09 11:51:22 +02:00
|
|
|
command_error(client, ACK_ERROR_EXIST,
|
2008-09-07 13:52:48 +02:00
|
|
|
"Playlist already exists");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_BAD_NAME:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"playlist name is invalid: "
|
|
|
|
"playlist names may not contain slashes,"
|
|
|
|
" newlines or carriage returns");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_BAD_RANGE:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "Bad song index");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_NOT_PLAYING:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_TOO_LARGE:
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_PLAYLIST_MAX,
|
|
|
|
"playlist is at the max size");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-01-18 16:15:45 +01:00
|
|
|
|
|
|
|
case PLAYLIST_RESULT_DISABLED:
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"stored playlist support is disabled");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
}
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
/**
|
|
|
|
* Send the GError to the client and free the GError.
|
|
|
|
*/
|
|
|
|
static enum command_return
|
|
|
|
print_error(struct client *client, GError *error)
|
|
|
|
{
|
|
|
|
assert(client != NULL);
|
|
|
|
assert(error != NULL);
|
|
|
|
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
|
|
|
|
if (error->domain == playlist_quark()) {
|
|
|
|
enum playlist_result result = error->code;
|
|
|
|
g_error_free(error);
|
|
|
|
return print_playlist_result(client, result);
|
2012-03-06 22:08:54 +01:00
|
|
|
} else if (error->domain == ack_quark()) {
|
|
|
|
command_error(client, error->code, "%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2011-09-10 19:24:30 +02:00
|
|
|
} else if (error->domain == db_quark()) {
|
|
|
|
switch ((enum db_error)error->code) {
|
2011-09-13 20:54:27 +02:00
|
|
|
case DB_DISABLED:
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "%s",
|
|
|
|
error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
case DB_NOT_FOUND:
|
|
|
|
g_error_free(error);
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "Not found");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2011-09-11 07:41:25 +02:00
|
|
|
} else if (error->domain == g_file_error_quark()) {
|
|
|
|
command_error(client, ACK_ERROR_SYSTEM, "%s",
|
|
|
|
g_strerror(error->code));
|
|
|
|
g_error_free(error);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_error_free(error);
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN, "error");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-10-22 19:16:35 +02:00
|
|
|
static void
|
|
|
|
print_spl_list(struct client *client, GPtrArray *list)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < list->len; ++i) {
|
|
|
|
struct stored_playlist_info *playlist =
|
|
|
|
g_ptr_array_index(list, i);
|
2008-10-22 19:18:39 +02:00
|
|
|
time_t t;
|
2008-12-29 17:28:13 +01:00
|
|
|
#ifndef WIN32
|
2008-10-22 19:18:39 +02:00
|
|
|
struct tm tm;
|
2008-12-29 17:28:13 +01:00
|
|
|
#endif
|
2008-10-22 19:18:39 +02:00
|
|
|
char timestamp[32];
|
2008-10-22 19:16:35 +02:00
|
|
|
|
|
|
|
client_printf(client, "playlist: %s\n", playlist->name);
|
2008-10-22 19:18:39 +02:00
|
|
|
|
|
|
|
t = playlist->mtime;
|
2010-05-18 23:54:03 +02:00
|
|
|
strftime(timestamp, sizeof(timestamp),
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
"%Y-%m-%dT%H:%M:%SZ",
|
2008-12-29 17:28:13 +01:00
|
|
|
gmtime(&t)
|
|
|
|
#else
|
2010-05-18 23:54:03 +02:00
|
|
|
"%FT%TZ",
|
2008-12-29 17:28:13 +01:00
|
|
|
gmtime_r(&t, &tm)
|
|
|
|
#endif
|
|
|
|
);
|
2008-10-22 19:18:39 +02:00
|
|
|
client_printf(client, "Last-Modified: %s\n", timestamp);
|
2008-10-22 19:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_urlhandlers(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-06-03 01:22:37 +02:00
|
|
|
{
|
2012-02-13 20:00:33 +01:00
|
|
|
if (client_is_local(client))
|
2008-10-17 17:53:43 +02:00
|
|
|
client_puts(client, "handler: file://\n");
|
2009-01-04 17:46:42 +01:00
|
|
|
print_supported_uri_schemes(client);
|
2008-12-16 21:18:31 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-06-03 01:22:37 +02:00
|
|
|
}
|
|
|
|
|
2009-11-07 15:57:22 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_decoders(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
decoder_list_print(client);
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_tagtypes(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2007-03-31 20:43:16 +02:00
|
|
|
{
|
2008-09-07 13:53:55 +02:00
|
|
|
tag_print_types(client);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2007-03-31 20:43:16 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_play(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int song = -1;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (argc == 2 && !check_int(client, &song, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_play(&g_playlist, client->player_control, song);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playid(struct client *client, int argc, char *argv[])
|
2004-06-09 04:50:44 +02:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int id = -1;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (argc == 2 && !check_int(client, &id, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-01-26 13:46:53 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_play_id(&g_playlist, client->player_control, id);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2004-06-09 04:50:44 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_stop(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_stop(&g_playlist, client->player_control);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_currentsong(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-06-10 06:13:23 +02:00
|
|
|
{
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_current(client, &g_playlist);
|
2011-03-23 22:16:46 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-06-10 06:13:23 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_pause(struct client *client,
|
|
|
|
int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2006-07-29 20:54:56 +02:00
|
|
|
if (argc == 2) {
|
2008-10-23 09:53:35 +02:00
|
|
|
bool pause_flag;
|
|
|
|
if (!check_bool(client, &pause_flag, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-08-26 08:27:16 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_set_pause(client->player_control, pause_flag);
|
2009-10-08 21:12:57 +02:00
|
|
|
} else
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_pause(client->player_control);
|
2009-10-08 21:12:57 +02:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_status(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2008-02-05 11:17:33 +01:00
|
|
|
const char *state = NULL;
|
2009-10-08 20:48:07 +02:00
|
|
|
struct player_status player_status;
|
2004-04-11 05:12:00 +02:00
|
|
|
int updateJobId;
|
2009-10-08 20:45:38 +02:00
|
|
|
char *error;
|
2006-07-20 18:02:40 +02:00
|
|
|
int song;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_get_status(client->player_control, &player_status);
|
2009-10-08 20:48:07 +02:00
|
|
|
|
|
|
|
switch (player_status.state) {
|
2006-07-20 18:02:40 +02:00
|
|
|
case PLAYER_STATE_STOP:
|
2008-10-22 10:08:14 +02:00
|
|
|
state = "stop";
|
2006-07-20 18:02:40 +02:00
|
|
|
break;
|
|
|
|
case PLAYER_STATE_PAUSE:
|
2008-10-22 10:08:14 +02:00
|
|
|
state = "pause";
|
2006-07-20 18:02:40 +02:00
|
|
|
break;
|
|
|
|
case PLAYER_STATE_PLAY:
|
2008-10-22 10:08:14 +02:00
|
|
|
state = "play";
|
2006-07-20 18:02:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
client_printf(client,
|
2009-07-06 21:51:00 +02:00
|
|
|
"volume: %i\n"
|
2008-09-07 13:57:43 +02:00
|
|
|
COMMAND_STATUS_REPEAT ": %i\n"
|
|
|
|
COMMAND_STATUS_RANDOM ": %i\n"
|
2009-03-27 15:28:49 +01:00
|
|
|
COMMAND_STATUS_SINGLE ": %i\n"
|
2009-03-30 00:01:02 +02:00
|
|
|
COMMAND_STATUS_CONSUME ": %i\n"
|
2008-09-07 13:57:43 +02:00
|
|
|
COMMAND_STATUS_PLAYLIST ": %li\n"
|
|
|
|
COMMAND_STATUS_PLAYLIST_LENGTH ": %i\n"
|
|
|
|
COMMAND_STATUS_CROSSFADE ": %i\n"
|
2010-03-21 18:21:47 +01:00
|
|
|
COMMAND_STATUS_MIXRAMPDB ": %f\n"
|
|
|
|
COMMAND_STATUS_MIXRAMPDELAY ": %f\n"
|
2008-09-07 13:57:43 +02:00
|
|
|
COMMAND_STATUS_STATE ": %s\n",
|
2008-12-31 16:46:41 +01:00
|
|
|
volume_level_get(),
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_get_repeat(&g_playlist),
|
|
|
|
playlist_get_random(&g_playlist),
|
|
|
|
playlist_get_single(&g_playlist),
|
|
|
|
playlist_get_consume(&g_playlist),
|
|
|
|
playlist_get_version(&g_playlist),
|
|
|
|
playlist_get_length(&g_playlist),
|
2009-11-03 21:08:48 +01:00
|
|
|
(int)(pc_get_cross_fade(client->player_control) + 0.5),
|
|
|
|
pc_get_mixramp_db(client->player_control),
|
|
|
|
pc_get_mixramp_delay(client->player_control),
|
2008-09-07 13:57:43 +02:00
|
|
|
state);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
song = playlist_get_current_song(&g_playlist);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (song >= 0) {
|
2008-09-07 13:57:43 +02:00
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_SONG ": %i\n"
|
2008-10-23 07:19:46 +02:00
|
|
|
COMMAND_STATUS_SONGID ": %u\n",
|
2009-07-29 00:07:01 +02:00
|
|
|
song, playlist_get_song_id(&g_playlist, song));
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2008-10-10 14:51:22 +02:00
|
|
|
|
2009-10-08 20:48:07 +02:00
|
|
|
if (player_status.state != PLAYER_STATE_STOP) {
|
2009-11-10 17:57:14 +01:00
|
|
|
struct audio_format_string af_string;
|
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
client_printf(client,
|
2008-09-07 13:57:43 +02:00
|
|
|
COMMAND_STATUS_TIME ": %i:%i\n"
|
2009-06-25 08:37:34 +02:00
|
|
|
"elapsed: %1.3f\n"
|
2009-10-08 20:48:07 +02:00
|
|
|
COMMAND_STATUS_BITRATE ": %u\n"
|
2009-11-10 17:57:14 +01:00
|
|
|
COMMAND_STATUS_AUDIO ": %s\n",
|
2009-10-08 20:48:07 +02:00
|
|
|
(int)(player_status.elapsed_time + 0.5),
|
|
|
|
(int)(player_status.total_time + 0.5),
|
|
|
|
player_status.elapsed_time,
|
|
|
|
player_status.bit_rate,
|
2009-11-10 17:57:14 +01:00
|
|
|
audio_format_to_string(&player_status.audio_format,
|
|
|
|
&af_string));
|
2004-06-09 04:50:44 +02:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if ((updateJobId = isUpdatingDB())) {
|
2008-09-07 13:57:43 +02:00
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_UPDATING_DB ": %i\n",
|
|
|
|
updateJobId);
|
2004-04-11 05:12:00 +02:00
|
|
|
}
|
2004-04-11 04:34:26 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
error = pc_get_error_message(client->player_control);
|
2009-10-08 20:45:38 +02:00
|
|
|
if (error != NULL) {
|
2008-09-07 13:57:43 +02:00
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_ERROR ": %s\n",
|
2009-10-08 20:45:38 +02:00
|
|
|
error);
|
|
|
|
g_free(error);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
song = playlist_get_next_song(&g_playlist);
|
2009-02-08 06:21:00 +01:00
|
|
|
if (song >= 0) {
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_NEXTSONG ": %i\n"
|
|
|
|
COMMAND_STATUS_NEXTSONGID ": %u\n",
|
2009-07-29 00:07:01 +02:00
|
|
|
song, playlist_get_song_id(&g_playlist, song));
|
2009-02-08 06:21:00 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_kill(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
return COMMAND_RETURN_KILL;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_close(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
return COMMAND_RETURN_CLOSE;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_add(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-04 16:19:45 +01:00
|
|
|
char *uri = argv[1];
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2005-05-03 04:35:19 +02:00
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
if (strncmp(uri, "file:///", 8) == 0) {
|
2012-03-06 22:01:24 +01:00
|
|
|
const char *path = uri + 7;
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
if (!client_allow_file(client, path, &error))
|
|
|
|
return print_error(client, error);
|
|
|
|
|
2009-02-04 18:56:41 +01:00
|
|
|
result = playlist_append_file(&g_playlist,
|
2009-11-03 21:08:48 +01:00
|
|
|
client->player_control,
|
2012-03-06 22:01:24 +01:00
|
|
|
path,
|
2008-10-15 22:35:13 +02:00
|
|
|
NULL);
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
if (uri_has_scheme(uri)) {
|
2009-01-04 17:46:42 +01:00
|
|
|
if (!uri_supported_scheme(uri)) {
|
2009-01-04 16:22:08 +01:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"unsupported URI scheme");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_append_uri(&g_playlist,
|
|
|
|
client->player_control,
|
|
|
|
uri, NULL);
|
2009-03-14 14:33:19 +01:00
|
|
|
return print_playlist_result(client, result);
|
2008-12-16 21:23:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return addAllIn(client->player_control, uri, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_addid(struct client *client, int argc, char *argv[])
|
2004-11-03 00:44:33 +01:00
|
|
|
{
|
2009-01-04 16:19:45 +01:00
|
|
|
char *uri = argv[1];
|
2008-10-23 07:19:46 +02:00
|
|
|
unsigned added_id;
|
2008-10-15 22:35:13 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
if (strncmp(uri, "file:///", 8) == 0) {
|
2012-03-06 22:01:24 +01:00
|
|
|
const char *path = uri + 7;
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
if (!client_allow_file(client, path, &error))
|
|
|
|
return print_error(client, error);
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_append_file(&g_playlist,
|
|
|
|
client->player_control,
|
2012-03-06 22:01:24 +01:00
|
|
|
path,
|
2008-10-15 22:35:13 +02:00
|
|
|
&added_id);
|
2009-01-04 16:22:08 +01:00
|
|
|
} else {
|
2009-01-04 17:46:42 +01:00
|
|
|
if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) {
|
2009-01-04 16:22:08 +01:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"unsupported URI scheme");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_append_uri(&g_playlist,
|
|
|
|
client->player_control,
|
|
|
|
uri, &added_id);
|
2009-01-04 16:22:08 +01:00
|
|
|
}
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2008-09-23 23:59:55 +02:00
|
|
|
if (result != PLAYLIST_RESULT_SUCCESS)
|
2008-10-15 22:35:04 +02:00
|
|
|
return print_playlist_result(client, result);
|
2008-09-07 13:39:31 +02:00
|
|
|
|
|
|
|
if (argc == 3) {
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned to;
|
|
|
|
if (!check_unsigned(client, &to, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_move_id(&g_playlist, client->player_control,
|
|
|
|
added_id, to);
|
2008-09-07 13:39:31 +02:00
|
|
|
if (result != PLAYLIST_RESULT_SUCCESS) {
|
2008-10-22 21:41:49 +02:00
|
|
|
enum command_return ret =
|
|
|
|
print_playlist_result(client, result);
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_id(&g_playlist, client->player_control,
|
|
|
|
added_id);
|
2008-09-07 13:39:31 +02:00
|
|
|
return ret;
|
2008-01-26 13:46:56 +01:00
|
|
|
}
|
|
|
|
}
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2008-10-23 07:19:46 +02:00
|
|
|
client_printf(client, "Id: %u\n", added_id);
|
2009-03-14 14:36:07 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-11-03 00:44:33 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_delete(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-09-30 23:13:13 +02:00
|
|
|
unsigned start, end;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_range(client, &start, &end, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_delete_range(&g_playlist, client->player_control,
|
|
|
|
start, end);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_deleteid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-06-09 04:50:44 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned id;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &id, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_delete_id(&g_playlist, client->player_control, id);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2004-06-09 04:50:44 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlist(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_uris(client, &g_playlist);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_shuffle(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-02-13 10:38:32 +01:00
|
|
|
unsigned start = 0, end = queue_length(&g_playlist.queue);
|
2012-02-14 18:59:03 +01:00
|
|
|
if (argc == 2 && !check_range(client, &start, &end, argv[1]))
|
2009-02-13 10:38:32 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_shuffle(&g_playlist, client->player_control, start, end);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_clear(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_clear(&g_playlist, client->player_control);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_save(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2009-02-04 22:15:37 +01:00
|
|
|
result = spl_save_playlist(argv[1], &g_playlist);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2012-02-09 23:52:51 +01:00
|
|
|
handle_load(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2012-02-09 23:52:51 +01:00
|
|
|
unsigned start_index, end_index;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
start_index = 0;
|
|
|
|
end_index = G_MAXUINT;
|
2012-02-14 18:59:03 +01:00
|
|
|
} else if (!check_range(client, &start_index, &end_index, argv[2]))
|
2012-02-09 23:52:51 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2012-02-09 23:44:33 +01:00
|
|
|
result = playlist_open_into_queue(argv[1],
|
2012-02-09 23:52:51 +01:00
|
|
|
start_index, end_index,
|
2012-02-09 23:44:33 +01:00
|
|
|
&g_playlist,
|
2009-11-03 21:08:48 +01:00
|
|
|
client->player_control, true);
|
2009-10-13 18:53:33 +02:00
|
|
|
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
|
2011-03-18 19:45:59 +01:00
|
|
|
return print_playlist_result(client, result);
|
2009-10-13 18:53:33 +02:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
2012-02-13 19:51:27 +01:00
|
|
|
if (playlist_load_spl(&g_playlist, client->player_control,
|
|
|
|
argv[1], start_index, end_index,
|
|
|
|
&error))
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
|
|
|
|
if (error->domain == playlist_quark() &&
|
|
|
|
error->code == PLAYLIST_RESULT_BAD_NAME)
|
|
|
|
/* the message for BAD_NAME is confusing when the
|
|
|
|
client wants to load a playlist file from the music
|
|
|
|
directory; patch the GError object to show "no such
|
|
|
|
playlist" instead */
|
|
|
|
error->code = PLAYLIST_RESULT_NO_SUCH_LIST;
|
|
|
|
|
|
|
|
return print_error(client, error);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2006-07-14 20:47:55 +02:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_listplaylist(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-03-26 15:46:05 +02:00
|
|
|
{
|
2010-02-08 10:19:43 +01:00
|
|
|
if (playlist_file_print(client, argv[1], false))
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_print(client, argv[1], false, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2006-03-26 15:46:05 +02:00
|
|
|
}
|
2006-07-14 20:47:55 +02:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_listplaylistinfo(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, char *argv[])
|
2006-03-26 15:46:05 +02:00
|
|
|
{
|
2010-02-08 10:19:43 +01:00
|
|
|
if (playlist_file_print(client, argv[1], true))
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_print(client, argv[1], true, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2006-03-26 15:46:05 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_lsinfo(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-04 16:19:45 +01:00
|
|
|
const char *uri;
|
2007-05-24 19:06:59 +02:00
|
|
|
|
|
|
|
if (argc == 2)
|
2009-01-04 16:19:45 +01:00
|
|
|
uri = argv[1];
|
|
|
|
else
|
|
|
|
/* default is root directory */
|
|
|
|
uri = "";
|
2007-05-24 19:06:59 +02:00
|
|
|
|
2012-03-06 21:35:05 +01:00
|
|
|
if (strncmp(uri, "file:///", 8) == 0) {
|
|
|
|
/* print information about an arbitrary local file */
|
|
|
|
const char *path = uri + 7;
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
if (!client_allow_file(client, path, &error))
|
|
|
|
return print_error(client, error);
|
|
|
|
|
|
|
|
struct song *song = song_file_load(path, NULL);
|
|
|
|
if (song == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"No such file");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
song_print_info(client, song);
|
|
|
|
song_free(song);
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-13 21:24:22 +02:00
|
|
|
struct db_selection selection;
|
|
|
|
db_selection_init(&selection, uri, false);
|
2007-05-24 19:06:59 +02:00
|
|
|
|
2011-09-13 21:24:22 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
if (!db_selection_print(client, &selection, true, &error))
|
|
|
|
return print_error(client, error);
|
2008-10-08 11:07:39 +02:00
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
if (isRootDirectory(uri)) {
|
2011-09-11 07:41:25 +02:00
|
|
|
GPtrArray *list = spl_list(NULL);
|
2008-10-22 19:16:35 +02:00
|
|
|
if (list != NULL) {
|
|
|
|
print_spl_list(client, list);
|
|
|
|
spl_list_free(list);
|
|
|
|
}
|
|
|
|
}
|
2007-05-24 19:06:59 +02:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_rm(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_delete(argv[1], &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_rename(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2007-05-24 20:07:19 +02:00
|
|
|
{
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_rename(argv[1], argv[2], &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2007-05-24 20:07:19 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-06-05 03:14:37 +02:00
|
|
|
{
|
2008-09-29 15:49:29 +02:00
|
|
|
uint32_t version;
|
2004-06-05 03:14:37 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_uint32(client, &version, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-01-24 14:52:04 +01:00
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_changes_info(client, &g_playlist, version);
|
2009-01-24 14:52:04 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-06-05 03:14:37 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-04-23 13:10:41 +02:00
|
|
|
{
|
2008-09-29 15:49:29 +02:00
|
|
|
uint32_t version;
|
2006-04-23 13:10:41 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_uint32(client, &version, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-01-24 14:52:04 +01:00
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_changes_position(client, &g_playlist, version);
|
2009-01-24 14:52:04 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2006-04-23 13:10:41 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlistinfo(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-10-18 01:24:45 +02:00
|
|
|
unsigned start = 0, end = G_MAXUINT;
|
2009-02-04 22:09:04 +01:00
|
|
|
bool ret;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (argc == 2 && !check_range(client, &start, &end, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
ret = playlist_print_info(client, &g_playlist, start, end);
|
|
|
|
if (!ret)
|
2009-01-24 14:52:04 +01:00
|
|
|
return print_playlist_result(client,
|
|
|
|
PLAYLIST_RESULT_BAD_RANGE);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlistid(struct client *client, int argc, char *argv[])
|
2004-06-09 04:50:44 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
if (argc >= 2) {
|
|
|
|
unsigned id;
|
|
|
|
if (!check_unsigned(client, &id, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
bool ret = playlist_print_id(client, &g_playlist, id);
|
|
|
|
if (!ret)
|
2009-01-24 14:52:04 +01:00
|
|
|
return print_playlist_result(client,
|
|
|
|
PLAYLIST_RESULT_NO_SUCH_SONG);
|
|
|
|
} else {
|
2009-10-18 01:24:45 +02:00
|
|
|
playlist_print_info(client, &g_playlist, 0, G_MAXUINT);
|
2009-01-24 14:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
2004-06-09 04:50:44 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_find(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
2011-09-13 21:36:51 +02:00
|
|
|
enum command_return ret = findSongsIn(client, "", list, &error)
|
2011-09-10 19:24:30 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(list);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return ret;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-08-25 13:43:22 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_findadd(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
2011-09-13 21:36:51 +02:00
|
|
|
findAddIn(client->player_control, "", list, &error)
|
2011-09-10 19:24:30 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2009-08-25 13:43:22 +02:00
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_search(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
2011-09-13 21:36:51 +02:00
|
|
|
enum command_return ret = searchForSongsIn(client, "", list, &error)
|
2011-09-10 19:24:30 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(list);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return ret;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 09:26:00 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_searchadd(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret = search_add_songs(client->player_control,
|
|
|
|
"", list, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-27 09:26:03 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_searchaddpl(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *playlist = argv[1];
|
|
|
|
|
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 2, argc - 2);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
|
|
|
search_add_to_playlist("", playlist, list, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_count(struct client *client, int argc, char *argv[])
|
2007-04-26 01:46:11 +02:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
2007-04-26 01:46:11 +02:00
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-04-26 01:46:11 +02:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
2011-09-13 21:36:51 +02:00
|
|
|
searchStatsForSongsIn(client, "", list, &error)
|
2011-09-10 19:24:30 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2007-04-26 01:46:11 +02:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(list);
|
2007-04-26 01:46:11 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlistfind(struct client *client, int argc, char *argv[])
|
2007-02-24 03:00:03 +01:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-02-24 03:00:03 +01:00
|
|
|
}
|
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_find(client, &g_playlist, list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2007-02-24 03:00:03 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlistsearch(struct client *client, int argc, char *argv[])
|
2007-02-24 03:00:03 +01:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *list =
|
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
if (list == NULL || list->length == 0) {
|
|
|
|
if (list != NULL)
|
|
|
|
locate_item_list_free(list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-02-24 03:00:03 +01:00
|
|
|
}
|
|
|
|
|
2009-02-04 22:09:04 +01:00
|
|
|
playlist_print_search(client, &g_playlist, list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(list);
|
2007-02-24 03:00:03 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2007-02-24 03:00:03 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_playlistdelete(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, char *argv[]) {
|
2007-05-16 14:02:10 +02:00
|
|
|
char *playlist = argv[1];
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned from;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &from, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_remove_index(playlist, from, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2007-05-16 14:02:10 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_playlistmove(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2007-05-16 14:02:10 +02:00
|
|
|
{
|
|
|
|
char *playlist = argv[1];
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned from, to;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &from, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &to, argv[3]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_move_index(playlist, from, to, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2007-05-16 14:02:10 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_update(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-09-24 21:39:43 +02:00
|
|
|
const char *path = NULL;
|
2008-10-09 19:20:05 +02:00
|
|
|
unsigned ret;
|
2008-09-07 13:50:06 +02:00
|
|
|
|
2008-10-06 18:32:27 +02:00
|
|
|
assert(argc <= 2);
|
2010-02-27 19:01:17 +01:00
|
|
|
if (argc == 2) {
|
2009-09-24 21:39:43 +02:00
|
|
|
path = argv[1];
|
2008-10-09 19:17:44 +02:00
|
|
|
|
2010-03-12 17:58:16 +01:00
|
|
|
if (*path == 0 || strcmp(path, "/") == 0)
|
|
|
|
/* backwards compatibility with MPD 0.15 */
|
|
|
|
path = NULL;
|
|
|
|
else if (!uri_safe_local(path)) {
|
2010-02-27 19:01:17 +01:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Malformed path");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 21:55:40 +02:00
|
|
|
ret = update_enqueue(path, false);
|
|
|
|
if (ret > 0) {
|
|
|
|
client_printf(client, "updating_db: %i\n", ret);
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
} else {
|
|
|
|
command_error(client, ACK_ERROR_UPDATE_ALREADY,
|
|
|
|
"already updating");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_rescan(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *path = NULL;
|
|
|
|
unsigned ret;
|
|
|
|
|
|
|
|
assert(argc <= 2);
|
2010-02-27 19:01:17 +01:00
|
|
|
if (argc == 2) {
|
2009-09-24 21:55:40 +02:00
|
|
|
path = argv[1];
|
|
|
|
|
2010-02-27 19:01:17 +01:00
|
|
|
if (!uri_safe_local(path)) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Malformed path");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 21:55:40 +02:00
|
|
|
ret = update_enqueue(path, true);
|
2008-10-09 19:17:44 +02:00
|
|
|
if (ret > 0) {
|
|
|
|
client_printf(client, "updating_db: %i\n", ret);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2008-10-09 19:17:44 +02:00
|
|
|
} else {
|
|
|
|
command_error(client, ACK_ERROR_UPDATE_ALREADY,
|
|
|
|
"already updating");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-09 19:17:44 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_next(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-03-31 14:05:11 +02:00
|
|
|
/* single mode is not considered when this is user who
|
|
|
|
* wants to change song. */
|
|
|
|
int single = g_playlist.queue.single;
|
|
|
|
g_playlist.queue.single = false;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_next(&g_playlist, client->player_control);
|
2009-03-31 14:05:11 +02:00
|
|
|
|
|
|
|
g_playlist.queue.single = single;
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_previous(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_previous(&g_playlist, client->player_control);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2011-07-19 00:34:33 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_prio(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
unsigned priority;
|
|
|
|
|
|
|
|
if (!check_unsigned(client, &priority, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
if (priority > 0xff) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Priority out of range: %s", argv[1]);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 2; i < argc; ++i) {
|
|
|
|
unsigned start_position, end_position;
|
|
|
|
if (!check_range(client, &start_position, &end_position,
|
2012-02-14 18:59:03 +01:00
|
|
|
argv[i]))
|
2011-07-19 00:34:33 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
enum playlist_result result =
|
|
|
|
playlist_set_priority(&g_playlist,
|
|
|
|
client->player_control,
|
|
|
|
start_position, end_position,
|
|
|
|
priority);
|
|
|
|
if (result != PLAYLIST_RESULT_SUCCESS)
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_prioid(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
unsigned priority;
|
|
|
|
|
|
|
|
if (!check_unsigned(client, &priority, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
if (priority > 0xff) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Priority out of range: %s", argv[1]);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 2; i < argc; ++i) {
|
|
|
|
unsigned song_id;
|
|
|
|
if (!check_unsigned(client, &song_id, argv[i]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
enum playlist_result result =
|
|
|
|
playlist_set_priority_id(&g_playlist,
|
|
|
|
client->player_control,
|
|
|
|
song_id, priority);
|
|
|
|
if (result != PLAYLIST_RESULT_SUCCESS)
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2011-09-13 21:36:51 +02:00
|
|
|
const char *directory = "";
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-29 20:54:56 +02:00
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
2008-09-07 13:48:37 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return printAllIn(client, directory, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_setvol(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned level;
|
2009-03-14 11:10:21 +01:00
|
|
|
bool success;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &level, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:50:16 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (level > 100) {
|
2009-07-06 21:52:10 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "Invalid volume value");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-07-06 21:51:24 +02:00
|
|
|
success = volume_level_change(level);
|
2009-03-14 11:10:21 +01:00
|
|
|
if (!success) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_SYSTEM,
|
|
|
|
"problems setting volume");
|
2009-03-14 11:10:21 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2008-09-07 13:50:16 +02:00
|
|
|
|
2009-03-14 11:10:21 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_repeat(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_set_repeat(&g_playlist, client->player_control, status);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-03-27 14:42:55 +01:00
|
|
|
static enum command_return
|
2009-03-27 15:28:49 +01:00
|
|
|
handle_single(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2009-03-27 14:42:55 +01:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
2009-03-27 14:42:55 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_set_single(&g_playlist, client->player_control, status);
|
2009-03-27 14:42:55 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-30 00:01:02 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_consume(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
2009-03-30 00:01:02 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_set_consume(&g_playlist, status);
|
2009-03-30 00:01:02 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_random(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_set_random(&g_playlist, client->player_control, status);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_stats(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-18 15:22:26 +01:00
|
|
|
return stats_print(client);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_clearerror(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_clear_error(client->player_control);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_list(struct client *client, int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-01-24 15:56:30 +01:00
|
|
|
struct locate_item_list *conditionals;
|
2009-01-24 15:26:59 +01:00
|
|
|
int tagType = locate_parse_type(argv[1]);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (tagType < 0) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-12-11 21:18:04 +01:00
|
|
|
if (tagType == LOCATE_TAG_ANY_TYPE) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"any\" is not a valid return tag type");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2006-12-11 21:18:04 +01:00
|
|
|
}
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
/* for compatibility with < 0.12.0 */
|
2006-07-29 20:54:56 +02:00
|
|
|
if (argc == 3) {
|
2009-10-13 16:12:45 +02:00
|
|
|
if (tagType != TAG_ALBUM) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"should be \"%s\" for 3 arguments",
|
2009-10-13 16:12:45 +02:00
|
|
|
tag_item_names[TAG_ALBUM]);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_parse(argv + 1, argc - 1);
|
|
|
|
|
|
|
|
conditionals = locate_item_list_new(1);
|
2009-10-13 16:12:45 +02:00
|
|
|
conditionals->items[0].tag = TAG_ARTIST;
|
2009-01-24 15:56:30 +01:00
|
|
|
conditionals->items[0].needle = g_strdup(argv[2]);
|
|
|
|
} else {
|
|
|
|
conditionals =
|
|
|
|
locate_item_list_parse(argv + 2, argc - 2);
|
|
|
|
if (conditionals == NULL) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"not able to parse args");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-11-12 02:44:27 +01:00
|
|
|
}
|
|
|
|
}
|
2006-07-14 20:47:55 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
|
|
|
listAllUniqueTags(client, tagType, conditionals, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2009-01-24 15:56:30 +01:00
|
|
|
locate_item_list_free(conditionals);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return ret;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_move(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-03-26 22:02:56 +01:00
|
|
|
unsigned start, end;
|
|
|
|
int to;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_range(client, &start, &end, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_int(client, &to, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_move_range(&g_playlist, client->player_control,
|
|
|
|
start, end, to);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_moveid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned id;
|
|
|
|
int to;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &id, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_int(client, &to, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_move_id(&g_playlist, client->player_control,
|
|
|
|
id, to);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_swap(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned song1, song2;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &song1, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &song2, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_swap_songs(&g_playlist, client->player_control,
|
|
|
|
song1, song2);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_swapid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned id1, id2;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &id1, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &id2, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_swap_songs_id(&g_playlist, client->player_control,
|
|
|
|
id1, id2);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_seek(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned song, seek_time;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &song, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &seek_time, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_seek_song(&g_playlist, client->player_control,
|
|
|
|
song, seek_time);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_seekid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2012-02-14 18:52:22 +01:00
|
|
|
unsigned id, seek_time;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &id, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2012-02-14 18:52:22 +01:00
|
|
|
if (!check_unsigned(client, &seek_time, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
result = playlist_seek_song_id(&g_playlist, client->player_control,
|
|
|
|
id, seek_time);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2011-12-24 11:20:02 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_seekcur(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *p = argv[1];
|
|
|
|
bool relative = *p == '+' || *p == '-';
|
|
|
|
int seek_time;
|
2012-02-14 18:59:03 +01:00
|
|
|
if (!check_int(client, &seek_time, p))
|
2011-12-24 11:20:02 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
enum playlist_result result =
|
|
|
|
playlist_seek_current(&g_playlist, client->player_control,
|
|
|
|
seek_time, relative);
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_listallinfo(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2011-09-13 21:36:51 +02:00
|
|
|
const char *directory = "";
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-07-29 20:54:56 +02:00
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
2008-09-07 13:52:48 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return printInfoForAllIn(client, directory, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_ping(G_GNUC_UNUSED struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_password(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-17 23:53:28 +02:00
|
|
|
unsigned permission = 0;
|
2008-09-07 19:17:25 +02:00
|
|
|
|
|
|
|
if (getPermissionFromPassword(argv[1], &permission) < 0) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_PASSWORD, "incorrect password");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 19:17:25 +02:00
|
|
|
client_set_permission(client, permission);
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_crossfade(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2008-10-23 09:53:35 +02:00
|
|
|
unsigned xfade_time;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-23 09:53:35 +02:00
|
|
|
if (!check_unsigned(client, &xfade_time, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_set_cross_fade(client->player_control, xfade_time);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 18:21:47 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_mixrampdb(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
float db;
|
|
|
|
|
|
|
|
if (!check_float(client, &db, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_set_mixramp_db(client->player_control, db);
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_mixrampdelay(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
float delay_secs;
|
|
|
|
|
|
|
|
if (!check_float(client, &delay_secs, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_set_mixramp_delay(client->player_control, delay_secs);
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_enableoutput(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-11-02 23:13:58 +01:00
|
|
|
{
|
2008-10-23 09:53:35 +02:00
|
|
|
unsigned device;
|
2009-02-11 18:02:45 +01:00
|
|
|
bool ret;
|
2004-11-02 23:13:58 +01:00
|
|
|
|
2008-10-23 09:53:35 +02:00
|
|
|
if (!check_unsigned(client, &device, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:51:50 +02:00
|
|
|
|
2009-02-11 18:02:45 +01:00
|
|
|
ret = audio_output_enable_index(device);
|
|
|
|
if (!ret) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"No such audio output");
|
2009-02-11 18:02:45 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2008-09-07 13:51:50 +02:00
|
|
|
|
2009-02-11 18:02:45 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-11-02 23:13:58 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_disableoutput(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-11-02 23:13:58 +01:00
|
|
|
{
|
2008-10-23 09:53:35 +02:00
|
|
|
unsigned device;
|
2009-02-11 18:02:45 +01:00
|
|
|
bool ret;
|
2004-11-02 23:13:58 +01:00
|
|
|
|
2008-10-23 09:53:35 +02:00
|
|
|
if (!check_unsigned(client, &device, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:51:50 +02:00
|
|
|
|
2009-02-11 18:02:45 +01:00
|
|
|
ret = audio_output_disable_index(device);
|
|
|
|
if (!ret) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"No such audio output");
|
2009-02-11 18:02:45 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2008-09-07 13:51:50 +02:00
|
|
|
|
2009-02-11 18:02:45 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-11-02 23:13:58 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_devices(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2004-11-03 00:08:00 +01:00
|
|
|
{
|
2008-09-07 14:04:16 +02:00
|
|
|
printAudioDevices(client);
|
2004-11-03 00:08:00 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2004-11-03 00:08:00 +01:00
|
|
|
}
|
|
|
|
|
2004-11-08 19:01:36 +01:00
|
|
|
/* don't be fooled, this is the command handler for "commands" command */
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_commands(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]);
|
2004-11-08 19:01:36 +01:00
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_not_commands(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]);
|
2004-11-23 20:46:33 +01:00
|
|
|
|
2012-02-13 19:59:41 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_config(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
if (!client_is_local(client)) {
|
|
|
|
command_error(client, ACK_ERROR_PERMISSION,
|
|
|
|
"Command only permitted to local clients");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *path = mapper_get_music_directory();
|
|
|
|
if (path != NULL)
|
|
|
|
client_printf(client, "music_directory: %s\n", path);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_playlistclear(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-12-07 15:41:40 +01:00
|
|
|
{
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
return spl_clear(argv[1], &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
2006-12-07 15:41:40 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_playlistadd(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2006-12-07 15:41:40 +01:00
|
|
|
{
|
|
|
|
char *playlist = argv[1];
|
2009-01-04 16:19:45 +01:00
|
|
|
char *uri = argv[2];
|
2006-12-07 15:41:40 +01:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
bool success;
|
|
|
|
GError *error = NULL;
|
2009-01-04 16:22:08 +01:00
|
|
|
if (uri_has_scheme(uri)) {
|
2009-01-04 17:46:42 +01:00
|
|
|
if (!uri_supported_scheme(uri)) {
|
2009-01-04 16:22:08 +01:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"unsupported URI scheme");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
success = spl_append_uri(argv[1], playlist, &error);
|
2008-12-16 21:23:29 +01:00
|
|
|
} else
|
2011-09-11 07:41:25 +02:00
|
|
|
success = addAllInToStoredPlaylist(uri, playlist, &error);
|
2008-09-07 13:48:37 +02:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
if (!success && error == NULL) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:48:37 +02:00
|
|
|
}
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
return success ? COMMAND_RETURN_OK : print_error(client, error);
|
2006-12-07 15:41:40 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_listplaylists(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2008-10-22 19:16:56 +02:00
|
|
|
{
|
2011-09-11 07:41:25 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
GPtrArray *list = spl_list(&error);
|
|
|
|
if (list == NULL)
|
|
|
|
return print_error(client, error);
|
2008-10-22 19:16:56 +02:00
|
|
|
|
|
|
|
print_spl_list(client, list);
|
|
|
|
spl_list_free(list);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2008-10-22 19:16:56 +02:00
|
|
|
}
|
|
|
|
|
2009-10-17 22:58:19 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_replay_gain_mode(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (!replay_gain_set_mode_string(argv[1])) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Unrecognized replay gain mode");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_replay_gain_status(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
client_printf(client, "replay_gain_mode: %s\n",
|
|
|
|
replay_gain_get_mode_string());
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-14 22:38:14 +02:00
|
|
|
handle_idle(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2008-10-14 22:38:14 +02:00
|
|
|
{
|
2008-11-22 13:26:21 +01:00
|
|
|
unsigned flags = 0, j;
|
|
|
|
int i;
|
|
|
|
const char *const* idle_names;
|
|
|
|
|
|
|
|
idle_names = idle_get_names();
|
|
|
|
for (i = 1; i < argc; ++i) {
|
|
|
|
if (!argv[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; idle_names[j]; ++j) {
|
2009-04-28 09:34:03 +02:00
|
|
|
if (!g_ascii_strcasecmp(argv[i], idle_names[j])) {
|
2008-11-22 13:26:21 +01:00
|
|
|
flags |= (1 << j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No argument means that the client wants to receive everything */
|
|
|
|
if (flags == 0)
|
|
|
|
flags = ~0;
|
|
|
|
|
2008-10-14 22:38:14 +02:00
|
|
|
/* enable "idle" mode on this client */
|
2008-11-22 13:26:21 +01:00
|
|
|
client_idle_wait(client, flags);
|
2008-10-14 22:38:14 +02:00
|
|
|
|
|
|
|
/* return value is "1" so the caller won't print "OK" */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
#ifdef ENABLE_SQLITE
|
2009-04-01 18:53:02 +02:00
|
|
|
struct sticker_song_find_data {
|
|
|
|
struct client *client;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
sticker_song_find_print_cb(struct song *song, const char *value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct sticker_song_find_data *data = user_data;
|
|
|
|
|
2009-10-13 18:01:06 +02:00
|
|
|
song_print_uri(data->client, song);
|
2009-04-01 18:53:02 +02:00
|
|
|
sticker_print_value(data->client, data->name, value);
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_sticker_song(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
2009-11-04 00:21:58 +01:00
|
|
|
/* get song song_id key */
|
2009-01-19 19:09:49 +01:00
|
|
|
if (argc == 5 && strcmp(argv[1], "get") == 0) {
|
2009-04-01 18:44:39 +02:00
|
|
|
struct song *song;
|
2009-01-19 19:09:49 +01:00
|
|
|
char *value;
|
|
|
|
|
2009-04-01 18:44:39 +02:00
|
|
|
song = db_get_song(argv[3]);
|
|
|
|
if (song == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such song");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
value = sticker_song_get_value(song, argv[4]);
|
|
|
|
if (value == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such sticker");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-04-01 17:30:56 +02:00
|
|
|
sticker_print_value(client, argv[4], value);
|
2009-01-19 19:09:49 +01:00
|
|
|
g_free(value);
|
|
|
|
|
2009-03-03 07:49:23 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2009-11-04 00:21:58 +01:00
|
|
|
/* list song song_id */
|
2009-03-03 07:49:23 +01:00
|
|
|
} else if (argc == 4 && strcmp(argv[1], "list") == 0) {
|
2009-04-01 18:44:39 +02:00
|
|
|
struct song *song;
|
|
|
|
struct sticker *sticker;
|
|
|
|
|
|
|
|
song = db_get_song(argv[3]);
|
|
|
|
if (song == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such song");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sticker = sticker_song_get(song);
|
2010-11-27 20:36:11 +01:00
|
|
|
if (sticker) {
|
|
|
|
sticker_print(client, sticker);
|
|
|
|
sticker_free(sticker);
|
2009-03-03 07:49:23 +01:00
|
|
|
}
|
2009-03-14 14:20:04 +01:00
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
2009-11-04 00:21:58 +01:00
|
|
|
/* set song song_id id key */
|
2009-01-19 19:09:49 +01:00
|
|
|
} else if (argc == 6 && strcmp(argv[1], "set") == 0) {
|
2009-04-01 18:44:39 +02:00
|
|
|
struct song *song;
|
2009-01-19 19:09:49 +01:00
|
|
|
bool ret;
|
|
|
|
|
2009-04-01 18:44:39 +02:00
|
|
|
song = db_get_song(argv[3]);
|
|
|
|
if (song == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such song");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
ret = sticker_song_set_value(song, argv[4], argv[5]);
|
|
|
|
if (!ret) {
|
|
|
|
command_error(client, ACK_ERROR_SYSTEM,
|
2009-03-03 07:49:23 +01:00
|
|
|
"failed to set sticker value");
|
2009-01-19 19:09:49 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-04-28 20:25:07 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2009-11-04 00:21:58 +01:00
|
|
|
/* delete song song_id [key] */
|
2009-04-28 20:25:07 +02:00
|
|
|
} else if ((argc == 4 || argc == 5) &&
|
|
|
|
strcmp(argv[1], "delete") == 0) {
|
|
|
|
struct song *song;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
song = db_get_song(argv[3]);
|
|
|
|
if (song == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such song");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = argc == 4
|
|
|
|
? sticker_song_delete(song)
|
|
|
|
: sticker_song_delete_value(song, argv[4]);
|
|
|
|
if (!ret) {
|
|
|
|
command_error(client, ACK_ERROR_SYSTEM,
|
|
|
|
"no such sticker");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-04-01 18:53:02 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2009-11-04 00:21:58 +01:00
|
|
|
/* find song dir key */
|
2009-04-01 18:53:02 +02:00
|
|
|
} else if (argc == 5 && strcmp(argv[1], "find") == 0) {
|
|
|
|
/* "sticker find song a/directory name" */
|
|
|
|
struct directory *directory;
|
|
|
|
bool success;
|
|
|
|
struct sticker_song_find_data data = {
|
|
|
|
.client = client,
|
|
|
|
.name = argv[4],
|
|
|
|
};
|
|
|
|
|
2012-01-31 22:12:14 +01:00
|
|
|
db_lock();
|
2009-04-01 18:53:02 +02:00
|
|
|
directory = db_get_directory(argv[3]);
|
|
|
|
if (directory == NULL) {
|
2012-01-31 22:12:14 +01:00
|
|
|
db_unlock();
|
2009-04-01 18:53:02 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no such directory");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = sticker_song_find(directory, data.name,
|
|
|
|
sticker_song_find_print_cb, &data);
|
2012-01-31 22:12:14 +01:00
|
|
|
db_unlock();
|
2009-04-01 18:53:02 +02:00
|
|
|
if (!success) {
|
|
|
|
command_error(client, ACK_ERROR_SYSTEM,
|
|
|
|
"failed to set search sticker database");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-01-19 19:09:49 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
} else {
|
|
|
|
command_error(client, ACK_ERROR_ARG, "bad request");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_sticker(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc >= 4);
|
|
|
|
|
|
|
|
if (!sticker_enabled()) {
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"sticker database is disabled");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(argv[2], "song") == 0)
|
|
|
|
return handle_sticker_song(client, argc, argv);
|
|
|
|
else {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"unknown sticker domain");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-29 09:26:22 +01:00
|
|
|
static enum command_return
|
|
|
|
handle_subscribe(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc == 2);
|
|
|
|
|
|
|
|
switch (client_subscribe(client, argv[1])) {
|
|
|
|
case CLIENT_SUBSCRIBE_OK:
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
|
|
|
|
case CLIENT_SUBSCRIBE_INVALID:
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"invalid channel name");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
case CLIENT_SUBSCRIBE_ALREADY:
|
|
|
|
command_error(client, ACK_ERROR_EXIST,
|
|
|
|
"already subscribed to this channel");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
case CLIENT_SUBSCRIBE_FULL:
|
|
|
|
command_error(client, ACK_ERROR_EXIST,
|
|
|
|
"subscription list is full");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unreachable */
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_unsubscribe(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc == 2);
|
|
|
|
|
|
|
|
if (client_unsubscribe(client, argv[1]))
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
else {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"not subscribed to this channel");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct channels_context {
|
|
|
|
GStringChunk *chunk;
|
|
|
|
|
|
|
|
GHashTable *channels;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
collect_channels(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct channels_context *context = user_data;
|
|
|
|
const struct client *client = data;
|
|
|
|
|
|
|
|
for (GSList *i = client->subscriptions; i != NULL;
|
|
|
|
i = g_slist_next(i)) {
|
|
|
|
const char *channel = i->data;
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(context->channels, channel) == NULL) {
|
|
|
|
char *channel2 = g_string_chunk_insert(context->chunk,
|
|
|
|
channel);
|
|
|
|
g_hash_table_insert(context->channels, channel2,
|
|
|
|
context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_channel(gpointer key, G_GNUC_UNUSED gpointer value, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct client *client = user_data;
|
|
|
|
const char *channel = key;
|
|
|
|
|
|
|
|
client_printf(client, "channel: %s\n", channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_channels(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc == 1);
|
|
|
|
|
|
|
|
struct channels_context context = {
|
|
|
|
.chunk = g_string_chunk_new(1024),
|
|
|
|
.channels = g_hash_table_new(g_str_hash, g_str_equal),
|
|
|
|
};
|
|
|
|
|
|
|
|
client_list_foreach(collect_channels, &context);
|
|
|
|
|
|
|
|
g_hash_table_foreach(context.channels, print_channel, client);
|
|
|
|
|
|
|
|
g_hash_table_destroy(context.channels);
|
|
|
|
g_string_chunk_free(context.chunk);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_read_messages(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc == 1);
|
|
|
|
|
|
|
|
GSList *messages = client_read_messages(client);
|
|
|
|
|
|
|
|
for (GSList *i = messages; i != NULL; i = g_slist_next(i)) {
|
|
|
|
struct client_message *msg = i->data;
|
|
|
|
|
|
|
|
client_printf(client, "channel: %s\nmessage: %s\n",
|
|
|
|
msg->channel, msg->message);
|
|
|
|
client_message_free(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(messages);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct send_message_context {
|
|
|
|
struct client_message msg;
|
|
|
|
|
|
|
|
bool sent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_message(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct send_message_context *context = user_data;
|
|
|
|
struct client *client = data;
|
|
|
|
|
|
|
|
if (client_push_message(client, &context->msg))
|
|
|
|
context->sent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum command_return
|
|
|
|
handle_send_message(struct client *client,
|
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
assert(argc == 3);
|
|
|
|
|
|
|
|
if (!client_message_valid_channel_name(argv[1])) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"invalid channel name");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct send_message_context context = {
|
|
|
|
.sent = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
client_message_init(&context.msg, argv[1], argv[2]);
|
|
|
|
|
|
|
|
client_list_foreach(send_message, &context);
|
|
|
|
|
|
|
|
client_message_deinit(&context.msg);
|
|
|
|
|
|
|
|
if (context.sent)
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
else {
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"nobody is subscribed to this channel");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 10:08:14 +02:00
|
|
|
/**
|
|
|
|
* The command registry.
|
|
|
|
*
|
|
|
|
* This array must be sorted!
|
|
|
|
*/
|
|
|
|
static const struct command commands[] = {
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "add", PERMISSION_ADD, 1, 1, handle_add },
|
|
|
|
{ "addid", PERMISSION_ADD, 1, 2, handle_addid },
|
2011-01-29 09:26:22 +01:00
|
|
|
{ "channels", PERMISSION_READ, 0, 0, handle_channels },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "clear", PERMISSION_CONTROL, 0, 0, handle_clear },
|
|
|
|
{ "clearerror", PERMISSION_CONTROL, 0, 0, handle_clearerror },
|
|
|
|
{ "close", PERMISSION_NONE, -1, -1, handle_close },
|
|
|
|
{ "commands", PERMISSION_NONE, 0, 0, handle_commands },
|
2012-02-13 19:59:41 +01:00
|
|
|
{ "config", PERMISSION_ADMIN, 0, 0, handle_config },
|
2009-03-30 00:01:02 +02:00
|
|
|
{ "consume", PERMISSION_CONTROL, 1, 1, handle_consume },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "count", PERMISSION_READ, 2, -1, handle_count },
|
|
|
|
{ "crossfade", PERMISSION_CONTROL, 1, 1, handle_crossfade },
|
|
|
|
{ "currentsong", PERMISSION_READ, 0, 0, handle_currentsong },
|
2009-11-07 15:57:22 +01:00
|
|
|
{ "decoders", PERMISSION_READ, 0, 0, handle_decoders },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "delete", PERMISSION_CONTROL, 1, 1, handle_delete },
|
|
|
|
{ "deleteid", PERMISSION_CONTROL, 1, 1, handle_deleteid },
|
|
|
|
{ "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput },
|
|
|
|
{ "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput },
|
|
|
|
{ "find", PERMISSION_READ, 2, -1, handle_find },
|
2009-08-25 13:43:22 +02:00
|
|
|
{ "findadd", PERMISSION_READ, 2, -1, handle_findadd},
|
2008-11-22 13:26:21 +01:00
|
|
|
{ "idle", PERMISSION_READ, 0, -1, handle_idle },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "kill", PERMISSION_ADMIN, -1, -1, handle_kill },
|
|
|
|
{ "list", PERMISSION_READ, 1, -1, handle_list },
|
|
|
|
{ "listall", PERMISSION_READ, 0, 1, handle_listall },
|
|
|
|
{ "listallinfo", PERMISSION_READ, 0, 1, handle_listallinfo },
|
|
|
|
{ "listplaylist", PERMISSION_READ, 1, 1, handle_listplaylist },
|
|
|
|
{ "listplaylistinfo", PERMISSION_READ, 1, 1, handle_listplaylistinfo },
|
|
|
|
{ "listplaylists", PERMISSION_READ, 0, 0, handle_listplaylists },
|
2012-02-09 23:52:51 +01:00
|
|
|
{ "load", PERMISSION_ADD, 1, 2, handle_load },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "lsinfo", PERMISSION_READ, 0, 1, handle_lsinfo },
|
2010-03-21 18:21:47 +01:00
|
|
|
{ "mixrampdb", PERMISSION_CONTROL, 1, 1, handle_mixrampdb },
|
|
|
|
{ "mixrampdelay", PERMISSION_CONTROL, 1, 1, handle_mixrampdelay },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "move", PERMISSION_CONTROL, 2, 2, handle_move },
|
|
|
|
{ "moveid", PERMISSION_CONTROL, 2, 2, handle_moveid },
|
|
|
|
{ "next", PERMISSION_CONTROL, 0, 0, handle_next },
|
|
|
|
{ "notcommands", PERMISSION_NONE, 0, 0, handle_not_commands },
|
|
|
|
{ "outputs", PERMISSION_READ, 0, 0, handle_devices },
|
|
|
|
{ "password", PERMISSION_NONE, 1, 1, handle_password },
|
|
|
|
{ "pause", PERMISSION_CONTROL, 0, 1, handle_pause },
|
|
|
|
{ "ping", PERMISSION_NONE, 0, 0, handle_ping },
|
|
|
|
{ "play", PERMISSION_CONTROL, 0, 1, handle_play },
|
|
|
|
{ "playid", PERMISSION_CONTROL, 0, 1, handle_playid },
|
|
|
|
{ "playlist", PERMISSION_READ, 0, 0, handle_playlist },
|
|
|
|
{ "playlistadd", PERMISSION_CONTROL, 2, 2, handle_playlistadd },
|
|
|
|
{ "playlistclear", PERMISSION_CONTROL, 1, 1, handle_playlistclear },
|
|
|
|
{ "playlistdelete", PERMISSION_CONTROL, 2, 2, handle_playlistdelete },
|
|
|
|
{ "playlistfind", PERMISSION_READ, 2, -1, handle_playlistfind },
|
|
|
|
{ "playlistid", PERMISSION_READ, 0, 1, handle_playlistid },
|
|
|
|
{ "playlistinfo", PERMISSION_READ, 0, 1, handle_playlistinfo },
|
|
|
|
{ "playlistmove", PERMISSION_CONTROL, 3, 3, handle_playlistmove },
|
|
|
|
{ "playlistsearch", PERMISSION_READ, 2, -1, handle_playlistsearch },
|
|
|
|
{ "plchanges", PERMISSION_READ, 1, 1, handle_plchanges },
|
|
|
|
{ "plchangesposid", PERMISSION_READ, 1, 1, handle_plchangesposid },
|
|
|
|
{ "previous", PERMISSION_CONTROL, 0, 0, handle_previous },
|
2011-07-19 00:34:33 +02:00
|
|
|
{ "prio", PERMISSION_CONTROL, 2, -1, handle_prio },
|
|
|
|
{ "prioid", PERMISSION_CONTROL, 2, -1, handle_prioid },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "random", PERMISSION_CONTROL, 1, 1, handle_random },
|
2011-01-29 09:26:22 +01:00
|
|
|
{ "readmessages", PERMISSION_READ, 0, 0, handle_read_messages },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "rename", PERMISSION_CONTROL, 2, 2, handle_rename },
|
|
|
|
{ "repeat", PERMISSION_CONTROL, 1, 1, handle_repeat },
|
2009-10-17 22:58:19 +02:00
|
|
|
{ "replay_gain_mode", PERMISSION_CONTROL, 1, 1,
|
|
|
|
handle_replay_gain_mode },
|
|
|
|
{ "replay_gain_status", PERMISSION_READ, 0, 0,
|
|
|
|
handle_replay_gain_status },
|
2011-02-27 23:35:00 +01:00
|
|
|
{ "rescan", PERMISSION_CONTROL, 0, 1, handle_rescan },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "rm", PERMISSION_CONTROL, 1, 1, handle_rm },
|
|
|
|
{ "save", PERMISSION_CONTROL, 1, 1, handle_save },
|
|
|
|
{ "search", PERMISSION_READ, 2, -1, handle_search },
|
2012-06-27 09:26:00 +02:00
|
|
|
{ "searchadd", PERMISSION_READ, 2, -1, handle_searchadd },
|
2012-06-27 09:26:03 +02:00
|
|
|
{ "searchaddpl", PERMISSION_READ, 3, -1, handle_searchaddpl },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "seek", PERMISSION_CONTROL, 2, 2, handle_seek },
|
2011-12-24 11:20:02 +01:00
|
|
|
{ "seekcur", PERMISSION_CONTROL, 1, 1, handle_seekcur },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "seekid", PERMISSION_CONTROL, 2, 2, handle_seekid },
|
2011-01-29 09:26:22 +01:00
|
|
|
{ "sendmessage", PERMISSION_CONTROL, 2, 2, handle_send_message },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "setvol", PERMISSION_CONTROL, 1, 1, handle_setvol },
|
2009-02-13 10:38:32 +01:00
|
|
|
{ "shuffle", PERMISSION_CONTROL, 0, 1, handle_shuffle },
|
2009-03-27 15:28:49 +01:00
|
|
|
{ "single", PERMISSION_CONTROL, 1, 1, handle_single },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "stats", PERMISSION_READ, 0, 0, handle_stats },
|
|
|
|
{ "status", PERMISSION_READ, 0, 0, handle_status },
|
2009-01-19 19:09:49 +01:00
|
|
|
#ifdef ENABLE_SQLITE
|
|
|
|
{ "sticker", PERMISSION_ADMIN, 3, -1, handle_sticker },
|
|
|
|
#endif
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "stop", PERMISSION_CONTROL, 0, 0, handle_stop },
|
2011-01-29 09:26:22 +01:00
|
|
|
{ "subscribe", PERMISSION_READ, 1, 1, handle_subscribe },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "swap", PERMISSION_CONTROL, 2, 2, handle_swap },
|
|
|
|
{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
|
|
|
|
{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
|
2011-01-29 09:26:22 +01:00
|
|
|
{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
|
2011-02-27 23:35:00 +01:00
|
|
|
{ "update", PERMISSION_CONTROL, 0, 1, handle_update },
|
2008-10-22 21:40:44 +02:00
|
|
|
{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
|
2008-10-22 10:08:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_commands = sizeof(commands) / sizeof(commands[0]);
|
|
|
|
|
2009-01-23 18:51:14 +01:00
|
|
|
static bool
|
2009-01-24 11:13:58 +01:00
|
|
|
command_available(G_GNUC_UNUSED const struct command *cmd)
|
2009-01-23 18:51:14 +01:00
|
|
|
{
|
|
|
|
#ifdef ENABLE_SQLITE
|
|
|
|
if (strcmp(cmd->cmd, "sticker") == 0)
|
|
|
|
return sticker_enabled();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-22 10:08:14 +02:00
|
|
|
/* don't be fooled, this is the command handler for "commands" command */
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_commands(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2008-10-22 10:08:14 +02:00
|
|
|
{
|
|
|
|
const unsigned permission = client_get_permission(client);
|
|
|
|
const struct command *cmd;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_commands; ++i) {
|
|
|
|
cmd = &commands[i];
|
|
|
|
|
2009-01-23 18:51:14 +01:00
|
|
|
if (cmd->permission == (permission & cmd->permission) &&
|
|
|
|
command_available(cmd))
|
2008-10-22 10:08:14 +02:00
|
|
|
client_printf(client, "command: %s\n", cmd->cmd);
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2008-10-22 10:08:14 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
static enum command_return
|
2008-10-22 21:40:44 +02:00
|
|
|
handle_not_commands(struct client *client,
|
2008-11-24 14:55:32 +01:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
2008-10-22 10:08:14 +02:00
|
|
|
{
|
|
|
|
const unsigned permission = client_get_permission(client);
|
|
|
|
const struct command *cmd;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_commands; ++i) {
|
|
|
|
cmd = &commands[i];
|
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
if (cmd->permission != (permission & cmd->permission))
|
2008-10-22 10:08:14 +02:00
|
|
|
client_printf(client, "command: %s\n", cmd->cmd);
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
2008-10-22 10:08:14 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
void command_init(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-22 10:08:14 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
/* ensure that the command list is sorted */
|
|
|
|
for (unsigned i = 0; i < num_commands - 1; ++i)
|
|
|
|
assert(strcmp(commands[i].cmd, commands[i + 1].cmd) < 0);
|
|
|
|
#endif
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
void command_finish(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-22 10:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct command *
|
|
|
|
command_lookup(const char *name)
|
|
|
|
{
|
|
|
|
unsigned a = 0, b = num_commands, i;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
/* binary search */
|
|
|
|
do {
|
|
|
|
i = (a + b) / 2;
|
|
|
|
|
|
|
|
cmp = strcmp(name, commands[i].cmd);
|
|
|
|
if (cmp == 0)
|
|
|
|
return &commands[i];
|
|
|
|
else if (cmp < 0)
|
|
|
|
b = i;
|
|
|
|
else if (cmp > 0)
|
|
|
|
a = i + 1;
|
|
|
|
} while (a < b);
|
|
|
|
|
|
|
|
return NULL;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
static bool
|
2008-10-22 21:40:44 +02:00
|
|
|
command_check_request(const struct command *cmd, struct client *client,
|
|
|
|
unsigned permission, int argc, char *argv[])
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int min = cmd->min + 1;
|
|
|
|
int max = cmd->max + 1;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
if (cmd->permission != (permission & cmd->permission)) {
|
2008-09-07 13:52:36 +02:00
|
|
|
if (client != NULL)
|
|
|
|
command_error(client, ACK_ERROR_PERMISSION,
|
|
|
|
"you don't have permission for \"%s\"",
|
|
|
|
cmd->cmd);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (min == 0)
|
2008-10-22 21:41:54 +02:00
|
|
|
return true;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (min == max && max != argc) {
|
2008-09-07 13:52:36 +02:00
|
|
|
if (client != NULL)
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"wrong number of arguments for \"%s\"",
|
|
|
|
argv[0]);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else if (argc < min) {
|
2008-09-07 13:52:36 +02:00
|
|
|
if (client != NULL)
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"too few arguments for \"%s\"", argv[0]);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else if (argc > max && max /* != 0 */ ) {
|
2008-09-07 13:52:36 +02:00
|
|
|
if (client != NULL)
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"too many arguments for \"%s\"", argv[0]);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else
|
2008-10-22 21:41:54 +02:00
|
|
|
return true;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-22 09:59:01 +02:00
|
|
|
static const struct command *
|
2008-10-22 21:40:44 +02:00
|
|
|
command_checked_lookup(struct client *client, unsigned permission,
|
|
|
|
int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2008-10-22 09:59:01 +02:00
|
|
|
const struct command *cmd;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2012-02-14 18:34:04 +01:00
|
|
|
current_command = "";
|
2004-06-04 03:58:31 +02:00
|
|
|
|
2006-07-29 20:54:56 +02:00
|
|
|
if (argc == 0)
|
2006-07-20 18:02:40 +02:00
|
|
|
return NULL;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 10:08:14 +02:00
|
|
|
cmd = command_lookup(argv[0]);
|
|
|
|
if (cmd == NULL) {
|
2008-09-07 13:52:36 +02:00
|
|
|
if (client != NULL)
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"unknown command \"%s\"", argv[0]);
|
2006-07-20 18:02:40 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-06-04 03:58:31 +02:00
|
|
|
current_command = cmd->cmd;
|
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!command_check_request(cmd, client, permission, argc, argv))
|
2004-04-11 19:37:47 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:41:49 +02:00
|
|
|
enum command_return
|
2009-07-29 08:00:01 +02:00
|
|
|
command_process(struct client *client, unsigned num, char *line)
|
2004-04-11 19:37:47 +02:00
|
|
|
{
|
2009-07-19 15:15:36 +02:00
|
|
|
GError *error = NULL;
|
2006-10-06 12:33:27 +02:00
|
|
|
int argc;
|
|
|
|
char *argv[COMMAND_ARGV_MAX] = { NULL };
|
2008-10-22 09:59:01 +02:00
|
|
|
const struct command *cmd;
|
2008-10-22 21:41:49 +02:00
|
|
|
enum command_return ret = COMMAND_RETURN_ERROR;
|
2004-04-12 03:44:52 +02:00
|
|
|
|
2009-07-29 08:00:01 +02:00
|
|
|
command_list_num = num;
|
|
|
|
|
2009-07-19 15:15:36 +02:00
|
|
|
/* get the command name (first word on the line) */
|
|
|
|
|
|
|
|
argv[0] = tokenizer_next_word(&line, &error);
|
|
|
|
if (argv[0] == NULL) {
|
|
|
|
current_command = "";
|
|
|
|
if (*line == 0)
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"No command given");
|
|
|
|
else {
|
|
|
|
command_error(client, ACK_ERROR_UNKNOWN,
|
|
|
|
"%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
current_command = NULL;
|
|
|
|
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
argc = 1;
|
|
|
|
|
|
|
|
/* now parse the arguments (quoted or unquoted) */
|
|
|
|
|
|
|
|
while (argc < (int)G_N_ELEMENTS(argv) &&
|
|
|
|
(argv[argc] =
|
2009-09-25 00:53:15 +02:00
|
|
|
tokenizer_next_param(&line, &error)) != NULL)
|
2009-07-19 15:15:36 +02:00
|
|
|
++argc;
|
|
|
|
|
|
|
|
/* some error checks; we have to set current_command because
|
|
|
|
command_error() expects it to be set */
|
|
|
|
|
|
|
|
current_command = argv[0];
|
|
|
|
|
|
|
|
if (argc >= (int)G_N_ELEMENTS(argv)) {
|
|
|
|
command_error(client, ACK_ERROR_ARG, "Too many arguments");
|
|
|
|
current_command = NULL;
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*line != 0) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"%s", error->message);
|
|
|
|
current_command = NULL;
|
|
|
|
g_error_free(error);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look up and invoke the command handler */
|
2004-04-11 19:37:47 +02:00
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
cmd = command_checked_lookup(client, client_get_permission(client),
|
|
|
|
argc, argv);
|
2008-10-06 18:39:33 +02:00
|
|
|
if (cmd)
|
|
|
|
ret = cmd->handler(client, argc, argv);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-06-04 03:58:31 +02:00
|
|
|
current_command = NULL;
|
2008-10-22 21:40:44 +02:00
|
|
|
command_list_num = 0;
|
2004-06-04 03:58:31 +02:00
|
|
|
|
2004-04-12 03:44:52 +02:00
|
|
|
return ret;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|