diff options
author | Max Kellermann <max@duempel.org> | 2009-04-01 18:53:02 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-04-01 18:53:02 +0200 |
commit | e720b5bdf8c9943d31f217dd52555f824be5d733 (patch) | |
tree | cfb1fabaf41570305b6eb9b4cfe2d42cd87269a2 /src/command.c | |
parent | c95fa4b441a445bcbe55707e74adfa22e783f732 (diff) | |
download | mpd-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-- | src/command.c | 41 |
1 files changed, 41 insertions, 0 deletions
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; |