blob: fa432aa6705d054d9adc74c7bff40da504cd7b68 (
plain)
ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 00 00 00 01 00 08 06 00 00 00 5c 72 a8 | .PNG........IHDR.............\r. |
0020 | 66 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0e c3 00 | f....bKGD..............pHYs..... |
0040 | 00 0e c3 01 c7 6f a8 64 00 00 00 07 74 49 4d 45 07 e0 06 09 13 13 0d 29 e6 2b 0e 00 00 20 00 49 | .....o.d....tIME.......).+.....I |
0060 | 44 41 54 78 da ec bd 69 90 64 d7 75 1e f8 9d bb bd 25 b3 b6 ac a5 57 74 a3 bb 81 c6 d2 00 1a 00 | DATx...i.d.u.....%....Wt........ |
0080 | 41 09 82 08 50 84 28 53 a3 5d e2 26 41 b2 2d 8d 16 92 96 ac 99 b1 1c 31 e1 08 7b c2 e1 f0 fc 98 | A...P.(S.].&A.-........1..{..... |
00a0 | 3f 76 88 d2 58 33 f6 58 63 71 3c a6 68 4a 63 7b c6 16 69 ca a2 24 6b 17 40 82 20 08 80 c4 d2 0b | ?v..X3.Xcq<.hJc{..i..$k.@....... |
00c0 | d0 04 ba 51 7b e5 f2 b6 7b ef 99 1f f7 bd 57 d9 c5 06 40 88 24 d0 00 df e9 c8 a8 ae aa 97 59 55 | ...Q{...{.....W...@.$./*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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 <vector>
#include <iostream>
#include <sstream>
#include "convert_json.h"
#include "content/mods.h"
#include "config.h"
#include "log.h"
#include "settings.h"
#include "httpfetch.h"
#include "porting.h"
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)
fetch_request.extra_headers = *extra_headers;
httpfetch_sync(fetch_request, fetch_result);
if (!fetch_result.succeeded) {
return Json::Value();
}
Json::Value root;
std::istringstream stream(fetch_result.data);
Json::CharReaderBuilder builder;
builder.settings_["collectComments"] = false;
std::string errs;
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
errorstream << "URL: " << url << std::endl;
errorstream << "Failed to parse json data " << errs << std::endl;
if (fetch_result.data.size() > 100) {
errorstream << "Data (" << fetch_result.data.size()
<< " bytes) printed to warningstream." << std::endl;
warningstream << "data: \"" << fetch_result.data << "\"" << std::endl;
} else {
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
}
return Json::Value();
}
return root;
}
std::string fastWriteJson(const Json::Value &value)
{
std::ostringstream oss;
Json::StreamWriterBuilder builder;
builder["indentation"] = "";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(value, &oss);
return oss.str();
}
|