From a3f47bdeb630361502a743259dcaa0bb1377f3bd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 2 Sep 2015 19:58:41 +0100 Subject: Use libadhocutil --- libtmdb/Jamfile.jam | 2 ++ libtmdb/httpClient.cpp | 34 ++++++---------------------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/libtmdb/Jamfile.jam b/libtmdb/Jamfile.jam index 3c719b6..668af7d 100644 --- a/libtmdb/Jamfile.jam +++ b/libtmdb/Jamfile.jam @@ -14,6 +14,7 @@ lib boost_system ; lib boost_filesystem ; lib curl ; lib boost_utf : : boost_unit_test_framework ; +lib adhocutil : : : : /usr/include/adhocutil ; lib tmdb : [ glob *.cpp *.ice : test*.cpp ] : @@ -26,6 +27,7 @@ lib tmdb : boost_system glibmm curl + adhocutil yes -fvisibility=hidden : : diff --git a/libtmdb/httpClient.cpp b/libtmdb/httpClient.cpp index a4b4eb7..4331c07 100644 --- a/libtmdb/httpClient.cpp +++ b/libtmdb/httpClient.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace TMDb { HttpClient::HttpClient(const std::string & bu, const std::string & k) : @@ -38,38 +39,15 @@ namespace TMDb { } } - static size_t - appendString(void * contents, size_t size, size_t nmemb, void * userp) - { - auto data = static_cast(userp); - data->write(static_cast(contents), size * nmemb); - return size * nmemb; - } - json::Value HttpClient::FetchJson(const std::string & path) const { - std::stringstream jsonData; - - struct curl_slist *headers = NULL; - curl_slist_append(headers, "Accept: application/json"); - - CURL * curl_handle = curl_easy_init(); - curl_easy_setopt(curl_handle, CURLOPT_URL, path.c_str()); - curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, appendString); - curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&jsonData); - curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); - curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); - CURLcode res = curl_easy_perform(curl_handle); - - long http_code = 0; - curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code); - curl_easy_cleanup(curl_handle); - if (res != CURLE_OK) { - throw TMDb::HttpException(http_code); - } + AdHoc::Net::CurlStreamSource css(path); + css.appendHeader("Accept: application/json"); + css.setopt(CURLOPT_USERAGENT, "libtmdb/1.0"); - return json::parseValue(jsonData); + AdHoc::Net::CurlStream curlstrm(css); + return json::parseValue(curlstrm); } } -- cgit v1.2.3