playlist/SoundCloud: move code to Yajl::Parse(InputStream&)
This commit is contained in:
parent
7fe07324d7
commit
26b1573cbe
@ -243,6 +243,7 @@ CURL_SOURCES = \
|
|||||||
src/lib/curl/Slist.hxx
|
src/lib/curl/Slist.hxx
|
||||||
|
|
||||||
YAJL_SOURCES = \
|
YAJL_SOURCES = \
|
||||||
|
src/lib/yajl/ParseInputStream.cxx src/lib/yajl/ParseInputStream.hxx \
|
||||||
src/lib/yajl/Handle.hxx
|
src/lib/yajl/Handle.hxx
|
||||||
|
|
||||||
UPNP_SOURCES = \
|
UPNP_SOURCES = \
|
||||||
|
43
src/lib/yajl/ParseInputStream.cxx
Normal file
43
src/lib/yajl/ParseInputStream.cxx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2018 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "ParseInputStream.hxx"
|
||||||
|
#include "Handle.hxx"
|
||||||
|
#include "input/InputStream.hxx"
|
||||||
|
|
||||||
|
void
|
||||||
|
Yajl::ParseInputStream(Handle &handle, InputStream &is)
|
||||||
|
{
|
||||||
|
const std::lock_guard<Mutex> protect(is.mutex);
|
||||||
|
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
|
while (!done) {
|
||||||
|
unsigned char buffer[4096];
|
||||||
|
const size_t nbytes = is.Read(buffer, sizeof(buffer));
|
||||||
|
if (nbytes == 0)
|
||||||
|
done = true;
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
handle.CompleteParse();
|
||||||
|
} else
|
||||||
|
handle.Parse(buffer, nbytes);
|
||||||
|
}
|
||||||
|
}
|
34
src/lib/yajl/ParseInputStream.hxx
Normal file
34
src/lib/yajl/ParseInputStream.hxx
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2018 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef YAJL_PARSE_INPUT_STREAM_HXX
|
||||||
|
#define YAJL_PARSE_INPUT_STREAM_HXX
|
||||||
|
|
||||||
|
class InputStream;
|
||||||
|
|
||||||
|
namespace Yajl {
|
||||||
|
|
||||||
|
class Handle;
|
||||||
|
|
||||||
|
void
|
||||||
|
ParseInputStream(Handle &handle, InputStream &is);
|
||||||
|
|
||||||
|
} // namespace Yajl
|
||||||
|
|
||||||
|
#endif
|
@ -22,6 +22,7 @@
|
|||||||
#include "../PlaylistPlugin.hxx"
|
#include "../PlaylistPlugin.hxx"
|
||||||
#include "../MemorySongEnumerator.hxx"
|
#include "../MemorySongEnumerator.hxx"
|
||||||
#include "lib/yajl/Handle.hxx"
|
#include "lib/yajl/Handle.hxx"
|
||||||
|
#include "lib/yajl/ParseInputStream.hxx"
|
||||||
#include "config/Block.hxx"
|
#include "config/Block.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "tag/Builder.hxx"
|
#include "tag/Builder.hxx"
|
||||||
@ -227,23 +228,7 @@ soundcloud_parse_json(const char *url, Yajl::Handle &handle,
|
|||||||
Mutex &mutex, Cond &cond)
|
Mutex &mutex, Cond &cond)
|
||||||
{
|
{
|
||||||
auto input_stream = InputStream::OpenReady(url, mutex, cond);
|
auto input_stream = InputStream::OpenReady(url, mutex, cond);
|
||||||
|
Yajl::ParseInputStream(handle, *input_stream);
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
|
|
||||||
bool done = false;
|
|
||||||
|
|
||||||
while (!done) {
|
|
||||||
unsigned char buffer[4096];
|
|
||||||
const size_t nbytes =
|
|
||||||
input_stream->Read(buffer, sizeof(buffer));
|
|
||||||
if (nbytes == 0)
|
|
||||||
done = true;
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
handle.CompleteParse();
|
|
||||||
} else
|
|
||||||
handle.Parse(buffer, nbytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user