diff options
author | Max Kellermann <max@duempel.org> | 2013-10-30 10:00:57 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-30 10:00:57 +0100 |
commit | 6a147a17af10af3852aed3549858d6aae75a8841 (patch) | |
tree | 69b01e77b06652ff8104d9de0182fda0f4ab7dfd /src/db | |
parent | 2b7529e905770e307396ab768a94013833efb802 (diff) | |
download | mpd-6a147a17af10af3852aed3549858d6aae75a8841.tar.gz mpd-6a147a17af10af3852aed3549858d6aae75a8841.tar.xz mpd-6a147a17af10af3852aed3549858d6aae75a8841.zip |
db/proxy: pass search/find to remote MPD
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/ProxyDatabasePlugin.cxx | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index 5bab287ad..05d023668 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -472,6 +472,38 @@ Visit(struct mpd_connection *connection, const char *uri, return CheckError(connection, error); } +static bool +SearchSongs(struct mpd_connection *connection, + const DatabaseSelection &selection, + VisitSong visit_song, + Error &error) +{ + assert(selection.recursive); + assert(visit_song); + + const bool exact = selection.filter == nullptr || + !selection.filter->HasFoldCase(); + + if (!mpd_search_db_songs(connection, exact) || + !SendConstraints(connection, selection) || + !mpd_search_commit(connection)) + return CheckError(connection, error); + + bool result = true; + struct mpd_song *song; + while (result && (song = mpd_recv_song(connection)) != nullptr) { + Song *song2 = Convert(song); + mpd_song_free(song); + + result = !Match(selection.filter, *song2) || + visit_song(*song2, error); + song2->Free(); + } + + mpd_response_finish(connection); + return result && CheckError(connection, error); +} + bool ProxyDatabase::Visit(const DatabaseSelection &selection, VisitDirectory visit_directory, @@ -479,9 +511,14 @@ ProxyDatabase::Visit(const DatabaseSelection &selection, VisitPlaylist visit_playlist, Error &error) const { - // TODO: match // TODO: auto-reconnect + if (!visit_directory && !visit_playlist && selection.recursive) + /* this optimized code path can only be used under + certain conditions */ + return ::SearchSongs(connection, selection, visit_song, error); + + /* fall back to recursive walk (slow!) */ return ::Visit(connection, selection.uri.c_str(), selection.recursive, selection.filter, visit_directory, visit_song, visit_playlist, |