aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-04-01 18:53:02 +0200
committerMax Kellermann <max@duempel.org>2009-04-01 18:53:02 +0200
commite720b5bdf8c9943d31f217dd52555f824be5d733 (patch)
treecfb1fabaf41570305b6eb9b4cfe2d42cd87269a2
parentc95fa4b441a445bcbe55707e74adfa22e783f732 (diff)
downloadmpd-e720b5bdf8c9943d31f217dd52555f824be5d733.tar.gz
mpd-e720b5bdf8c9943d31f217dd52555f824be5d733.tar.xz
mpd-e720b5bdf8c9943d31f217dd52555f824be5d733.zip
command: added command "sticker find"
This command allows clients to search for stickers with a specified name.
Diffstat (limited to '')
-rw-r--r--doc/protocol.xml19
-rw-r--r--src/command.c41
2 files changed, 60 insertions, 0 deletions
diff --git a/doc/protocol.xml b/doc/protocol.xml
index 0096ed672..7910f407f 100644
--- a/doc/protocol.xml
+++ b/doc/protocol.xml
@@ -1288,6 +1288,25 @@ OK
</para>
</listitem>
</varlistentry>
+ <varlistentry id="command_sticker_find">
+ <term>
+ <cmdsynopsis>
+ <command>sticker</command>
+ <arg choice="plain">find</arg>
+ <arg choice="req"><replaceable>TYPE</replaceable></arg>
+ <arg choice="req"><replaceable>URI</replaceable></arg>
+ <arg choice="req"><replaceable>NAME</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Searches the sticker database for stickers with the
+ specified name, below the specified directory (URI).
+ For each matching song, it prints the URI and that one
+ sticker's value.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</section>
diff --git a/src/command.c b/src/command.c
index aab63998e..2ad6362d7 100644
--- a/src/command.c
+++ b/src/command.c
@@ -50,6 +50,7 @@
#include "sticker.h"
#include "sticker_print.h"
#include "song_sticker.h"
+#include "song_print.h"
#endif
#include <assert.h>
@@ -1507,6 +1508,21 @@ handle_idle(struct client *client,
}
#ifdef ENABLE_SQLITE
+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;
+
+ song_print_url(data->client, song);
+ sticker_print_value(data->client, data->name, value);
+}
+
static enum command_return
handle_sticker_song(struct client *client, int argc, char *argv[])
{
@@ -1573,6 +1589,31 @@ handle_sticker_song(struct client *client, int argc, char *argv[])
}
return COMMAND_RETURN_OK;
+ } 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;
+ }
+
+ return COMMAND_RETURN_OK;
} else {
command_error(client, ACK_ERROR_ARG, "bad request");
return COMMAND_RETURN_ERROR;