Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
e118e958
Commit
e118e958
authored
Aug 11, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protocol/ArgParser: add overload with max_value parameter
parent
ee61dfe0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
31 deletions
+33
-31
OtherCommands.cxx
src/command/OtherCommands.cxx
+2
-12
QueueCommands.cxx
src/command/QueueCommands.cxx
+2
-14
ArgParser.cxx
src/protocol/ArgParser.cxx
+21
-5
ArgParser.hxx
src/protocol/ArgParser.hxx
+8
-0
No files found.
src/command/OtherCommands.cxx
View file @
e118e958
...
...
@@ -309,14 +309,9 @@ CommandResult
handle_setvol
(
Client
&
client
,
Request
args
)
{
unsigned
level
;
if
(
!
ParseCommandArg
(
client
,
level
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
level
,
args
.
front
()
,
100
))
return
CommandResult
::
ERROR
;
if
(
level
>
100
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Invalid volume value"
);
return
CommandResult
::
ERROR
;
}
if
(
!
volume_level_change
(
client
.
partition
.
outputs
,
level
))
{
command_error
(
client
,
ACK_ERROR_SYSTEM
,
"problems setting volume"
);
...
...
@@ -330,14 +325,9 @@ CommandResult
handle_volume
(
Client
&
client
,
Request
args
)
{
int
relative
;
if
(
!
ParseCommandArg
(
client
,
relative
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
relative
,
args
.
front
()
,
-
100
,
100
))
return
CommandResult
::
ERROR
;
if
(
relative
<
-
100
||
relative
>
100
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Invalid volume value"
);
return
CommandResult
::
ERROR
;
}
const
int
old_volume
=
volume_level_get
(
client
.
partition
.
outputs
);
if
(
old_volume
<
0
)
{
command_error
(
client
,
ACK_ERROR_SYSTEM
,
"No mixer"
);
...
...
src/command/QueueCommands.cxx
View file @
e118e958
...
...
@@ -314,15 +314,9 @@ handle_prio(Client &client, Request args)
{
const
char
*
const
priority_string
=
args
.
shift
();
unsigned
priority
;
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
))
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
,
0xff
))
return
CommandResult
::
ERROR
;
if
(
priority
>
0xff
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Priority out of range: %s"
,
priority_string
);
return
CommandResult
::
ERROR
;
}
for
(
const
char
*
i
:
args
)
{
RangeArg
range
;
if
(
!
ParseCommandArg
(
client
,
range
,
i
))
...
...
@@ -344,15 +338,9 @@ handle_prioid(Client &client, Request args)
{
const
char
*
const
priority_string
=
args
.
shift
();
unsigned
priority
;
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
))
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
,
0xff
))
return
CommandResult
::
ERROR
;
if
(
priority
>
0xff
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Priority out of range: %s"
,
priority_string
);
return
CommandResult
::
ERROR
;
}
for
(
const
char
*
i
:
args
)
{
unsigned
song_id
;
if
(
!
ParseCommandArg
(
client
,
song_id
,
i
))
...
...
src/protocol/ArgParser.cxx
View file @
e118e958
...
...
@@ -39,7 +39,8 @@ check_uint32(Client &client, uint32_t *dst, const char *s)
}
bool
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
,
int
min_value
,
int
max_value
)
{
char
*
test
;
long
value
;
...
...
@@ -51,8 +52,7 @@ ParseCommandArg(Client &client, int &value_r, const char *s)
return
false
;
}
if
(
value
<
std
::
numeric_limits
<
int
>::
min
()
||
value
>
std
::
numeric_limits
<
int
>::
max
())
{
if
(
value
<
min_value
||
value
>
max_value
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Number too large: %s"
,
s
);
return
false
;
...
...
@@ -63,6 +63,14 @@ ParseCommandArg(Client &client, int &value_r, const char *s)
}
bool
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
)
{
return
ParseCommandArg
(
client
,
value_r
,
s
,
std
::
numeric_limits
<
int
>::
min
(),
std
::
numeric_limits
<
int
>::
max
());
}
bool
ParseCommandArg
(
Client
&
client
,
RangeArg
&
value_r
,
const
char
*
s
)
{
char
*
test
,
*
test2
;
...
...
@@ -129,7 +137,8 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s)
}
bool
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
,
unsigned
max_value
)
{
unsigned
long
value
;
char
*
endptr
;
...
...
@@ -141,7 +150,7 @@ ParseCommandArg(Client &client, unsigned &value_r, const char *s)
return
false
;
}
if
(
value
>
std
::
numeric_limits
<
unsigned
>::
max
()
)
{
if
(
value
>
max_value
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Number too large: %s"
,
s
);
return
false
;
...
...
@@ -152,6 +161,13 @@ ParseCommandArg(Client &client, unsigned &value_r, const char *s)
}
bool
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
)
{
return
ParseCommandArg
(
client
,
value_r
,
s
,
std
::
numeric_limits
<
unsigned
>::
max
());
}
bool
ParseCommandArg
(
Client
&
client
,
bool
&
value_r
,
const
char
*
s
)
{
long
value
;
...
...
src/protocol/ArgParser.hxx
View file @
e118e958
...
...
@@ -34,6 +34,10 @@ bool
check_uint32
(
Client
&
client
,
uint32_t
*
dst
,
const
char
*
s
);
bool
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
,
int
min_value
,
int
max_value
);
bool
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
);
struct
RangeArg
{
...
...
@@ -49,6 +53,10 @@ bool
ParseCommandArg
(
Client
&
client
,
RangeArg
&
value_r
,
const
char
*
s
);
bool
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
,
unsigned
max_value
);
bool
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
);
bool
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment