diff options
author | Max Kellermann <max@musicpd.org> | 2018-09-02 22:39:45 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-09-02 22:39:45 +0200 |
commit | 0701333ec18e599d95386a94de84714a1c72aaec (patch) | |
tree | 7c0b444cff897618586101bb82999ad3dc88f8df /src/db | |
parent | a8e70f09016ed844578e79e63649553ee8f247ae (diff) |
db/proxy: forward filter as expression to server
This adds support for the full set of MPD 0.21 filter types.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/plugins/ProxyDatabasePlugin.cxx | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index 6d0600c0c..b1a63a6a6 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -347,6 +347,14 @@ SendConstraints(mpd_connection *connection, const ISongFilter &f) static bool 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()) if (!SendConstraints(connection, *i)) return false; @@ -870,8 +878,18 @@ IsFilterSupported(const ISongFilter &f) noexcept gcc_pure 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()) if (!IsFilterSupported(*i)) return false; @@ -881,10 +899,11 @@ IsFilterFullySupported(const SongFilter &filter) noexcept gcc_pure static bool -IsFilterFullySupported(const SongFilter *filter) noexcept +IsFilterFullySupported(const SongFilter *filter, + const struct mpd_connection *connection) noexcept { return filter == nullptr || - IsFilterFullySupported(*filter); + IsFilterFullySupported(*filter, connection); } #endif @@ -933,7 +952,7 @@ CheckSelection(DatabaseSelection selection, #if LIBMPDCLIENT_CHECK_VERSION(2, 10, 0) if (selection.window != RangeArg::All() && - IsFilterFullySupported(selection.filter)) + IsFilterFullySupported(selection.filter, connection)) /* we can forward the "window" parameter to the other MPD */ selection.window = RangeArg::All(); |