MCPcopy Create free account
hub / github.com/comaps/comaps / ParseMetaConfig

Function ParseMetaConfig

libs/platform/servers_list.cpp:12–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10{
11
12std::optional<MetaConfig> ParseMetaConfig(std::string const & jsonStr)
13{
14 char constexpr kSettings[] = "settings";
15 char constexpr kServers[] = "servers";
16
17 MetaConfig outMetaConfig;
18 try
19 {
20 base::Json const root(jsonStr.c_str());
21 json_t const * servers;
22 if (json_is_object(root.get()))
23 {
24 // New format:
25 // {
26 // "servers": ["http://url1", "http://url2", "http://url3"],
27 // "settings": {
28 // "key1": "value1",
29 // "key2": "http://url"
30 // }
31 // }
32
33 json_t * settings = json_object_get(root.get(), kSettings);
34 char const * key;
35 json_t const * value;
36 json_object_foreach(settings, key, value)
37 {
38 if (key == settings::kDonateUrl || key == settings::kNY)
39 {
40 char const * valueStr = json_string_value(value);
41 if (value)
42 outMetaConfig.m_settings[key] = valueStr;
43 }
44 }
45
46 servers = json_object_get(root.get(), kServers);
47 }
48 else
49 {
50 // Old format:
51 // ["http://url1", "http://url2", "http://url3"]
52 servers = root.get();
53 }
54
55 for (size_t i = 0; i < json_array_size(servers); ++i)
56 {
57 char const * url = json_string_value(json_array_get(servers, i));
58 if (url)
59 outMetaConfig.m_serversList.push_back(url);
60 }
61 }
62 catch (base::Json::Exception const & ex)
63 {
64 LOG(LWARNING, ("Can't parse meta configuration:", ex.Msg(), jsonStr));
65 }
66
67 if (outMetaConfig.m_serversList.empty())
68 return std::nullopt;
69

Callers 3

LoadMetaConfigMethod · 0.85
UNIT_TESTFunction · 0.85
UNIT_TESTFunction · 0.85

Calls 3

getMethod · 0.65
push_backMethod · 0.45
emptyMethod · 0.45

Tested by 2

UNIT_TESTFunction · 0.68
UNIT_TESTFunction · 0.68