aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/DatabaseCommands.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-08-06 22:10:25 +0200
committerMax Kellermann <max@duempel.org>2015-08-12 08:41:05 +0200
commit7652a2986b0d0ad55b2776685130f1c68d7108c7 (patch)
treeb4d45e60e97757454f1ff8e4dc793a1e7d852c36 /src/command/DatabaseCommands.cxx
parentb1480167be487d09ff46bb86ad02041fb28acff1 (diff)
downloadmpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.tar.gz
mpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.tar.xz
mpd-7652a2986b0d0ad55b2776685130f1c68d7108c7.zip
client/Response: new Client wrapper class for writing responses
Diffstat (limited to '')
-rw-r--r--src/command/DatabaseCommands.cxx82
1 files changed, 52 insertions, 30 deletions
diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx
index 6e6f3399b..62764139e 100644
--- a/src/command/DatabaseCommands.cxx
+++ b/src/command/DatabaseCommands.cxx
@@ -28,11 +28,11 @@
#include "db/Selection.hxx"
#include "CommandError.hxx"
#include "client/Client.hxx"
+#include "client/Response.hxx"
#include "tag/Tag.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "SongFilter.hxx"
-#include "protocol/Result.hxx"
#include "BulkEdit.hxx"
#include <string.h>
@@ -40,11 +40,13 @@
CommandResult
handle_listfiles_db(Client &client, const char *uri)
{
+ Response r(client);
const DatabaseSelection selection(uri, false);
Error error;
- if (!db_selection_print(client, selection, false, true, error))
- return print_error(client, error);
+ if (!db_selection_print(r, client.partition,
+ selection, false, true, error))
+ return print_error(r, error);
return CommandResult::OK;
}
@@ -52,14 +54,17 @@ handle_listfiles_db(Client &client, const char *uri)
CommandResult
handle_lsinfo2(Client &client, Request args)
{
+ Response r(client);
+
/* default is root directory */
const auto uri = args.GetOptional(0, "");
const DatabaseSelection selection(uri, false);
Error error;
- if (!db_selection_print(client, selection, true, false, error))
- return print_error(client, error);
+ if (!db_selection_print(r, client.partition,
+ selection, true, false, error))
+ return print_error(r, error);
return CommandResult::OK;
}
@@ -67,9 +72,11 @@ handle_lsinfo2(Client &client, Request args)
static CommandResult
handle_match(Client &client, Request args, bool fold_case)
{
+ Response r(client);
+
RangeArg window;
if (args.size >= 2 && strcmp(args[args.size - 2], "window") == 0) {
- if (!args.Parse(args.size - 1, window, client))
+ if (!args.Parse(args.size - 1, window, r))
return CommandResult::ERROR;
args.pop_back();
@@ -79,17 +86,18 @@ handle_match(Client &client, Request args, bool fold_case)
SongFilter filter;
if (!filter.Parse(args, fold_case)) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
const DatabaseSelection selection("", true, &filter);
Error error;
- return db_selection_print(client, selection, true, false,
+ return db_selection_print(r, client.partition,
+ selection, true, false,
window.start, window.end, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
@@ -107,9 +115,11 @@ handle_search(Client &client, Request args)
static CommandResult
handle_match_add(Client &client, Request args, bool fold_case)
{
+ Response r(client);
+
SongFilter filter;
if (!filter.Parse(args, fold_case)) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
@@ -119,7 +129,7 @@ handle_match_add(Client &client, Request args, bool fold_case)
Error error;
return AddFromDatabase(client.partition, selection, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
@@ -137,34 +147,38 @@ handle_searchadd(Client &client, Request args)
CommandResult
handle_searchaddpl(Client &client, Request args)
{
+ Response r(client);
+
const char *playlist = args.shift();
SongFilter filter;
if (!filter.Parse(args, true)) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
Error error;
const Database *db = client.GetDatabase(error);
if (db == nullptr)
- return print_error(client, error);
+ return print_error(r, error);
return search_add_to_playlist(*db, *client.GetStorage(),
"", playlist, &filter, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
handle_count(Client &client, Request args)
{
+ Response r(client);
+
TagType group = TAG_NUM_OF_ITEM_TYPES;
if (args.size >= 2 && strcmp(args[args.size - 2], "group") == 0) {
const char *s = args[args.size - 1];
group = tag_name_parse_i(s);
if (group == TAG_NUM_OF_ITEM_TYPES) {
- command_error(client, ACK_ERROR_ARG,
+ r.FormatError(ACK_ERROR_ARG,
"Unknown tag type: %s", s);
return CommandResult::ERROR;
}
@@ -175,38 +189,43 @@ handle_count(Client &client, Request args)
SongFilter filter;
if (!args.IsEmpty() && !filter.Parse(args, false)) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ r.Error(ACK_ERROR_ARG, "incorrect arguments");
return CommandResult::ERROR;
}
Error error;
- return PrintSongCount(client, "", &filter, group, error)
+ return PrintSongCount(r, client.partition, "", &filter, group, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
handle_listall(Client &client, Request args)
{
+ Response r(client);
+
/* default is root directory */
const auto uri = args.GetOptional(0, "");
Error error;
- return db_selection_print(client, DatabaseSelection(uri, true),
+ return db_selection_print(r, client.partition,
+ DatabaseSelection(uri, true),
false, false, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}
CommandResult
handle_list(Client &client, Request args)
{
+ Response r(client);
+
const char *tag_name = args.shift();
unsigned tagType = locate_parse_type(tag_name);
if (tagType >= TAG_NUM_OF_ITEM_TYPES &&
tagType != LOCATE_TAG_FILE_TYPE) {
- command_error(client, ACK_ERROR_ARG,
+ r.FormatError(ACK_ERROR_ARG,
"Unknown tag type: %s", tag_name);
return CommandResult::ERROR;
}
@@ -217,7 +236,7 @@ handle_list(Client &client, Request args)
if (args.size == 1) {
/* for compatibility with < 0.12.0 */
if (tagType != TAG_ALBUM) {
- command_error(client, ACK_ERROR_ARG,
+ r.FormatError(ACK_ERROR_ARG,
"should be \"%s\" for 3 arguments",
tag_item_names[TAG_ALBUM]);
return CommandResult::ERROR;
@@ -231,7 +250,7 @@ handle_list(Client &client, Request args)
const char *s = args[args.size - 1];
TagType gt = tag_name_parse_i(s);
if (gt == TAG_NUM_OF_ITEM_TYPES) {
- command_error(client, ACK_ERROR_ARG,
+ r.FormatError(ACK_ERROR_ARG,
"Unknown tag type: %s", s);
return CommandResult::ERROR;
}
@@ -246,8 +265,7 @@ handle_list(Client &client, Request args)
filter = new SongFilter();
if (!filter->Parse(args, false)) {
delete filter;
- command_error(client, ACK_ERROR_ARG,
- "not able to parse args");
+ r.Error(ACK_ERROR_ARG, "not able to parse args");
return CommandResult::ERROR;
}
}
@@ -255,15 +273,16 @@ handle_list(Client &client, Request args)
if (tagType < TAG_NUM_OF_ITEM_TYPES &&
group_mask & (1u << tagType)) {
delete filter;
- command_error(client, ACK_ERROR_ARG, "Conflicting group");
+ r.Error(ACK_ERROR_ARG, "Conflicting group");
return CommandResult::ERROR;
}
Error error;
CommandResult ret =
- PrintUniqueTags(client, tagType, group_mask, filter, error)
+ PrintUniqueTags(r, client.partition,
+ tagType, group_mask, filter, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
delete filter;
@@ -273,12 +292,15 @@ handle_list(Client &client, Request args)
CommandResult
handle_listallinfo(Client &client, Request args)
{
+ Response r(client);
+
/* default is root directory */
const auto uri = args.GetOptional(0, "");
Error error;
- return db_selection_print(client, DatabaseSelection(uri, true),
+ return db_selection_print(r, client.partition,
+ DatabaseSelection(uri, true),
true, false, error)
? CommandResult::OK
- : print_error(client, error);
+ : print_error(r, error);
}