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
0d97eba7
Commit
0d97eba7
authored
May 25, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client/Response: refactor FormatError() to use libfmt
parent
18efda71
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
33 deletions
+56
-33
Response.cxx
src/client/Response.cxx
+4
-6
Response.hxx
src/client/Response.hxx
+17
-1
AllCommands.cxx
src/command/AllCommands.cxx
+14
-12
DatabaseCommands.cxx
src/command/DatabaseCommands.cxx
+11
-9
OtherCommands.cxx
src/command/OtherCommands.cxx
+3
-2
TagCommands.cxx
src/command/TagCommands.cxx
+7
-3
No files found.
src/client/Response.cxx
View file @
0d97eba7
...
...
@@ -70,19 +70,17 @@ Response::WriteBinary(ConstBuffer<void> payload) noexcept
void
Response
::
Error
(
enum
ack
code
,
const
char
*
msg
)
noexcept
{
F
ormatError
(
code
,
"%s"
,
msg
);
F
mtError
(
code
,
FMT_STRING
(
"{}"
)
,
msg
);
}
void
Response
::
FormatError
(
enum
ack
code
,
const
char
*
fmt
,
...)
noexcept
Response
::
VFmtError
(
enum
ack
code
,
fmt
::
string_view
format_str
,
fmt
::
format_args
args
)
noexcept
{
Fmt
(
FMT_STRING
(
"ACK [{}@{}] {{{}}} "
),
(
int
)
code
,
list_index
,
command
);
std
::
va_list
args
;
va_start
(
args
,
fmt
);
FormatV
(
fmt
,
args
);
va_end
(
args
);
VFmt
(
format_str
,
std
::
move
(
args
));
Write
(
"
\n
"
);
}
src/client/Response.hxx
View file @
0d97eba7
...
...
@@ -105,7 +105,23 @@ public:
bool
WriteBinary
(
ConstBuffer
<
void
>
payload
)
noexcept
;
void
Error
(
enum
ack
code
,
const
char
*
msg
)
noexcept
;
void
FormatError
(
enum
ack
code
,
const
char
*
fmt
,
...)
noexcept
;
void
VFmtError
(
enum
ack
code
,
fmt
::
string_view
format_str
,
fmt
::
format_args
args
)
noexcept
;
template
<
typename
S
,
typename
...
Args
>
void
FmtError
(
enum
ack
code
,
const
S
&
format_str
,
Args
&&
...
args
)
noexcept
{
#if FMT_VERSION >= 70000
return
VFmtError
(
code
,
fmt
::
to_string_view
(
format_str
),
fmt
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...));
#else
/* expensive fallback for older libfmt versions */
const
auto
result
=
fmt
::
format
(
format_str
,
args
...);
return
Error
(
code
,
result
.
c_str
());
#endif
}
};
#endif
src/command/AllCommands.cxx
View file @
0d97eba7
...
...
@@ -325,9 +325,9 @@ command_check_request(const struct command *cmd, Response &r,
unsigned
permission
,
Request
args
)
noexcept
{
if
(
cmd
->
permission
!=
(
permission
&
cmd
->
permission
))
{
r
.
F
orma
tError
(
ACK_ERROR_PERMISSION
,
"you don't have permission for
\"
%s
\"
"
,
cmd
->
cmd
);
r
.
F
m
tError
(
ACK_ERROR_PERMISSION
,
FMT_STRING
(
"you don't have permission for
\"
{}
\"
"
)
,
cmd
->
cmd
);
return
false
;
}
...
...
@@ -338,17 +338,19 @@ command_check_request(const struct command *cmd, Response &r,
return
true
;
if
(
min
==
max
&&
unsigned
(
max
)
!=
args
.
size
)
{
r
.
F
orma
tError
(
ACK_ERROR_ARG
,
"wrong number of arguments for
\"
%s
\"
"
,
cmd
->
cmd
);
r
.
F
m
tError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"wrong number of arguments for
\"
{}
\"
"
)
,
cmd
->
cmd
);
return
false
;
}
else
if
(
args
.
size
<
unsigned
(
min
))
{
r
.
FormatError
(
ACK_ERROR_ARG
,
"too few arguments for
\"
%s
\"
"
,
cmd
->
cmd
);
r
.
FmtError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"too few arguments for
\"
{}
\"
"
),
cmd
->
cmd
);
return
false
;
}
else
if
(
max
>=
0
&&
args
.
size
>
unsigned
(
max
))
{
r
.
FormatError
(
ACK_ERROR_ARG
,
"too many arguments for
\"
%s
\"
"
,
cmd
->
cmd
);
r
.
FmtError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"too many arguments for
\"
{}
\"
"
),
cmd
->
cmd
);
return
false
;
}
else
return
true
;
...
...
@@ -360,8 +362,8 @@ command_checked_lookup(Response &r, unsigned permission,
{
const
struct
command
*
cmd
=
command_lookup
(
cmd_name
);
if
(
cmd
==
nullptr
)
{
r
.
F
orma
tError
(
ACK_ERROR_UNKNOWN
,
"unknown command
\"
%s
\"
"
,
cmd_name
);
r
.
F
m
tError
(
ACK_ERROR_UNKNOWN
,
FMT_STRING
(
"unknown command
\"
{}
\"
"
)
,
cmd_name
);
return
nullptr
;
}
...
...
src/command/DatabaseCommands.cxx
View file @
0d97eba7
...
...
@@ -34,6 +34,8 @@
#include "util/ASCII.hxx"
#include "song/Filter.hxx"
#include <fmt/format.h>
#include <memory>
#include <vector>
...
...
@@ -183,8 +185,8 @@ handle_count(Client &client, Request args, Response &r)
const
char
*
s
=
args
[
args
.
size
-
1
];
group
=
tag_name_parse_i
(
s
);
if
(
group
==
TAG_NUM_OF_ITEM_TYPES
)
{
r
.
F
orma
tError
(
ACK_ERROR_ARG
,
"Unknown tag type: %s"
,
s
);
r
.
F
m
tError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unknown tag type: {}"
)
,
s
);
return
CommandResult
::
ERROR
;
}
...
...
@@ -252,8 +254,8 @@ handle_list(Client &client, Request args, Response &r)
const
auto
tagType
=
tag_name_parse_i
(
tag_name
);
if
(
tagType
==
TAG_NUM_OF_ITEM_TYPES
)
{
r
.
F
orma
tError
(
ACK_ERROR_ARG
,
"Unknown tag type: %s"
,
tag_name
);
r
.
F
m
tError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unknown tag type: {}"
)
,
tag_name
);
return
CommandResult
::
ERROR
;
}
...
...
@@ -266,9 +268,9 @@ handle_list(Client &client, Request args, Response &r)
args
.
front
()[
0
]
!=
'('
)
{
/* for compatibility with < 0.12.0 */
if
(
tagType
!=
TAG_ALBUM
)
{
r
.
F
orma
tError
(
ACK_ERROR_ARG
,
"should be
\"
%s
\"
for 3 arguments"
,
tag_item_names
[
TAG_ALBUM
]);
r
.
F
m
tError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"should be
\"
{}
\"
for 3 arguments"
)
,
tag_item_names
[
TAG_ALBUM
]);
return
CommandResult
::
ERROR
;
}
...
...
@@ -281,8 +283,8 @@ handle_list(Client &client, Request args, Response &r)
const
char
*
s
=
args
[
args
.
size
-
1
];
const
auto
group
=
tag_name_parse_i
(
s
);
if
(
group
==
TAG_NUM_OF_ITEM_TYPES
)
{
r
.
F
orma
tError
(
ACK_ERROR_ARG
,
"Unknown tag type: %s"
,
s
);
r
.
F
m
tError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unknown tag type: {}"
)
,
s
);
return
CommandResult
::
ERROR
;
}
...
...
src/command/OtherCommands.cxx
View file @
0d97eba7
...
...
@@ -407,8 +407,9 @@ handle_idle(Client &client, Request args, Response &r)
for
(
const
char
*
i
:
args
)
{
unsigned
event
=
idle_parse_name
(
i
);
if
(
event
==
0
)
{
r
.
FormatError
(
ACK_ERROR_ARG
,
"Unrecognized idle event: %s"
,
i
);
r
.
FmtError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unrecognized idle event: {}"
),
i
);
return
CommandResult
::
ERROR
;
}
...
...
src/command/TagCommands.cxx
View file @
0d97eba7
...
...
@@ -25,6 +25,8 @@
#include "queue/Playlist.hxx"
#include "util/ConstBuffer.hxx"
#include <fmt/format.h>
CommandResult
handle_addtagid
(
Client
&
client
,
Request
args
,
Response
&
r
)
{
...
...
@@ -33,7 +35,8 @@ handle_addtagid(Client &client, Request args, Response &r)
const
char
*
const
tag_name
=
args
[
1
];
const
TagType
tag_type
=
tag_name_parse_i
(
tag_name
);
if
(
tag_type
==
TAG_NUM_OF_ITEM_TYPES
)
{
r
.
FormatError
(
ACK_ERROR_ARG
,
"Unknown tag type: %s"
,
tag_name
);
r
.
FmtError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unknown tag type: {}"
),
tag_name
);
return
CommandResult
::
ERROR
;
}
...
...
@@ -53,8 +56,9 @@ handle_cleartagid(Client &client, Request args, Response &r)
const
char
*
const
tag_name
=
args
[
1
];
tag_type
=
tag_name_parse_i
(
tag_name
);
if
(
tag_type
==
TAG_NUM_OF_ITEM_TYPES
)
{
r
.
FormatError
(
ACK_ERROR_ARG
,
"Unknown tag type: %s"
,
tag_name
);
r
.
FmtError
(
ACK_ERROR_ARG
,
FMT_STRING
(
"Unknown tag type: {}"
),
tag_name
);
return
CommandResult
::
ERROR
;
}
}
...
...
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