2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2012-08-25 12:59:54 +02:00
|
|
|
* Copyright (C) 2003-2012 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-08-25 12:59:54 +02:00
|
|
|
#include "QueueCommands.hxx"
|
|
|
|
#include "PlayerCommands.hxx"
|
|
|
|
#include "PlaylistCommands.hxx"
|
2012-08-07 21:55:11 +02:00
|
|
|
#include "DatabaseCommands.hxx"
|
2012-08-25 12:59:54 +02:00
|
|
|
#include "OutputCommands.hxx"
|
|
|
|
#include "StickerCommands.hxx"
|
|
|
|
#include "MessageCommands.hxx"
|
2012-08-07 22:26:14 +02:00
|
|
|
#include "CommandError.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"
|
2012-08-08 09:15:34 +02:00
|
|
|
#include "time_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 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-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"
|
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-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"
|
|
|
|
#endif
|
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
2012-08-25 12:59:54 +02:00
|
|
|
#include <string.h>
|
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 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);
|
|
|
|
|
|
|
|
client_printf(client, "playlist: %s\n", playlist->name);
|
2008-10-22 19:18:39 +02:00
|
|
|
|
2012-08-08 09:09:15 +02:00
|
|
|
if (playlist->mtime > 0)
|
|
|
|
time_print(client, "Last-Modified", playlist->mtime);
|
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-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-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;
|
|
|
|
}
|
|
|
|
|
2012-08-07 21:55:11 +02:00
|
|
|
enum command_return result = handle_lsinfo2(client, argc, argv);
|
|
|
|
if (result != COMMAND_RETURN_OK)
|
|
|
|
return result;
|
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_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
|
2012-08-25 12:59:54 +02:00
|
|
|
handle_setvol(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2012-08-25 12:59:54 +02:00
|
|
|
unsigned level;
|
|
|
|
bool success;
|
2009-03-31 14:05:11 +02:00
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
if (!check_unsigned(client, &level, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-03-31 14:05:11 +02:00
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
if (level > 100) {
|
|
|
|
command_error(client, ACK_ERROR_ARG, "Invalid volume value");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2009-07-06 21:52:10 +02:00
|
|
|
|
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-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
|
|
|
{
|
2012-08-28 20:52:07 +02:00
|
|
|
stats_print(client);
|
|
|
|
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_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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-13 23:37:50 +02:00
|
|
|
const char *path = mapper_get_music_directory_utf8();
|
2012-02-13 19:59:41 +01:00
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
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-29 00:05:33 +02:00
|
|
|
{ "searchadd", PERMISSION_ADD, 2, -1, handle_searchadd },
|
|
|
|
{ "searchaddpl", PERMISSION_CONTROL, 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
|
|
|
}
|