aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-07 21:55:11 +0200
committerMax Kellermann <max@duempel.org>2012-08-07 22:36:18 +0200
commitf35ceaee0a3e05e9b00230cce4b553169c4c8712 (patch)
tree73e2f2f632a44cb3ec007d9554c2812cb76a834d
parenta64a2a65a9ee5756171a279a9f294f8e4731b330 (diff)
downloadmpd-f35ceaee0a3e05e9b00230cce4b553169c4c8712.tar.gz
mpd-f35ceaee0a3e05e9b00230cce4b553169c4c8712.tar.xz
mpd-f35ceaee0a3e05e9b00230cce4b553169c4c8712.zip
command: move code to DatabaseCommands.cxx
Prepare to use the DatabasePlugin C++ API directly.
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--src/DatabaseCommands.cxx286
-rw-r--r--src/DatabaseCommands.hxx59
-rw-r--r--src/command.c242
4 files changed, 350 insertions, 238 deletions
diff --git a/Makefile.am b/Makefile.am
index 1d3cfecf0..b601519ca 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -239,6 +239,7 @@ src_mpd_SOURCES = \
src/protocol/result.c src/protocol/result.h \
src/CommandError.cxx src/CommandError.h \
src/command.c \
+ src/DatabaseCommands.cxx \
src/idle.c \
src/cmdline.c \
src/conf.c \
diff --git a/src/DatabaseCommands.cxx b/src/DatabaseCommands.cxx
new file mode 100644
index 000000000..96cd8a5b5
--- /dev/null
+++ b/src/DatabaseCommands.cxx
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "DatabaseCommands.hxx"
+#include "CommandError.h"
+#include "client_internal.h"
+#include "tag.h"
+#include "uri.h"
+
+extern "C" {
+#include "db_print.h"
+#include "db_selection.h"
+#include "dbUtils.h"
+#include "locate.h"
+#include "protocol/result.h"
+}
+
+#include <assert.h>
+#include <string.h>
+
+enum command_return
+handle_lsinfo2(struct client *client, int argc, char *argv[])
+{
+ const char *uri;
+
+ if (argc == 2)
+ uri = argv[1];
+ else
+ /* default is root directory */
+ uri = "";
+
+ struct db_selection selection;
+ db_selection_init(&selection, uri, false);
+
+ GError *error = NULL;
+ if (!db_selection_print(client, &selection, true, &error))
+ return print_error(client, error);
+
+ return COMMAND_RETURN_OK;
+}
+
+enum command_return
+handle_find(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret = findSongsIn(client, "", list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_findadd(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret =
+ findAddIn(client->player_control, "", list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_search(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret = searchForSongsIn(client, "", list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_searchadd(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret = search_add_songs(client->player_control,
+ "", list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_searchaddpl(struct client *client, int argc, char *argv[])
+{
+ const char *playlist = argv[1];
+
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 2, argc - 2);
+
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret =
+ search_add_to_playlist("", playlist, list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_count(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ GError *error = NULL;
+ enum command_return ret =
+ searchStatsForSongsIn(client, "", list, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+enum command_return
+handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
+{
+ const char *directory = "";
+
+ if (argc == 2)
+ directory = argv[1];
+
+ GError *error = NULL;
+ return printAllIn(client, directory, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+}
+
+enum command_return
+handle_list(struct client *client, int argc, char *argv[])
+{
+ struct locate_item_list *conditionals;
+ int tagType = locate_parse_type(argv[1]);
+
+ if (tagType < 0) {
+ command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]);
+ return COMMAND_RETURN_ERROR;
+ }
+
+ if (tagType == LOCATE_TAG_ANY_TYPE) {
+ command_error(client, ACK_ERROR_ARG,
+ "\"any\" is not a valid return tag type");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ /* for compatibility with < 0.12.0 */
+ if (argc == 3) {
+ if (tagType != TAG_ALBUM) {
+ command_error(client, ACK_ERROR_ARG,
+ "should be \"%s\" for 3 arguments",
+ tag_item_names[TAG_ALBUM]);
+ return COMMAND_RETURN_ERROR;
+ }
+
+ locate_item_list_parse(argv + 1, argc - 1);
+
+ conditionals = locate_item_list_new(1);
+ conditionals->items[0].tag = TAG_ARTIST;
+ conditionals->items[0].needle = g_strdup(argv[2]);
+ } else {
+ conditionals =
+ locate_item_list_parse(argv + 2, argc - 2);
+ if (conditionals == NULL) {
+ command_error(client, ACK_ERROR_ARG,
+ "not able to parse args");
+ return COMMAND_RETURN_ERROR;
+ }
+ }
+
+ GError *error = NULL;
+ enum command_return ret =
+ listAllUniqueTags(client, tagType, conditionals, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+
+ locate_item_list_free(conditionals);
+
+ return ret;
+}
+
+enum command_return
+handle_listallinfo(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
+{
+ const char *directory = "";
+
+ if (argc == 2)
+ directory = argv[1];
+
+ GError *error = NULL;
+ return printInfoForAllIn(client, directory, &error)
+ ? COMMAND_RETURN_OK
+ : print_error(client, error);
+}
diff --git a/src/DatabaseCommands.hxx b/src/DatabaseCommands.hxx
new file mode 100644
index 000000000..24ff71329
--- /dev/null
+++ b/src/DatabaseCommands.hxx
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef MPD_DATABASE_COMMANDS_HXX
+#define MPD_DATABASE_COMMANDS_HXX
+
+#include "command.h"
+
+G_BEGIN_DECLS
+
+enum command_return
+handle_lsinfo2(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_find(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_findadd(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_search(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_searchadd(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_searchaddpl(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_count(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_listall(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_list(struct client *client, int argc, char *argv[]);
+
+enum command_return
+handle_listallinfo(struct client *client, int argc, char *argv[]);
+
+G_END_DECLS
+
+#endif
diff --git a/src/command.c b/src/command.c
index 88e6faf4c..08d508de7 100644
--- a/src/command.c
+++ b/src/command.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "command.h"
+#include "DatabaseCommands.hxx"
#include "CommandError.h"
#include "protocol/argparser.h"
#include "protocol/result.h"
@@ -45,9 +46,6 @@
#include "output_print.h"
#include "locate.h"
#include "dbUtils.h"
-#include "db_error.h"
-#include "db_print.h"
-#include "db_selection.h"
#include "db_lock.h"
#include "tag.h"
#include "client.h"
@@ -582,12 +580,9 @@ handle_lsinfo(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_OK;
}
- struct db_selection selection;
- db_selection_init(&selection, uri, false);
-
- GError *error = NULL;
- if (!db_selection_print(client, &selection, true, &error))
- return print_error(client, error);
+ enum command_return result = handle_lsinfo2(client, argc, argv);
+ if (result != COMMAND_RETURN_OK)
+ return result;
if (isRootDirectory(uri)) {
GPtrArray *list = spl_list(NULL);
@@ -679,155 +674,6 @@ handle_playlistid(struct client *client, int argc, char *argv[])
}
static enum command_return
-handle_find(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
-
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret = findSongsIn(client, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
-handle_findadd(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret =
- findAddIn(client->player_control, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
-handle_search(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
-
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret = searchForSongsIn(client, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
-handle_searchadd(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
-
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret = search_add_songs(client->player_control,
- "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
-handle_searchaddpl(struct client *client, int argc, char *argv[])
-{
- const char *playlist = argv[1];
-
- struct locate_item_list *list =
- locate_item_list_parse(argv + 2, argc - 2);
-
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret =
- search_add_to_playlist("", playlist, list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
-handle_count(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
-
- if (list == NULL || list->length == 0) {
- if (list != NULL)
- locate_item_list_free(list);
-
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret =
- searchStatsForSongsIn(client, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
-}
-
-static enum command_return
handle_playlistfind(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
@@ -1046,20 +892,6 @@ handle_prioid(struct client *client, int argc, char *argv[])
}
static enum command_return
-handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
-{
- const char *directory = "";
-
- if (argc == 2)
- directory = argv[1];
-
- GError *error = NULL;
- return printAllIn(client, directory, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-}
-
-static enum command_return
handle_setvol(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{
unsigned level;
@@ -1143,58 +975,6 @@ handle_clearerror(G_GNUC_UNUSED struct client *client,
}
static enum command_return
-handle_list(struct client *client, int argc, char *argv[])
-{
- struct locate_item_list *conditionals;
- int tagType = locate_parse_type(argv[1]);
-
- if (tagType < 0) {
- command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]);
- return COMMAND_RETURN_ERROR;
- }
-
- if (tagType == LOCATE_TAG_ANY_TYPE) {
- command_error(client, ACK_ERROR_ARG,
- "\"any\" is not a valid return tag type");
- return COMMAND_RETURN_ERROR;
- }
-
- /* for compatibility with < 0.12.0 */
- if (argc == 3) {
- if (tagType != TAG_ALBUM) {
- command_error(client, ACK_ERROR_ARG,
- "should be \"%s\" for 3 arguments",
- tag_item_names[TAG_ALBUM]);
- return COMMAND_RETURN_ERROR;
- }
-
- locate_item_list_parse(argv + 1, argc - 1);
-
- conditionals = locate_item_list_new(1);
- conditionals->items[0].tag = TAG_ARTIST;
- conditionals->items[0].needle = g_strdup(argv[2]);
- } else {
- conditionals =
- locate_item_list_parse(argv + 2, argc - 2);
- if (conditionals == NULL) {
- command_error(client, ACK_ERROR_ARG,
- "not able to parse args");
- return COMMAND_RETURN_ERROR;
- }
- }
-
- GError *error = NULL;
- enum command_return ret =
- listAllUniqueTags(client, tagType, conditionals, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(conditionals);
-
- return ret;
-}
-
-static enum command_return
handle_move(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{
unsigned start, end;
@@ -1304,20 +1084,6 @@ handle_seekcur(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
}
static enum command_return
-handle_listallinfo(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
-{
- const char *directory = "";
-
- if (argc == 2)
- directory = argv[1];
-
- GError *error = NULL;
- return printInfoForAllIn(client, directory, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-}
-
-static enum command_return
handle_ping(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{