2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2010-01-01 05:55:13 +01:00
|
|
|
* Copyright (C) 2003-2010 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"
|
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"
|
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-09 15:23:37 +02:00
|
|
|
#include "directory_print.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"
|
2008-09-06 20:28:31 +02:00
|
|
|
#include "tag.h"
|
2008-08-29 09:36:42 +02:00
|
|
|
#include "client.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"
|
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"
|
2009-04-01 18:53:02 +02:00
|
|
|
#include "song_print.h"
|
2009-01-19 19:09:49 +01:00
|
|
|
#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"
|
|
|
|
#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-01-26 13:46:53 +01:00
|
|
|
/* this should really be "need a non-negative integer": */
|
|
|
|
static const char need_positive[] = "need a positive integer"; /* no-op */
|
2009-01-09 17:06:44 +01:00
|
|
|
static const char need_range[] = "need a range";
|
2008-01-26 13:46:53 +01:00
|
|
|
|
|
|
|
/* FIXME: redundant error messages */
|
|
|
|
static const char check_integer[] = "\"%s\" is not a integer";
|
|
|
|
static const char need_integer[] = "need an integer";
|
|
|
|
|
2008-02-05 11:17:33 +01:00
|
|
|
static const char *current_command;
|
2008-10-22 21:40:44 +02:00
|
|
|
static int command_list_num;
|
2004-06-04 03:58:31 +02:00
|
|
|
|
2008-09-07 13:51:59 +02:00
|
|
|
void command_success(struct client *client)
|
|
|
|
{
|
|
|
|
client_puts(client, "OK\n");
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:40:32 +02:00
|
|
|
static void command_error_v(struct client *client, enum ack error,
|
2008-09-07 13:51:59 +02:00
|
|
|
const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
assert(client != NULL);
|
|
|
|
assert(current_command != NULL);
|
|
|
|
|
|
|
|
client_printf(client, "ACK [%i@%i] {%s} ",
|
2008-10-22 21:40:44 +02:00
|
|
|
(int)error, command_list_num, current_command);
|
2008-09-07 13:51:59 +02:00
|
|
|
client_vprintf(client, fmt, args);
|
|
|
|
client_puts(client, "\n");
|
|
|
|
|
|
|
|
current_command = NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-29 19:58:15 +02:00
|
|
|
G_GNUC_PRINTF(3, 4) static void command_error(struct client *client, enum ack error,
|
2008-12-02 03:00:02 +01:00
|
|
|
const char *fmt, ...)
|
2008-09-07 13:51:59 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
command_error_v(client, error, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2008-12-02 03:00:02 +01:00
|
|
|
static bool G_GNUC_PRINTF(4, 5)
|
2008-10-22 21:41:54 +02:00
|
|
|
check_uint32(struct client *client, uint32_t *dst,
|
|
|
|
const char *s, const char *fmt, ...)
|
2008-01-26 13:46:53 +01:00
|
|
|
{
|
|
|
|
char *test;
|
|
|
|
|
|
|
|
*dst = strtoul(s, &test, 10);
|
|
|
|
if (*test != '\0') {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error_v(client, ACK_ERROR_ARG, fmt, args);
|
2008-01-26 13:46:53 +01:00
|
|
|
va_end(args);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2008-01-26 13:46:53 +01:00
|
|
|
}
|
2008-10-22 21:41:54 +02:00
|
|
|
return true;
|
2008-01-26 13:46:53 +01:00
|
|
|
}
|
|
|
|
|
2008-12-02 03:00:02 +01:00
|
|
|
static bool G_GNUC_PRINTF(4, 5)
|
2008-10-23 09:54:10 +02:00
|
|
|
check_int(struct client *client, int *value_r,
|
2008-10-22 21:41:54 +02:00
|
|
|
const char *s, const char *fmt, ...)
|
2008-01-26 13:46:53 +01:00
|
|
|
{
|
|
|
|
char *test;
|
2008-10-23 09:54:10 +02:00
|
|
|
long value;
|
2008-01-26 13:46:53 +01:00
|
|
|
|
2008-10-23 09:54:10 +02:00
|
|
|
value = strtol(s, &test, 10);
|
2008-10-23 09:53:35 +02:00
|
|
|
if (*test != '\0') {
|
2008-01-26 13:46:53 +01:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error_v(client, ACK_ERROR_ARG, fmt, args);
|
2008-01-26 13:46:53 +01:00
|
|
|
va_end(args);
|
2008-10-22 21:41:54 +02:00
|
|
|
return false;
|
2008-01-26 13:46:53 +01:00
|
|
|
}
|
2008-10-23 09:54:10 +02:00
|
|
|
|
2009-10-18 01:24:45 +02:00
|
|
|
#if G_MAXLONG > G_MAXINT
|
|
|
|
if (value < G_MININT || value > G_MAXINT) {
|
2008-10-23 09:54:10 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number too large: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*value_r = (int)value;
|
2008-10-22 21:41:54 +02:00
|
|
|
return true;
|
2008-01-26 13:46:53 +01:00
|
|
|
}
|
|
|
|
|
2009-01-09 17:06:40 +01:00
|
|
|
static bool G_GNUC_PRINTF(5, 6)
|
2009-01-10 17:39:49 +01:00
|
|
|
check_range(struct client *client, unsigned *value_r1, unsigned *value_r2,
|
2009-01-09 17:06:40 +01:00
|
|
|
const char *s, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *test, *test2;
|
|
|
|
long value;
|
|
|
|
|
|
|
|
value = strtol(s, &test, 10);
|
|
|
|
if (*test != '\0' && *test != ':') {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
command_error_v(client, ACK_ERROR_ARG, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:11:11 +01:00
|
|
|
if (value == -1 && *test == 0) {
|
|
|
|
/* compatibility with older MPD versions: specifying
|
|
|
|
"-1" makes MPD display the whole list */
|
|
|
|
*value_r1 = 0;
|
2009-10-18 01:24:45 +02:00
|
|
|
*value_r2 = G_MAXUINT;
|
2009-01-11 17:11:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-10 17:39:49 +01:00
|
|
|
if (value < 0) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number is negative: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-18 01:24:45 +02:00
|
|
|
#if G_MAXLONG > G_MAXUINT
|
|
|
|
if (value > G_MAXUINT) {
|
2009-01-09 17:06:40 +01:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number too large: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-10 17:39:49 +01:00
|
|
|
*value_r1 = (unsigned)value;
|
2009-01-09 17:06:40 +01:00
|
|
|
|
|
|
|
if (*test == ':') {
|
|
|
|
value = strtol(++test, &test2, 10);
|
2009-10-18 01:24:49 +02:00
|
|
|
if (*test2 != '\0') {
|
2009-01-09 17:06:40 +01:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
command_error_v(client, ACK_ERROR_ARG, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-10 17:39:49 +01:00
|
|
|
|
2009-10-18 01:24:49 +02:00
|
|
|
if (test == test2)
|
|
|
|
value = G_MAXUINT;
|
|
|
|
|
2009-01-10 17:39:49 +01:00
|
|
|
if (value < 0) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number is negative: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-18 01:24:45 +02:00
|
|
|
#if G_MAXLONG > G_MAXUINT
|
|
|
|
if (value > G_MAXUINT) {
|
2009-01-09 17:06:40 +01:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number too large: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2009-01-10 17:39:49 +01:00
|
|
|
*value_r2 = (unsigned)value;
|
|
|
|
} else {
|
|
|
|
*value_r2 = (unsigned)value + 1;
|
2009-01-09 17:06:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-23 09:53:35 +02:00
|
|
|
static bool
|
|
|
|
check_unsigned(struct client *client, unsigned *value_r, const char *s)
|
|
|
|
{
|
|
|
|
unsigned long value;
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
value = strtoul(s, &endptr, 10);
|
|
|
|
if (*endptr != 0) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Integer expected: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-18 01:24:45 +02:00
|
|
|
if (value > G_MAXUINT) {
|
2008-10-23 09:53:35 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Number too large: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value_r = (unsigned)value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
check_bool(struct client *client, bool *value_r, const char *s)
|
|
|
|
{
|
|
|
|
long value;
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
value = strtol(s, &endptr, 10);
|
2008-10-23 18:06:05 +02:00
|
|
|
if (*endptr != 0 || (value != 0 && value != 1)) {
|
2008-10-23 09:53:35 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Boolean (0/1) expected: %s", s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value_r = !!value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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:
|
2008-11-22 14:57:00 +01:00
|
|
|
command_error(client, ACK_ERROR_SYSTEM, "%s", 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:
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
strftime(timestamp, sizeof(timestamp), "%FT%TZ",
|
2008-12-29 17:28:13 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
gmtime(&t)
|
|
|
|
#else
|
|
|
|
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
|
|
|
{
|
2008-10-17 17:53:43 +02:00
|
|
|
if (client_get_uid(client) > 0)
|
|
|
|
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
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (argc == 2 && !check_int(client, &song, argv[1], need_positive))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-29 00:07:01 +02:00
|
|
|
result = playlist_play(&g_playlist, 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
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-01-26 13:46:53 +01:00
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
result = playlist_play_id(&g_playlist, 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-07-29 00:07:01 +02:00
|
|
|
playlist_stop(&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-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);
|
2009-01-24 14:52:04 +01:00
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
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-10-08 21:12:57 +02:00
|
|
|
pc_set_pause(pause_flag);
|
|
|
|
} else
|
|
|
|
pc_pause();
|
|
|
|
|
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-10-08 20:48:07 +02:00
|
|
|
pc_get_status(&player_status);
|
|
|
|
|
|
|
|
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"
|
|
|
|
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-10-08 21:12:57 +02:00
|
|
|
(int)(pc_get_cross_fade() + 0.5),
|
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-10-08 21:12:57 +02:00
|
|
|
error = pc_get_error_message();
|
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) {
|
2009-01-03 12:29:42 +01:00
|
|
|
#ifdef WIN32
|
2008-12-30 19:14:13 +01:00
|
|
|
result = PLAYLIST_RESULT_DENIED;
|
|
|
|
#else
|
2009-02-04 18:56:41 +01:00
|
|
|
result = playlist_append_file(&g_playlist,
|
|
|
|
uri + 7, client_get_uid(client),
|
2008-10-15 22:35:13 +02:00
|
|
|
NULL);
|
2008-12-30 19:14:13 +01:00
|
|
|
#endif
|
2008-10-15 22:35:13 +02:00
|
|
|
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-07-14 21:28:36 +02:00
|
|
|
result = playlist_append_uri(&g_playlist, uri, NULL);
|
2009-03-14 14:33:19 +01:00
|
|
|
return print_playlist_result(client, result);
|
2008-12-16 21:23:29 +01:00
|
|
|
}
|
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
result = addAllIn(uri);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (result == (enum playlist_result)-1) {
|
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
|
|
|
}
|
|
|
|
|
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_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) {
|
2009-01-03 12:29:42 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
result = PLAYLIST_RESULT_DENIED;
|
|
|
|
#else
|
2009-02-04 18:56:41 +01:00
|
|
|
result = playlist_append_file(&g_playlist, uri + 7,
|
2008-10-17 17:53:43 +02:00
|
|
|
client_get_uid(client),
|
2008-10-15 22:35:13 +02:00
|
|
|
&added_id);
|
2009-01-03 12:29:42 +01:00
|
|
|
#endif
|
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-07-14 21:28:36 +02:00
|
|
|
result = playlist_append_uri(&g_playlist, 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) {
|
|
|
|
int to;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &to, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_move_id(&g_playlist, 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-07-14 21:28:36 +02:00
|
|
|
playlist_delete_id(&g_playlist, 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
|
|
|
|
2009-09-30 23:13:13 +02:00
|
|
|
if (!check_range(client, &start, &end, argv[1], need_range))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-09-30 23:13:13 +02:00
|
|
|
result = playlist_delete_range(&g_playlist, 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
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int id;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &id, argv[1], need_positive))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_delete_id(&g_playlist, 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);
|
|
|
|
if (argc == 2 && !check_range(client, &start, &end,
|
|
|
|
argv[1], need_range))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_shuffle(&g_playlist, 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-07-14 21:28:36 +02:00
|
|
|
playlist_clear(&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-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
|
2008-11-24 14:55:32 +01:00
|
|
|
handle_load(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2009-10-13 18:53:33 +02:00
|
|
|
result = playlist_open_into_queue(argv[1], &g_playlist);
|
|
|
|
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
|
|
|
|
return result;
|
|
|
|
|
2009-02-04 18:56:41 +01:00
|
|
|
result = playlist_load_spl(&g_playlist, argv[1]);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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;
|
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
bool ret;
|
2008-09-07 13:44:20 +02:00
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
ret = spl_print(client, argv[1], false);
|
|
|
|
if (!ret) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
|
2009-02-04 21:04:30 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2008-09-07 13:44:20 +02:00
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
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;
|
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
bool ret;
|
2008-09-07 13:44:20 +02:00
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
ret = spl_print(client, argv[1], true);
|
|
|
|
if (!ret) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
|
2009-02-04 21:04:30 +01:00
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2008-09-07 13:44:20 +02:00
|
|
|
|
2009-02-04 21:04:30 +01:00
|
|
|
return COMMAND_RETURN_OK;
|
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;
|
2008-10-08 11:07:39 +02:00
|
|
|
const struct directory *directory;
|
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
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
directory = db_get_directory(uri);
|
2008-10-08 11:07:39 +02:00
|
|
|
if (directory == NULL) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory not found");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:49:01 +02:00
|
|
|
}
|
2007-05-24 19:06:59 +02:00
|
|
|
|
2008-10-08 11:07:39 +02:00
|
|
|
directory_print(client, directory);
|
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
if (isRootDirectory(uri)) {
|
2008-10-22 19:16:35 +02:00
|
|
|
GPtrArray *list = spl_list();
|
|
|
|
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
|
|
|
{
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2008-10-23 09:54:32 +02:00
|
|
|
result = spl_delete(argv[1]);
|
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_rename(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2007-05-24 20:07:19 +02:00
|
|
|
{
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2008-10-22 17:21:59 +02:00
|
|
|
result = spl_rename(argv[1], argv[2]);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_uint32(client, &version, argv[1], need_positive))
|
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
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_uint32(client, &version, argv[1], need_positive))
|
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
|
|
|
|
2009-01-10 17:39:49 +01:00
|
|
|
if (argc == 2 && !check_range(client, &start, &end,
|
|
|
|
argv[1], need_range))
|
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
|
|
|
{
|
2009-02-04 22:09:04 +01:00
|
|
|
int id = -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-01-24 14:52:04 +01:00
|
|
|
if (id >= 0) {
|
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
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret;
|
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
|
|
|
}
|
|
|
|
|
2009-01-24 15:56:34 +01:00
|
|
|
ret = findSongsIn(client, NULL, list);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
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[])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = findAddIn(client, NULL, list);
|
|
|
|
if (ret == -1)
|
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret;
|
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
|
|
|
}
|
|
|
|
|
2009-01-24 15:56:34 +01:00
|
|
|
ret = searchForSongsIn(client, NULL, list);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int ret;
|
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
|
|
|
}
|
|
|
|
|
2009-01-24 15:56:34 +01:00
|
|
|
ret = searchStatsForSongsIn(client, NULL, list);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
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];
|
|
|
|
int from;
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &from, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2008-10-22 17:21:59 +02:00
|
|
|
result = spl_remove_index(playlist, from);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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];
|
|
|
|
int from, to;
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &from, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &to, argv[3], check_integer, argv[3]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2007-05-16 14:02:10 +02:00
|
|
|
|
2008-10-22 17:21:59 +02:00
|
|
|
result = spl_move_index(playlist, from, to);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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-07-29 00:07:01 +02:00
|
|
|
playlist_next(&g_playlist);
|
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-07-29 00:07:01 +02:00
|
|
|
playlist_previous(&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_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
char *directory = NULL;
|
2008-09-07 13:48:37 +02:00
|
|
|
int ret;
|
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
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
ret = printAllIn(client, directory);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
2008-09-07 13:48:37 +02: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_setvol(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2009-03-14 11:10:21 +01:00
|
|
|
int level;
|
|
|
|
bool success;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &level, argv[1], need_integer))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:50:16 +02:00
|
|
|
|
2009-07-06 21:52:10 +02:00
|
|
|
if (level < 0 || level > 100) {
|
|
|
|
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
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int status;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &status, argv[1], need_integer))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
|
|
|
|
if (status != 0 && status != 1) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"%i\" is not 0 or 1", status);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
}
|
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_set_repeat(&g_playlist, 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
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!check_int(client, &status, argv[1], need_integer))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
if (status != 0 && status != 1) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"%i\" is not 0 or 1", status);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_set_single(&g_playlist, 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[])
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!check_int(client, &status, argv[1], need_integer))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
if (status != 0 && status != 1) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"%i\" is not 0 or 1", status);
|
|
|
|
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
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int status;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &status, argv[1], need_integer))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
|
|
|
|
if (status != 0 && status != 1) {
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"%i\" is not 0 or 1", status);
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:38:59 +02:00
|
|
|
}
|
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_set_random(&g_playlist, 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-10-08 21:12:57 +02:00
|
|
|
pc_clear_error();
|
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
|
|
|
int ret;
|
|
|
|
|
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
|
|
|
|
2009-01-24 15:56:34 +01:00
|
|
|
ret = listAllUniqueTags(client, tagType, conditionals);
|
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
|
|
|
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
2008-09-07 13:48:37 +02: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
|
|
|
|
2009-03-26 22:02:56 +01:00
|
|
|
if (!check_range(client, &start, &end,
|
|
|
|
argv[1], need_range))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &to, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_move_range(&g_playlist, 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
|
|
|
{
|
2008-01-26 13:46:53 +01:00
|
|
|
int id, to;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &id, argv[1], check_integer, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &to, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_move_id(&g_playlist, 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
|
|
|
{
|
2008-01-26 13:46:53 +01:00
|
|
|
int song1, song2;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &song1, argv[1], check_integer, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &song2, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_swap_songs(&g_playlist, 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
|
|
|
{
|
2008-01-26 13:46:53 +01:00
|
|
|
int id1, id2;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &id1, argv[1], check_integer, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &id2, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2009-07-14 21:28:36 +02:00
|
|
|
result = playlist_swap_songs_id(&g_playlist, 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
|
|
|
{
|
2008-01-26 13:46:53 +01:00
|
|
|
int song, seek_time;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &song, argv[1], check_integer, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &seek_time, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
result = playlist_seek_song(&g_playlist, 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
|
|
|
{
|
2008-01-26 13:46:53 +01:00
|
|
|
int id, seek_time;
|
2008-09-07 13:39:31 +02:00
|
|
|
enum playlist_result result;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &id, argv[1], check_integer, argv[1]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-10-22 21:41:54 +02:00
|
|
|
if (!check_int(client, &seek_time, argv[2], check_integer, argv[2]))
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_ERROR;
|
2008-09-07 13:39:31 +02:00
|
|
|
|
2009-07-29 00:07:01 +02:00
|
|
|
result = playlist_seek_song_id(&g_playlist, 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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
char *directory = NULL;
|
2008-09-07 13:48:37 +02:00
|
|
|
int ret;
|
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
|
|
|
|
2008-09-07 13:53:55 +02:00
|
|
|
ret = printInfoForAllIn(client, directory);
|
2008-09-07 13:48:37 +02:00
|
|
|
if (ret == -1)
|
2008-09-07 13:52:48 +02:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"directory or file not found");
|
2008-09-07 13:48:37 +02:00
|
|
|
|
|
|
|
return ret;
|
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-10-08 21:12:57 +02:00
|
|
|
pc_set_cross_fade(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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
|
|
|
|
2008-10-22 17:23:58 +02:00
|
|
|
result = spl_clear(argv[1]);
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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];
|
2008-09-07 13:44:12 +02:00
|
|
|
enum playlist_result result;
|
2006-12-07 15:41:40 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:19:45 +01:00
|
|
|
result = spl_append_uri(uri, playlist);
|
2008-12-16 21:23:29 +01:00
|
|
|
} else
|
2009-01-04 16:19:45 +01:00
|
|
|
result = addAllInToStoredPlaylist(uri, playlist);
|
2008-09-07 13:48:37 +02:00
|
|
|
|
|
|
|
if (result == (enum playlist_result)-1) {
|
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
|
|
|
}
|
|
|
|
|
2008-09-07 13:52:48 +02:00
|
|
|
return print_playlist_result(client, result);
|
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
|
|
|
{
|
|
|
|
GPtrArray *list = spl_list();
|
|
|
|
if (list == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_SYSTEM,
|
|
|
|
"failed to get list of stored playlists");
|
2008-10-22 21:41:49 +02:00
|
|
|
return COMMAND_RETURN_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);
|
2009-03-14 14:20:04 +01:00
|
|
|
if (NULL == sticker) {
|
2009-03-03 07:49:23 +01:00
|
|
|
command_error(client, ACK_ERROR_NO_EXIST,
|
|
|
|
"no stickers found");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2009-03-14 14:20:04 +01:00
|
|
|
|
2009-04-01 17:30:56 +02:00
|
|
|
sticker_print(client, sticker);
|
2009-03-14 14:20:04 +01:00
|
|
|
sticker_free(sticker);
|
2009-03-03 07:49:23 +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],
|
|
|
|
};
|
|
|
|
|
|
|
|
directory = db_get_directory(argv[3]);
|
|
|
|
if (directory == NULL) {
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
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 },
|
|
|
|
{ "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 },
|
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 },
|
|
|
|
{ "load", PERMISSION_ADD, 1, 1, handle_load },
|
|
|
|
{ "lsinfo", PERMISSION_READ, 0, 1, handle_lsinfo },
|
|
|
|
{ "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 },
|
|
|
|
{ "random", PERMISSION_CONTROL, 1, 1, handle_random },
|
|
|
|
{ "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 },
|
2009-09-24 21:55:40 +02:00
|
|
|
{ "rescan", PERMISSION_ADMIN, 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 },
|
|
|
|
{ "seek", PERMISSION_CONTROL, 2, 2, handle_seek },
|
|
|
|
{ "seekid", PERMISSION_CONTROL, 2, 2, handle_seekid },
|
|
|
|
{ "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 },
|
|
|
|
{ "swap", PERMISSION_CONTROL, 2, 2, handle_swap },
|
|
|
|
{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
|
|
|
|
{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
|
|
|
|
{ "update", PERMISSION_ADMIN, 0, 1, handle_update },
|
|
|
|
{ "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
|
|
|
{
|
2004-06-04 03:58:31 +02:00
|
|
|
static char unknown[] = "";
|
2008-10-22 09:59:01 +02:00
|
|
|
const struct command *cmd;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-06-04 03:58:31 +02:00
|
|
|
current_command = unknown;
|
|
|
|
|
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
|
|
|
}
|