1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Reduce indentation of HTTPFetchOngoing

Also clean up some related things.
This commit is contained in:
ShadowNinja 2014-09-14 20:46:45 -04:00
parent 18bfa1c785
commit 86a3c8ce56
8 changed files with 318 additions and 321 deletions

View file

@ -30,45 +30,34 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "httpfetch.h"
#include "porting.h"
Json::Value fetchJsonValue(const std::string &url,
std::vector<std::string> *extra_headers) {
HTTPFetchRequest fetchrequest;
HTTPFetchResult fetchresult;
fetchrequest.url = url;
fetchrequest.caller = HTTPFETCH_SYNC;
Json::Value fetchJsonValue(const std::string &url,
std::vector<std::string> *extra_headers)
{
HTTPFetchRequest fetch_request;
HTTPFetchResult fetch_result;
fetch_request.url = url;
fetch_request.caller = HTTPFETCH_SYNC;
if (extra_headers != NULL)
fetchrequest.extra_headers = *extra_headers;
fetch_request.extra_headers = *extra_headers;
httpfetch_sync(fetchrequest,fetchresult);
httpfetch_sync(fetch_request, fetch_result);
if (!fetchresult.succeeded) {
if (!fetch_result.succeeded) {
return Json::Value();
}
Json::Value root;
Json::Reader reader;
std::istringstream stream(fetchresult.data);
std::istringstream stream(fetch_result.data);
if (!reader.parse( stream, root ) )
{
if (!reader.parse(stream, root)) {
errorstream << "URL: " << url << std::endl;
errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
errorstream << "data: \"" << fetchresult.data << "\"" << std::endl;
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
return Json::Value();
}
if (root.isArray()) {
return root;
}
if ((root["list"].isArray())) {
return root["list"];
}
else {
return root;
}
return Json::Value();
return root;
}
std::vector<ModStoreMod> readModStoreList(Json::Value& modlist) {