client: add tag_mask attribute
The "tagtypes" command now has several sub commands which can be used to edit that mask.
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#include "client/Client.hxx"
|
||||
#include "client/Response.hxx"
|
||||
#include "TagPrint.hxx"
|
||||
#include "tag/ParseName.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
|
||||
CommandResult
|
||||
handle_close(gcc_unused Client &client, gcc_unused Request args,
|
||||
@@ -53,10 +55,58 @@ handle_password(Client &client, Request args, Response &r)
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_tagtypes(gcc_unused Client &client, gcc_unused Request request,
|
||||
Response &r)
|
||||
static TagMask
|
||||
ParseTagMask(Request request)
|
||||
{
|
||||
tag_print_types(r);
|
||||
return CommandResult::OK;
|
||||
if (request.IsEmpty())
|
||||
throw ProtocolError(ACK_ERROR_ARG, "Not enough arguments");
|
||||
|
||||
TagMask result = TagMask::None();
|
||||
|
||||
for (const char *name : request) {
|
||||
auto type = tag_name_parse_i(name);
|
||||
if (type == TAG_NUM_OF_ITEM_TYPES)
|
||||
throw ProtocolError(ACK_ERROR_ARG, "Unknown tag type");
|
||||
|
||||
result |= type;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_tagtypes(Client &client, Request request, Response &r)
|
||||
{
|
||||
if (request.IsEmpty()) {
|
||||
tag_print_types(r);
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
const char *cmd = request.shift();
|
||||
if (StringIsEqual(cmd, "all")) {
|
||||
if (!request.IsEmpty()) {
|
||||
r.Error(ACK_ERROR_ARG, "Too many arguments");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
client.tag_mask = TagMask::All();
|
||||
return CommandResult::OK;
|
||||
} else if (StringIsEqual(cmd, "clear")) {
|
||||
if (!request.IsEmpty()) {
|
||||
r.Error(ACK_ERROR_ARG, "Too many arguments");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
client.tag_mask = TagMask::None();
|
||||
return CommandResult::OK;
|
||||
} else if (StringIsEqual(cmd, "enable")) {
|
||||
client.tag_mask |= ParseTagMask(request);
|
||||
return CommandResult::OK;
|
||||
} else if (StringIsEqual(cmd, "disable")) {
|
||||
client.tag_mask &= ~ParseTagMask(request);
|
||||
return CommandResult::OK;
|
||||
} else {
|
||||
r.Error(ACK_ERROR_ARG, "Unknown sub command");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user