Commit 0701333e authored by Max Kellermann's avatar Max Kellermann

db/proxy: forward filter as expression to server

This adds support for the full set of MPD 0.21 filter types.
parent a8e70f09
...@@ -347,6 +347,14 @@ SendConstraints(mpd_connection *connection, const ISongFilter &f) ...@@ -347,6 +347,14 @@ SendConstraints(mpd_connection *connection, const ISongFilter &f)
static bool static bool
SendConstraints(mpd_connection *connection, const SongFilter &filter) SendConstraints(mpd_connection *connection, const SongFilter &filter)
{ {
#if LIBMPDCLIENT_CHECK_VERSION(2, 15, 0)
if (mpd_connection_cmp_server_version(connection, 0, 21, 0) >= 0)
/* with MPD 0.21 (and libmpdclient 2.15), we can pass
arbitrary filters as expression */
return mpd_search_add_expression(connection,
filter.ToExpression().c_str());
#endif
for (const auto &i : filter.GetItems()) for (const auto &i : filter.GetItems())
if (!SendConstraints(connection, *i)) if (!SendConstraints(connection, *i))
return false; return false;
...@@ -870,8 +878,18 @@ IsFilterSupported(const ISongFilter &f) noexcept ...@@ -870,8 +878,18 @@ IsFilterSupported(const ISongFilter &f) noexcept
gcc_pure gcc_pure
static bool static bool
IsFilterFullySupported(const SongFilter &filter) noexcept IsFilterFullySupported(const SongFilter &filter,
const struct mpd_connection *connection) noexcept
{ {
#if LIBMPDCLIENT_CHECK_VERSION(2, 15, 0)
if (mpd_connection_cmp_server_version(connection, 0, 21, 0) >= 0)
/* with MPD 0.21 (and libmpdclient 2.15), we can pass
arbitrary filters as expression */
return true;
#else
(void)connection;
#endif
for (const auto &i : filter.GetItems()) for (const auto &i : filter.GetItems())
if (!IsFilterSupported(*i)) if (!IsFilterSupported(*i))
return false; return false;
...@@ -881,10 +899,11 @@ IsFilterFullySupported(const SongFilter &filter) noexcept ...@@ -881,10 +899,11 @@ IsFilterFullySupported(const SongFilter &filter) noexcept
gcc_pure gcc_pure
static bool static bool
IsFilterFullySupported(const SongFilter *filter) noexcept IsFilterFullySupported(const SongFilter *filter,
const struct mpd_connection *connection) noexcept
{ {
return filter == nullptr || return filter == nullptr ||
IsFilterFullySupported(*filter); IsFilterFullySupported(*filter, connection);
} }
#endif #endif
...@@ -933,7 +952,7 @@ CheckSelection(DatabaseSelection selection, ...@@ -933,7 +952,7 @@ CheckSelection(DatabaseSelection selection,
#if LIBMPDCLIENT_CHECK_VERSION(2, 10, 0) #if LIBMPDCLIENT_CHECK_VERSION(2, 10, 0)
if (selection.window != RangeArg::All() && if (selection.window != RangeArg::All() &&
IsFilterFullySupported(selection.filter)) IsFilterFullySupported(selection.filter, connection))
/* we can forward the "window" parameter to the other /* we can forward the "window" parameter to the other
MPD */ MPD */
selection.window = RangeArg::All(); selection.window = RangeArg::All();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment