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
9231f420
Commit
9231f420
authored
Aug 11, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protocol/ArgParser: overload as ParseCommandArg(), pass references
parent
0f92d021
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
71 deletions
+56
-71
OtherCommands.cxx
src/command/OtherCommands.cxx
+2
-2
OutputCommands.cxx
src/command/OutputCommands.cxx
+3
-3
PlayerCommands.cxx
src/command/PlayerCommands.cxx
+16
-20
PlaylistCommands.cxx
src/command/PlaylistCommands.cxx
+3
-5
QueueCommands.cxx
src/command/QueueCommands.cxx
+16
-25
TagCommands.cxx
src/command/TagCommands.cxx
+2
-2
ArgParser.cxx
src/protocol/ArgParser.cxx
+10
-10
ArgParser.hxx
src/protocol/ArgParser.hxx
+4
-4
No files found.
src/command/OtherCommands.cxx
View file @
9231f420
...
...
@@ -309,7 +309,7 @@ CommandResult
handle_setvol
(
Client
&
client
,
Request
args
)
{
unsigned
level
;
if
(
!
check_unsigned
(
client
,
&
level
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
level
,
args
.
front
()))
return
CommandResult
::
ERROR
;
if
(
level
>
100
)
{
...
...
@@ -330,7 +330,7 @@ CommandResult
handle_volume
(
Client
&
client
,
Request
args
)
{
int
relative
;
if
(
!
check_int
(
client
,
&
relative
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
relative
,
args
.
front
()))
return
CommandResult
::
ERROR
;
if
(
relative
<
-
100
||
relative
>
100
)
{
...
...
src/command/OutputCommands.cxx
View file @
9231f420
...
...
@@ -34,7 +34,7 @@ handle_enableoutput(Client &client, Request args)
assert
(
args
.
size
==
1
);
unsigned
device
;
if
(
!
check_unsigned
(
client
,
&
device
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
device
,
args
.
front
()))
return
CommandResult
::
ERROR
;
if
(
!
audio_output_enable_index
(
client
.
partition
.
outputs
,
device
))
{
...
...
@@ -52,7 +52,7 @@ handle_disableoutput(Client &client, Request args)
assert
(
args
.
size
==
1
);
unsigned
device
;
if
(
!
check_unsigned
(
client
,
&
device
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
device
,
args
.
front
()))
return
CommandResult
::
ERROR
;
if
(
!
audio_output_disable_index
(
client
.
partition
.
outputs
,
device
))
{
...
...
@@ -70,7 +70,7 @@ handle_toggleoutput(Client &client, Request args)
assert
(
args
.
size
==
1
);
unsigned
device
;
if
(
!
check_unsigned
(
client
,
&
device
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
device
,
args
.
front
()))
return
CommandResult
::
ERROR
;
if
(
!
audio_output_toggle_index
(
client
.
partition
.
outputs
,
device
))
{
...
...
src/command/PlayerCommands.cxx
View file @
9231f420
...
...
@@ -61,9 +61,9 @@ CommandResult
handle_play
(
Client
&
client
,
Request
args
)
{
int
song
=
-
1
;
if
(
!
args
.
IsEmpty
()
&&
!
check_int
(
client
,
&
song
,
args
.
front
()))
if
(
!
args
.
IsEmpty
()
&&
!
ParseCommandArg
(
client
,
song
,
args
.
front
()))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
PlayPosition
(
song
);
return
print_playlist_result
(
client
,
result
);
}
...
...
@@ -72,8 +72,7 @@ CommandResult
handle_playid
(
Client
&
client
,
Request
args
)
{
int
id
=
-
1
;
if
(
!
args
.
IsEmpty
()
&&
!
check_int
(
client
,
&
id
,
args
.
front
()))
if
(
!
args
.
IsEmpty
()
&&
!
ParseCommandArg
(
client
,
id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
PlayId
(
id
);
...
...
@@ -99,7 +98,7 @@ handle_pause(Client &client, Request args)
{
if
(
!
args
.
IsEmpty
())
{
bool
pause_flag
;
if
(
!
check_bool
(
client
,
&
pause_flag
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
pause_flag
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
player_control
.
SetPause
(
pause_flag
);
...
...
@@ -250,7 +249,7 @@ CommandResult
handle_repeat
(
Client
&
client
,
Request
args
)
{
bool
status
;
if
(
!
check_bool
(
client
,
&
status
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
status
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
partition
.
SetRepeat
(
status
);
...
...
@@ -261,7 +260,7 @@ CommandResult
handle_single
(
Client
&
client
,
Request
args
)
{
bool
status
;
if
(
!
check_bool
(
client
,
&
status
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
status
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
partition
.
SetSingle
(
status
);
...
...
@@ -272,7 +271,7 @@ CommandResult
handle_consume
(
Client
&
client
,
Request
args
)
{
bool
status
;
if
(
!
check_bool
(
client
,
&
status
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
status
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
partition
.
SetConsume
(
status
);
...
...
@@ -283,7 +282,7 @@ CommandResult
handle_random
(
Client
&
client
,
Request
args
)
{
bool
status
;
if
(
!
check_bool
(
client
,
&
status
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
status
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
partition
.
SetRandom
(
status
);
...
...
@@ -304,7 +303,7 @@ handle_seek(Client &client, Request args)
unsigned
song
;
SongTime
seek_time
;
if
(
!
check_unsigned
(
client
,
&
song
,
args
[
0
]))
if
(
!
ParseCommandArg
(
client
,
song
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
ParseCommandArg
(
client
,
seek_time
,
args
[
1
]))
return
CommandResult
::
ERROR
;
...
...
@@ -319,8 +318,7 @@ handle_seekid(Client &client, Request args)
{
unsigned
id
;
SongTime
seek_time
;
if
(
!
check_unsigned
(
client
,
&
id
,
args
[
0
]))
if
(
!
ParseCommandArg
(
client
,
id
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
ParseCommandArg
(
client
,
seek_time
,
args
[
1
]))
return
CommandResult
::
ERROR
;
...
...
@@ -348,11 +346,10 @@ CommandResult
handle_crossfade
(
Client
&
client
,
Request
args
)
{
unsigned
xfade_time
;
if
(
!
check_unsigned
(
client
,
&
xfade_time
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
xfade_time
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
player_control
.
SetCrossFade
(
xfade_time
);
client
.
player_control
.
SetCrossFade
(
xfade_time
);
return
CommandResult
::
OK
;
}
...
...
@@ -360,11 +357,10 @@ CommandResult
handle_mixrampdb
(
Client
&
client
,
Request
args
)
{
float
db
;
if
(
!
check_float
(
client
,
&
db
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
db
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
player_control
.
SetMixRampDb
(
db
);
client
.
player_control
.
SetMixRampDb
(
db
);
return
CommandResult
::
OK
;
}
...
...
@@ -372,9 +368,9 @@ CommandResult
handle_mixrampdelay
(
Client
&
client
,
Request
args
)
{
float
delay_secs
;
if
(
!
check_float
(
client
,
&
delay_secs
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
delay_secs
,
args
.
front
()))
return
CommandResult
::
ERROR
;
client
.
player_control
.
SetMixRampDelay
(
delay_secs
);
return
CommandResult
::
OK
;
...
...
src/command/PlaylistCommands.cxx
View file @
9231f420
...
...
@@ -146,8 +146,7 @@ handle_playlistdelete(Client &client, Request args)
{
const
char
*
const
name
=
args
[
0
];
unsigned
from
;
if
(
!
check_unsigned
(
client
,
&
from
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
from
,
args
[
1
]))
return
CommandResult
::
ERROR
;
Error
error
;
...
...
@@ -161,10 +160,9 @@ handle_playlistmove(Client &client, Request args)
{
const
char
*
const
name
=
args
.
front
();
unsigned
from
,
to
;
if
(
!
check_unsigned
(
client
,
&
from
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
from
,
args
[
1
]))
return
CommandResult
::
ERROR
;
if
(
!
check_unsigned
(
client
,
&
to
,
args
[
2
]))
if
(
!
ParseCommandArg
(
client
,
to
,
args
[
2
]))
return
CommandResult
::
ERROR
;
Error
error
;
...
...
src/command/QueueCommands.cxx
View file @
9231f420
...
...
@@ -105,7 +105,7 @@ handle_addid(Client &client, Request args)
if
(
args
.
size
==
2
)
{
unsigned
to
;
if
(
!
check_unsigned
(
client
,
&
to
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
to
,
args
[
1
]))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
MoveId
(
added_id
,
to
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
{
...
...
@@ -155,7 +155,7 @@ CommandResult
handle_rangeid
(
Client
&
client
,
Request
args
)
{
unsigned
id
;
if
(
!
check_unsigned
(
client
,
&
id
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
SongTime
start
,
end
;
...
...
@@ -188,8 +188,7 @@ CommandResult
handle_deleteid
(
Client
&
client
,
Request
args
)
{
unsigned
id
;
if
(
!
check_unsigned
(
client
,
&
id
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
DeleteId
(
id
);
...
...
@@ -269,7 +268,7 @@ handle_playlistid(Client &client, Request args)
{
if
(
!
args
.
IsEmpty
())
{
unsigned
id
;
if
(
!
check_unsigned
(
client
,
&
id
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
bool
ret
=
playlist_print_id
(
client
,
client
.
playlist
,
id
);
...
...
@@ -315,8 +314,7 @@ handle_prio(Client &client, Request args)
{
const
char
*
const
priority_string
=
args
.
shift
();
unsigned
priority
;
if
(
!
check_unsigned
(
client
,
&
priority
,
priority_string
))
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
))
return
CommandResult
::
ERROR
;
if
(
priority
>
0xff
)
{
...
...
@@ -346,8 +344,7 @@ handle_prioid(Client &client, Request args)
{
const
char
*
const
priority_string
=
args
.
shift
();
unsigned
priority
;
if
(
!
check_unsigned
(
client
,
&
priority
,
priority_string
))
if
(
!
ParseCommandArg
(
client
,
priority
,
priority_string
))
return
CommandResult
::
ERROR
;
if
(
priority
>
0xff
)
{
...
...
@@ -358,7 +355,7 @@ handle_prioid(Client &client, Request args)
for
(
const
char
*
i
:
args
)
{
unsigned
song_id
;
if
(
!
check_unsigned
(
client
,
&
song_id
,
i
))
if
(
!
ParseCommandArg
(
client
,
song_id
,
i
))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
...
...
@@ -376,9 +373,8 @@ handle_move(Client &client, Request args)
RangeArg
range
;
int
to
;
if
(
!
ParseCommandArg
(
client
,
range
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
check_int
(
client
,
&
to
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
range
,
args
[
0
])
||
!
ParseCommandArg
(
client
,
to
,
args
[
1
]))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
...
...
@@ -391,11 +387,10 @@ handle_moveid(Client &client, Request args)
{
unsigned
id
;
int
to
;
if
(
!
check_unsigned
(
client
,
&
id
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
check_int
(
client
,
&
to
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
id
,
args
[
0
])
||
!
ParseCommandArg
(
client
,
to
,
args
[
1
]))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
MoveId
(
id
,
to
);
return
print_playlist_result
(
client
,
result
);
}
...
...
@@ -404,10 +399,8 @@ CommandResult
handle_swap
(
Client
&
client
,
Request
args
)
{
unsigned
song1
,
song2
;
if
(
!
check_unsigned
(
client
,
&
song1
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
check_unsigned
(
client
,
&
song2
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
song1
,
args
[
0
])
||
!
ParseCommandArg
(
client
,
song2
,
args
[
1
]))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
...
...
@@ -419,10 +412,8 @@ CommandResult
handle_swapid
(
Client
&
client
,
Request
args
)
{
unsigned
id1
,
id2
;
if
(
!
check_unsigned
(
client
,
&
id1
,
args
[
0
]))
return
CommandResult
::
ERROR
;
if
(
!
check_unsigned
(
client
,
&
id2
,
args
[
1
]))
if
(
!
ParseCommandArg
(
client
,
id1
,
args
[
0
])
||
!
ParseCommandArg
(
client
,
id2
,
args
[
1
]))
return
CommandResult
::
ERROR
;
PlaylistResult
result
=
client
.
partition
.
SwapIds
(
id1
,
id2
);
...
...
src/command/TagCommands.cxx
View file @
9231f420
...
...
@@ -32,7 +32,7 @@ CommandResult
handle_addtagid
(
Client
&
client
,
Request
args
)
{
unsigned
song_id
;
if
(
!
check_unsigned
(
client
,
&
song_id
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
song_id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
const
char
*
const
tag_name
=
args
[
1
];
...
...
@@ -57,7 +57,7 @@ CommandResult
handle_cleartagid
(
Client
&
client
,
Request
args
)
{
unsigned
song_id
;
if
(
!
check_unsigned
(
client
,
&
song_id
,
args
.
front
()))
if
(
!
ParseCommandArg
(
client
,
song_id
,
args
.
front
()))
return
CommandResult
::
ERROR
;
TagType
tag_type
=
TAG_NUM_OF_ITEM_TYPES
;
...
...
src/protocol/ArgParser.cxx
View file @
9231f420
...
...
@@ -41,7 +41,7 @@ check_uint32(Client &client, uint32_t *dst, const char *s)
}
bool
check_int
(
Client
&
client
,
int
*
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
)
{
char
*
test
;
long
value
;
...
...
@@ -60,7 +60,7 @@ check_int(Client &client, int *value_r, const char *s)
return
false
;
}
*
value_r
=
(
int
)
value
;
value_r
=
(
int
)
value
;
return
true
;
}
...
...
@@ -131,7 +131,7 @@ ParseCommandArg(Client &client, RangeArg &value_r, const char *s)
}
bool
check_unsigned
(
Client
&
client
,
unsigned
*
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
)
{
unsigned
long
value
;
char
*
endptr
;
...
...
@@ -149,12 +149,12 @@ check_unsigned(Client &client, unsigned *value_r, const char *s)
return
false
;
}
*
value_r
=
(
unsigned
)
value
;
value_r
=
(
unsigned
)
value
;
return
true
;
}
bool
check_bool
(
Client
&
client
,
bool
*
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
bool
&
value_r
,
const
char
*
s
)
{
long
value
;
char
*
endptr
;
...
...
@@ -166,12 +166,12 @@ check_bool(Client &client, bool *value_r, const char *s)
return
false
;
}
*
value_r
=
!!
value
;
value_r
=
!!
value
;
return
true
;
}
bool
check_float
(
Client
&
client
,
float
*
value_r
,
const
char
*
s
)
ParseCommandArg
(
Client
&
client
,
float
&
value_r
,
const
char
*
s
)
{
float
value
;
char
*
endptr
;
...
...
@@ -183,7 +183,7 @@ check_float(Client &client, float *value_r, const char *s)
return
false
;
}
*
value_r
=
value
;
value_r
=
value
;
return
true
;
}
...
...
@@ -191,7 +191,7 @@ bool
ParseCommandArg
(
Client
&
client
,
SongTime
&
value_r
,
const
char
*
s
)
{
float
value
;
bool
success
=
check_float
(
client
,
&
value
,
s
)
&&
value
>=
0
;
bool
success
=
ParseCommandArg
(
client
,
value
,
s
)
&&
value
>=
0
;
if
(
success
)
value_r
=
SongTime
::
FromS
(
value
);
...
...
@@ -202,7 +202,7 @@ bool
ParseCommandArg
(
Client
&
client
,
SignedSongTime
&
value_r
,
const
char
*
s
)
{
float
value
;
bool
success
=
check_float
(
client
,
&
value
,
s
);
bool
success
=
ParseCommandArg
(
client
,
value
,
s
);
if
(
success
)
value_r
=
SignedSongTime
::
FromS
(
value
);
...
...
src/protocol/ArgParser.hxx
View file @
9231f420
...
...
@@ -32,7 +32,7 @@ bool
check_uint32
(
Client
&
client
,
uint32_t
*
dst
,
const
char
*
s
);
bool
check_int
(
Client
&
client
,
int
*
value_r
,
const
char
*
s
);
ParseCommandArg
(
Client
&
client
,
int
&
value_r
,
const
char
*
s
);
struct
RangeArg
{
unsigned
start
,
end
;
...
...
@@ -47,13 +47,13 @@ bool
ParseCommandArg
(
Client
&
client
,
RangeArg
&
value_r
,
const
char
*
s
);
bool
check_unsigned
(
Client
&
client
,
unsigned
*
value_r
,
const
char
*
s
);
ParseCommandArg
(
Client
&
client
,
unsigned
&
value_r
,
const
char
*
s
);
bool
check_bool
(
Client
&
client
,
bool
*
value_r
,
const
char
*
s
);
ParseCommandArg
(
Client
&
client
,
bool
&
value_r
,
const
char
*
s
);
bool
check_float
(
Client
&
client
,
float
*
value_r
,
const
char
*
s
);
ParseCommandArg
(
Client
&
client
,
float
&
value_r
,
const
char
*
s
);
bool
ParseCommandArg
(
Client
&
client
,
SongTime
&
value_r
,
const
char
*
s
);
...
...
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