diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-21 10:52:49 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-08-21 10:52:49 +0200 |
commit | e6600b8562b37cf76c033c3f54aae6ee7e940915 (patch) | |
tree | d461c10b5ba5139f78554eee2c3dc0704ec286ac /src/command/AllCommands.cxx | |
parent | 04e2d084176b2571dc9ea37a1e4378ad833229b8 (diff) | |
parent | bc89ca92b402a0e1fae29c0450298b7e6634f75b (diff) |
Merge tag 'v0.21.14'
release v0.21.14
Diffstat (limited to 'src/command/AllCommands.cxx')
-rw-r--r-- | src/command/AllCommands.cxx | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 005d6245e..b8906f7cc 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -212,9 +212,10 @@ static constexpr struct command commands[] = { static constexpr unsigned num_commands = std::size(commands); +gcc_pure static bool command_available(gcc_unused const Partition &partition, - gcc_unused const struct command *cmd) + gcc_unused const struct command *cmd) noexcept { #ifdef ENABLE_SQLITE if (StringIsEqual(cmd->cmd, "sticker")) @@ -241,7 +242,7 @@ command_available(gcc_unused const Partition &partition, static CommandResult PrintAvailableCommands(Response &r, const Partition &partition, - unsigned permission) + unsigned permission) noexcept { for (unsigned i = 0; i < num_commands; ++i) { const struct command *cmd = &commands[i]; @@ -255,7 +256,7 @@ PrintAvailableCommands(Response &r, const Partition &partition, } static CommandResult -PrintUnavailableCommands(Response &r, unsigned permission) +PrintUnavailableCommands(Response &r, unsigned permission) noexcept { for (unsigned i = 0; i < num_commands; ++i) { const struct command *cmd = &commands[i]; @@ -282,7 +283,7 @@ handle_not_commands(Client &client, gcc_unused Request request, Response &r) } void -command_init() +command_init() noexcept { #ifndef NDEBUG /* ensure that the command list is sorted */ @@ -291,8 +292,9 @@ command_init() #endif } +gcc_pure static const struct command * -command_lookup(const char *name) +command_lookup(const char *name) noexcept { unsigned a = 0, b = num_commands, i; @@ -314,7 +316,7 @@ command_lookup(const char *name) static bool command_check_request(const struct command *cmd, Response &r, - unsigned permission, Request args) + unsigned permission, Request args) noexcept { if (cmd->permission != (permission & cmd->permission)) { r.FormatError(ACK_ERROR_PERMISSION, @@ -348,7 +350,7 @@ command_check_request(const struct command *cmd, Response &r, static const struct command * command_checked_lookup(Response &r, unsigned permission, - const char *cmd_name, Request args) + const char *cmd_name, Request args) noexcept { const struct command *cmd = command_lookup(cmd_name); if (cmd == nullptr) { @@ -366,8 +368,8 @@ command_checked_lookup(Response &r, unsigned permission, } CommandResult -command_process(Client &client, unsigned num, char *line) -try { +command_process(Client &client, unsigned num, char *line) noexcept +{ Response r(client, num); /* get the command name (first word on the line) */ @@ -395,34 +397,33 @@ try { char *argv[COMMAND_ARGV_MAX]; Request args(argv, 0); - /* now parse the arguments (quoted or unquoted) */ - - while (true) { - if (args.size == COMMAND_ARGV_MAX) { - r.Error(ACK_ERROR_ARG, "Too many arguments"); - return CommandResult::ERROR; - } + try { + /* now parse the arguments (quoted or unquoted) */ - char *a = tokenizer.NextParam(); - if (a == nullptr) - break; + while (true) { + if (args.size == COMMAND_ARGV_MAX) { + r.Error(ACK_ERROR_ARG, "Too many arguments"); + return CommandResult::ERROR; + } - argv[args.size++] = a; - } + char *a = tokenizer.NextParam(); + if (a == nullptr) + break; - /* look up and invoke the command handler */ + argv[args.size++] = a; + } - const struct command *cmd = - command_checked_lookup(r, client.GetPermission(), - cmd_name, args); + /* look up and invoke the command handler */ - CommandResult ret = cmd - ? cmd->handler(client, args, r) - : CommandResult::ERROR; + const struct command *cmd = + command_checked_lookup(r, client.GetPermission(), + cmd_name, args); + if (cmd == nullptr) + return CommandResult::ERROR; - return ret; -} catch (const std::exception &e) { - Response r(client, num); - PrintError(r, std::current_exception()); - return CommandResult::ERROR; + return cmd->handler(client, args, r); + } catch (...) { + PrintError(r, std::current_exception()); + return CommandResult::ERROR; + } } |