summaryrefslogtreecommitdiff
path: root/src/convert_json.cpp
blob: c774aa002b4355fa7184909490ae3a8ffbed09a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
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();
}
-0.028581 0.040885 0.439611 v -0.028581 0.167782 0.439611 v 0.028581 0.167782 0.439611 v 0.028581 0.040885 0.439611 v 0.028581 0.040885 0.496774 v 0.028581 0.167782 0.496774 v -0.028581 0.167782 0.496774 v -0.028581 0.040885 0.496774 v -0.028581 0.040885 0.325575 v -0.028581 0.167782 0.325575 v -0.028581 0.167782 0.268412 v -0.028581 0.040885 0.268412 v 0.028581 0.040885 0.268412 v 0.028581 0.167782 0.268412 v 0.028581 0.167782 0.325575 v 0.028581 0.040885 0.325575 v -0.269369 -0.475166 0.548486 v 0.230631 -0.475166 0.548486 v -0.269369 0.273749 0.548486 v 0.230631 0.273749 0.548486 v -0.269369 0.273749 0.501067 v -0.269369 -0.475166 0.501068 v 0.230631 -0.475166 0.501068 v 0.230631 0.273749 0.501067 vt 0.000000 0.000000 vt 0.538102 0.501950 vt 0.538102 0.192341 vt 0.615085 0.192341 vt 0.538102 0.000000 vt 0.615085 0.000000 vt 0.000000 0.501950 vt 0.000000 0.192341 vt 0.076983 0.192341 vt 0.076983 0.000000 vt 0.615085 0.501950 vt 0.692068 0.192341 vt 0.692068 0.000000 vt 0.692068 0.501950 vt 0.769051 0.192341 vt 0.769051 0.000000 vt 0.769051 0.501950 vt 0.846034 0.192341 vt 0.846034 0.000000 vt 0.846034 0.996502 vt 0.846034 0.686893 vt 0.923017 0.686893 vt 0.307543 0.501950 vt 0.307542 0.192341 vt 0.384525 0.192341 vt 0.307542 0.000000 vt 0.384525 0.000000 vt 0.230559 0.501950 vt 0.230559 0.192341 vt 0.230559 0.000000 vt 0.923017 0.478709 vt 1.000000 0.478709 vt 1.000000 0.650215 vt 0.846034 0.600923 vt 0.846034 0.429417 vt 0.923017 0.429417 vt 0.923017 0.600923 vt 0.846034 0.343447 vt 0.923017 0.343447 vt 0.538102 1.000000 vt 0.538102 0.692796 vt 0.615085 0.692796 vt 0.000000 1.000000 vt 0.000000 0.692797 vt 0.076983 0.692797 vt 0.076983 0.501950 vt 0.692068 1.000000 vt 0.692068 0.692796 vt 0.769051 0.692796 vt 0.692068 0.809153 vt 0.615085 0.809153 vt 0.615085 1.000000 vt 0.769051 1.000000 vt 0.846034 0.692796 vt 0.846034 0.501950 vt 0.923017 0.307203 vt 0.923017 0.000000 vt 1.000000 0.000000 vt 0.307543 1.000000 vt 0.307542 0.692797 vt 0.384525 0.692797 vt 0.384525 0.501950 vt 0.230559 1.000000 vt 0.230559 0.692797 vt 1.000000 0.307203 vt 0.846034 0.257476 vt 0.846034 0.085970 vt 0.923017 0.085970 vt 0.923017 0.257476 vt 0.923017 0.996502 vt 0.923017 0.650215 vt 0.076983 1.000000 vt 0.846034 1.000000 vt 0.384526 1.000000 vt 0.437731 0.748915 vt 0.437731 0.000000 vt 0.875462 0.000000 vt 0.000000 0.748915 vt 0.916975 0.748915 vt 0.916975 0.000000 vt 0.958487 0.000000 vt 1.000000 0.500000 vt 0.958487 0.500000 vt 0.958487 1.000000 vt 0.875462 0.748915 vt 0.958487 0.748915 vt 1.000000 1.000000 vn 0.000000 1.000000 0.000000 vn 1.000000 0.000000 0.000000 vn -1.000000 0.000000 -0.000000 vn 0.000000 0.000000 1.000000 vn 0.000000 0.000000 -1.000000 vn 0.000000 -1.000000 0.000000 g HSSignalschirm_Cube.002_Mast usemtl Mast s off f 5/1/1 1/1/1 2/1/1 f 14/2/2 20/3/2 21/4/2 f 20/3/2 19/5/2 22/6/2 f 11/7/3 24/8/3 17/9/3 f 24/8/3 23/1/3 18/10/3 f 12/11/4 21/4/4 24/12/4 f 21/4/4 22/6/4 23/13/4 f 16/14/5 17/12/5 20/15/5 f 17/12/5 18/13/5 19/16/5 f 10/17/5 28/15/5 29/18/5 f 28/15/5 27/16/5 30/19/5 f 13/20/4 32/21/4 25/22/4 f 9/23/2 29/24/2 32/25/2 f 29/24/2 30/26/2 31/27/2 f 15/28/3 25/29/3 28/24/3 f 25/29/3 26/30/3 27/26/3 f 31/27/2 19/5/2 20/3/2 f 25/31/6 32/32/6 20/33/6 f 25/29/3 17/9/3 18/10/3 f 26/34/1 18/35/1 19/36/1 f 26/34/1 31/37/1 30/22/1 f 18/35/1 23/38/1 22/39/1 f 37/1/1 33/1/1 34/1/1 f 46/40/2 52/41/2 53/42/2 f 52/41/2 51/2/2 54/11/2 f 43/43/3 56/44/3 49/45/3 f 56/44/3 55/7/3 50/46/3 f 44/47/4 53/48/4 56/49/4 f 53/48/4 54/14/4 55/17/4 f 48/14/5 49/50/5 52/51/5 f 49/50/5 50/47/5 51/52/5 f 42/53/5 60/49/5 61/54/5 f 60/49/5 59/17/5 62/55/5 f 45/56/4 64/57/4 57/58/4 f 41/59/2 61/60/2 64/61/2 f 61/60/2 62/23/2 63/62/2 f 47/63/3 57/64/3 60/60/3 f 57/64/3 58/28/3 59/23/3 f 63/62/2 51/2/2 52/41/2 f 57/56/6 64/65/6 52/32/6 f 57/64/3 49/45/3 50/46/3 f 58/66/1 50/67/1 51/68/1 f 58/66/1 63/69/1 62/39/1 f 50/67/1 55/19/1 54/57/1 f 8/1/1 5/1/1 2/1/1 f 12/11/2 14/2/2 21/4/2 f 21/4/2 20/3/2 22/6/2 f 16/46/3 11/7/3 17/9/3 f 17/9/3 24/8/3 18/10/3 f 11/14/4 12/11/4 24/12/4 f 24/12/4 21/4/4 23/13/4 f 14/17/5 16/14/5 20/15/5 f 20/15/5 17/12/5 19/16/5 f 9/55/5 10/17/5 29/18/5 f 29/18/5 28/15/5 30/19/5 f 15/70/4 13/20/4 25/22/4 f 13/62/2 9/23/2 32/25/2 f 32/25/2 29/24/2 31/27/2 f 10/23/3 15/28/3 28/24/3 f 28/24/3 25/29/3 27/26/3 f 32/25/2 31/27/2 20/3/2 f 17/71/6 25/31/6 20/33/6 f 26/30/3 25/29/3 18/10/3 f 31/37/1 26/34/1 19/36/1 f 27/21/1 26/34/1 30/22/1 f 19/36/1 18/35/1 22/39/1 f 40/1/1 37/1/1 34/1/1 f 44/52/2 46/40/2 53/42/2 f 53/42/2 52/41/2 54/11/2 f 48/72/3 43/43/3 49/45/3 f 49/45/3 56/44/3 50/46/3 f 43/53/4 44/47/4 56/49/4 f 56/49/4 53/48/4 55/17/4 f 46/11/5 48/14/5 52/51/5 f 52/51/5 49/50/5 51/52/5 f 41/73/5 42/53/5 61/54/5 f 61/54/5 60/49/5 62/55/5 f 47/65/4 45/56/4 57/58/4 f 45/74/2 41/59/2 64/61/2 f 64/61/2 61/60/2 63/62/2 f 42/59/3 47/63/3 60/60/3 f 60/60/3 57/64/3 59/23/3 f 64/61/2 63/62/2 52/41/2 f 49/31/6 57/56/6 52/32/6 f 58/28/3 57/64/3 50/46/3 f 63/69/1 58/66/1 51/68/1 f 59/38/1 58/66/1 62/39/1 f 51/68/1 50/67/1 54/57/1 g HSSignalschirm_Cube.002_Schirm usemtl Schirm f 66/75/4 68/76/4 67/77/4 f 69/75/5 72/78/5 71/1/5 f 69/79/3 70/80/3 65/81/3 f 72/58/1 69/82/1 67/83/1 f 70/84/6 71/83/6 66/82/6 f 71/80/2 72/79/2 68/85/2 f 65/85/4 66/75/4 67/77/4 f 70/76/5 69/75/5 71/1/5 f 67/86/3 69/79/3 65/81/3 f 68/81/1 72/58/1 67/83/1 f 65/87/6 70/84/6 66/82/6 f 66/77/2 71/80/2 68/85/2 l 2 3 l 4 1 l 3 4 l 6 7 l 7 8 l 5 6 l 34 35 l 36 33 l 35 36 l 38 39 l 39 40 l 37 38