This commit adds a new protocol command to toggle protocol features

for a client connection. It works like the tag_mask and the associated
tagtypes command.

New commands:

- protocol
  Shows enabled protocol features.

- protocol available
  Show all available protocol features.

- protocol enable {feature...}
  Enables protocol features.

- protocol disable {feature...}
  Disables protocol features.

- protocol all
  Enables all available protocol features.

- protocol clear
  Disables all protocol features.

This commit adds also the first protocol feature.

hide_playlists_in_root
  Disables the listing of playlists in the root folder
  for the lsinfo command.
This commit is contained in:
jcorporation
2024-09-28 16:36:43 +02:00
parent 124c0e66ee
commit 23c2bba483
10 changed files with 322 additions and 2 deletions

View File

@@ -156,6 +156,7 @@ static constexpr struct command commands[] = {
{ "previous", PERMISSION_PLAYER, 0, 0, handle_previous },
{ "prio", PERMISSION_PLAYER, 2, -1, handle_prio },
{ "prioid", PERMISSION_PLAYER, 2, -1, handle_prioid },
{ "protocol", PERMISSION_NONE, 0, -1, handle_protocol },
{ "random", PERMISSION_PLAYER, 1, 1, handle_random },
{ "rangeid", PERMISSION_ADD, 2, 2, handle_rangeid },
{ "readcomments", PERMISSION_READ, 1, 1, handle_read_comments },

View File

@@ -109,3 +109,67 @@ handle_tagtypes(Client &client, Request request, Response &r)
return CommandResult::ERROR;
}
}
static ProtocolFeature
ParseProtocolFeature(Request request)
{
if (request.empty())
throw ProtocolError(ACK_ERROR_ARG, "Not enough arguments");
ProtocolFeature result = ProtocolFeature::None();
for (const char *name : request) {
auto type = protocol_feature_parse_i(name);
if (type == PF_NUM_OF_ITEM_TYPES)
throw ProtocolError(ACK_ERROR_ARG, "Unknown protcol feature");
result |= type;
}
return result;
}
CommandResult
handle_protocol(Client &client, Request request, Response &r)
{
if (request.empty()) {
protocol_features_print(client, r);
return CommandResult::OK;
}
const char *cmd = request.shift();
if (StringIsEqual(cmd, "all")) {
if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR;
}
client.AllProtocolFeatures();
return CommandResult::OK;
} else if (StringIsEqual(cmd, "clear")) {
if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR;
}
client.ClearProtocolFeatures();
return CommandResult::OK;
} else if (StringIsEqual(cmd, "enable")) {
client.SetProtocolFeatures(ParseProtocolFeature(request), true);
return CommandResult::OK;
} else if (StringIsEqual(cmd, "disable")) {
client.SetProtocolFeatures(ParseProtocolFeature(request), false);
return CommandResult::OK;
} else if (StringIsEqual(cmd, "available")) {
if (!request.empty()) {
r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR;
}
protocol_features_print_all(r);
return CommandResult::OK;
} else {
r.Error(ACK_ERROR_ARG, "Unknown sub command");
return CommandResult::ERROR;
}
}

View File

@@ -25,4 +25,7 @@ handle_password(Client &client, Request request, Response &response);
CommandResult
handle_tagtypes(Client &client, Request request, Response &response);
CommandResult
handle_protocol(Client &client, Request request, Response &response);
#endif

View File

@@ -160,7 +160,7 @@ handle_lsinfo_relative(Client &client, Response &r, const char *uri)
(void)client;
#endif
if (isRootDirectory(uri)) {
if (!client.ProtocolFeatureEnabled(PF_HIDE_PLAYLISTS_IN_ROOT) && isRootDirectory(uri)) {
try {
print_spl_list(r, ListPlaylistFiles());
} catch (...) {