diff options
author | Max Kellermann <max@musicpd.org> | 2018-01-11 19:25:46 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-01-11 19:25:46 +0100 |
commit | 8e29430f215f9c71f113604b2e640b0145929f78 (patch) | |
tree | 91046373ce0a23e08bca880afc4b9c4e0ffc8ef8 /src/playlist/plugins | |
parent | 326488aeebe59299138da04854b91d4cad8d40e4 (diff) |
lib/yajl/Handle: libyajl C++ bindings
Diffstat (limited to 'src/playlist/plugins')
-rw-r--r-- | src/playlist/plugins/SoundCloudPlaylistPlugin.cxx | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx b/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx index 573f60281..276de5c52 100644 --- a/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx +++ b/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx @@ -21,6 +21,7 @@ #include "SoundCloudPlaylistPlugin.hxx" #include "../PlaylistPlugin.hxx" #include "../MemorySongEnumerator.hxx" +#include "lib/yajl/Handle.hxx" #include "config/Block.hxx" #include "input/InputStream.hxx" #include "tag/Builder.hxx" @@ -30,8 +31,6 @@ #include "util/ScopeExit.hxx" #include "Log.hxx" -#include <yajl/yajl_parse.h> - #include <string> #include <string.h> @@ -221,18 +220,17 @@ static constexpr yajl_callbacks parse_callbacks = { /** * Read JSON data and parse it using the given YAJL parser. * @param url URL of the JSON data. - * @param hand YAJL parser handle. + * @param handle YAJL parser handle. * @return -1 on error, 0 on success. */ static int -soundcloud_parse_json(const char *url, yajl_handle hand, +soundcloud_parse_json(const char *url, Yajl::Handle &handle, Mutex &mutex, Cond &cond) try { auto input_stream = InputStream::OpenReady(url, mutex, cond); const std::lock_guard<Mutex> protect(mutex); - yajl_status stat; bool done = false; while (!done) { @@ -243,16 +241,9 @@ try { done = true; if (done) { - stat = yajl_complete_parse(hand); + handle.CompleteParse(); } else - stat = yajl_parse(hand, buffer, nbytes); - - if (stat != yajl_status_ok) { - unsigned char *str = yajl_get_error(hand, 1, buffer, nbytes); - LogError(soundcloud_domain, (const char *)str); - yajl_free_error(hand, str); - break; - } + handle.Parse(buffer, nbytes); } return 0; @@ -310,10 +301,8 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond) } SoundCloudJsonData data; - yajl_handle hand = yajl_alloc(&parse_callbacks, nullptr, &data); - AtScopeExit(hand, &data) { yajl_free(hand); }; - - int ret = soundcloud_parse_json(u, hand, mutex, cond); + Yajl::Handle handle(&parse_callbacks, nullptr, &data); + int ret = soundcloud_parse_json(u, handle, mutex, cond); if (ret == -1) return nullptr; |