diff options
author | Max Kellermann <max@duempel.org> | 2013-10-30 09:40:23 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-30 09:40:23 +0100 |
commit | 2b7529e905770e307396ab768a94013833efb802 (patch) | |
tree | d6ee09dcfe4c08a534f500db3e89242202220f23 | |
parent | 1ed321f9647b88c1489d7f81095fbf6156d24454 (diff) |
db/proxy: pass SongFilter to the remote MPD in VisitUniqueTags()
-rw-r--r-- | src/db/ProxyDatabasePlugin.cxx | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index b8b660b44..5bab287ad 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -126,6 +126,76 @@ CheckError(struct mpd_connection *connection, Error &error) return false; } +static bool +SendConstraints(mpd_connection *connection, const SongFilter::Item &item) +{ + switch (item.GetTag()) { + mpd_tag_type tag; + +#if LIBMPDCLIENT_CHECK_VERSION(2,9,0) + case LOCATE_TAG_BASE_TYPE: + if (mpd_connection_cmp_server_version(connection, 0, 18, 0) < 0) + /* requires MPD 0.18 */ + return true; + + return mpd_search_add_base_constraint(connection, + MPD_OPERATOR_DEFAULT, + item.GetValue().c_str()); +#endif + + case LOCATE_TAG_FILE_TYPE: + return mpd_search_add_uri_constraint(connection, + MPD_OPERATOR_DEFAULT, + item.GetValue().c_str()); + + case LOCATE_TAG_ANY_TYPE: + return mpd_search_add_any_tag_constraint(connection, + MPD_OPERATOR_DEFAULT, + item.GetValue().c_str()); + + default: + tag = Convert(TagType(item.GetTag())); + if (tag == MPD_TAG_COUNT) + return true; + + return mpd_search_add_tag_constraint(connection, + MPD_OPERATOR_DEFAULT, + tag, + item.GetValue().c_str()); + } +} + +static bool +SendConstraints(mpd_connection *connection, const SongFilter &filter) +{ + for (const auto &i : filter.GetItems()) + if (!SendConstraints(connection, i)) + return false; + + return true; +} + +static bool +SendConstraints(mpd_connection *connection, const DatabaseSelection &selection) +{ +#if LIBMPDCLIENT_CHECK_VERSION(2,9,0) + if (!selection.uri.empty() && + mpd_connection_cmp_server_version(connection, 0, 18, 0) >= 0) { + /* requires MPD 0.18 */ + if (!mpd_search_add_base_constraint(connection, + MPD_OPERATOR_DEFAULT, + selection.uri.c_str())) + return false; + } +#endif + + if (selection.filter != nullptr && + !SendConstraints(connection, *selection.filter)) + return false; + + return true; +} + Database * ProxyDatabase::Create(const config_param ¶m, Error &error) { @@ -433,8 +503,8 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection, if (!mpd_search_db_tags(connection, tag_type2)) return CheckError(connection, error); - // TODO: match - (void)selection; + if (!SendConstraints(connection, selection)) + return CheckError(connection, error); if (!mpd_search_commit(connection)) return CheckError(connection, error); |