Idle: error out when unrecognized idle event was specified
Implements the error checks missing in commit 0bad8406
This commit is contained in:
parent
ac286ef734
commit
570b12ec13
1
NEWS
1
NEWS
@ -4,6 +4,7 @@ ver 0.19 (not yet released)
|
|||||||
- "lsinfo" and "readcomments" allowed for remote files
|
- "lsinfo" and "readcomments" allowed for remote files
|
||||||
- "listneighbors" lists file servers on the local network
|
- "listneighbors" lists file servers on the local network
|
||||||
- "playlistadd" supports file:///
|
- "playlistadd" supports file:///
|
||||||
|
- "idle" with unrecognized event name fails
|
||||||
* database
|
* database
|
||||||
- proxy: forward "idle" events
|
- proxy: forward "idle" events
|
||||||
- proxy: copy "Last-Modified" from remote directories
|
- proxy: copy "Last-Modified" from remote directories
|
||||||
|
13
src/Idle.cxx
13
src/Idle.cxx
@ -25,6 +25,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "GlobalEvents.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
#include "util/ASCII.hxx"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
@ -70,3 +71,15 @@ idle_get_names(void)
|
|||||||
{
|
{
|
||||||
return idle_names;
|
return idle_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned
|
||||||
|
idle_parse_name(const char *name)
|
||||||
|
{
|
||||||
|
assert(name != nullptr);
|
||||||
|
|
||||||
|
for (unsigned i = 0; idle_names[i] != nullptr; ++i)
|
||||||
|
if (StringEqualsCaseASCII(name, idle_names[i]))
|
||||||
|
return 1 << i;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
10
src/Idle.hxx
10
src/Idle.hxx
@ -25,6 +25,8 @@
|
|||||||
#ifndef MPD_IDLE_HXX
|
#ifndef MPD_IDLE_HXX
|
||||||
#define MPD_IDLE_HXX
|
#define MPD_IDLE_HXX
|
||||||
|
|
||||||
|
#include "Compiler.h"
|
||||||
|
|
||||||
/** song database has been updated*/
|
/** song database has been updated*/
|
||||||
static constexpr unsigned IDLE_DATABASE = 0x1;
|
static constexpr unsigned IDLE_DATABASE = 0x1;
|
||||||
|
|
||||||
@ -81,4 +83,12 @@ idle_get(void);
|
|||||||
const char*const*
|
const char*const*
|
||||||
idle_get_names(void);
|
idle_get_names(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse an idle name and return its mask. Returns 0 if the given
|
||||||
|
* name is unknown.
|
||||||
|
*/
|
||||||
|
gcc_nonnull_all gcc_pure
|
||||||
|
unsigned
|
||||||
|
idle_parse_name(const char *name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include "protocol/Result.hxx"
|
#include "protocol/Result.hxx"
|
||||||
#include "ls.hxx"
|
#include "ls.hxx"
|
||||||
#include "mixer/Volume.hxx"
|
#include "mixer/Volume.hxx"
|
||||||
#include "util/ASCII.hxx"
|
|
||||||
#include "util/UriUtil.hxx"
|
#include "util/UriUtil.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
@ -363,17 +362,19 @@ CommandResult
|
|||||||
handle_idle(Client &client,
|
handle_idle(Client &client,
|
||||||
gcc_unused int argc, gcc_unused char *argv[])
|
gcc_unused int argc, gcc_unused char *argv[])
|
||||||
{
|
{
|
||||||
unsigned flags = 0, j;
|
unsigned flags = 0;
|
||||||
int i;
|
int i;
|
||||||
const char *const* idle_names;
|
|
||||||
|
|
||||||
idle_names = idle_get_names();
|
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
for (j = 0; idle_names[j]; ++j) {
|
unsigned event = idle_parse_name(argv[i]);
|
||||||
if (StringEqualsCaseASCII(argv[i], idle_names[j])) {
|
if (event == 0) {
|
||||||
flags |= (1 << j);
|
command_error(client, ACK_ERROR_ARG,
|
||||||
}
|
"Unrecognized idle event: %s",
|
||||||
|
argv[i]);
|
||||||
|
return CommandResult::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags |= event;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No argument means that the client wants to receive everything */
|
/* No argument means that the client wants to receive everything */
|
||||||
|
Loading…
Reference in New Issue
Block a user