From d79f792e6fab5503bc70ad31cdf77ac935061bb7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 19 Jan 2017 15:05:26 -0800 Subject: OpenBSD fixes, workaround for apparent libstdc++ bug. --- one.cpp | 60 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'one.cpp') diff --git a/one.cpp b/one.cpp index 3ebaa8fa..43af7dea 100644 --- a/one.cpp +++ b/one.cpp @@ -289,7 +289,7 @@ static int cli(int argc,char **argv) nlohmann::json j; try { - j = nlohmann::json::parse(responseBody); + j = OSUtils::jsonParse(responseBody); } catch (std::exception &exc) { printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what()); return 1; @@ -299,14 +299,16 @@ static int cli(int argc,char **argv) } if (scode == 200) { - std::ostringstream out; if (json) { - out << j.dump(2) << ZT_EOL_S; + printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str()); } else { - if (j.is_object()) - out << "200 info " << j["address"].get() << " " << j["version"].get() << " " << ((j["tcpFallbackActive"]) ? "TUNNELED" : ((j["online"]) ? "ONLINE" : "OFFLINE")) << ZT_EOL_S; + if (j.is_object()) { + printf("200 info %s %s %s" ZT_EOL_S, + OSUtils::jsonString(j["address"],"-").c_str(), + OSUtils::jsonString(j["version"],"-").c_str(), + ((j["tcpFallbackActive"]) ? "TUNNELED" : ((j["online"]) ? "ONLINE" : "OFFLINE"))); + } } - printf("%s",out.str().c_str()); return 0; } else { printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); @@ -317,7 +319,7 @@ static int cli(int argc,char **argv) nlohmann::json j; try { - j = nlohmann::json::parse(responseBody); + j = OSUtils::jsonParse(responseBody); } catch (std::exception &exc) { printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what()); return 1; @@ -327,19 +329,18 @@ static int cli(int argc,char **argv) } if (scode == 200) { - std::ostringstream out; if (json) { - out << j.dump(2) << ZT_EOL_S; + printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str()); } else { - out << "200 listpeers " << ZT_EOL_S; + printf("200 listpeers " ZT_EOL_S); if (j.is_array()) { for(unsigned long k=0;k() << " " << bestPath << " " << p["latency"] << " " << ver << " " << p["role"].get() << ZT_EOL_S; + printf("200 listpeers %s %s %d %s %s" ZT_EOL_S, + OSUtils::jsonString(p["address"],"-").c_str(), + bestPath.c_str(), + (int)OSUtils::jsonInt(p["latency"],0), + ver, + OSUtils::jsonString(p["role"],"-").c_str()); } } } - printf("%s",out.str().c_str()); return 0; } else { printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); @@ -376,7 +381,7 @@ static int cli(int argc,char **argv) nlohmann::json j; try { - j = nlohmann::json::parse(responseBody); + j = OSUtils::jsonParse(responseBody); } catch (std::exception &exc) { printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what()); return 1; @@ -386,20 +391,19 @@ static int cli(int argc,char **argv) } if (scode == 200) { - std::ostringstream out; if (json) { - out << j.dump(2) << ZT_EOL_S; + printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str()); } else { - out << "200 listnetworks " << ZT_EOL_S; + printf("200 listnetworks " ZT_EOL_S); if (j.is_array()) { for(unsigned long i=0;i 0) aa.push_back(','); aa.append(addr.get()); @@ -407,14 +411,18 @@ static int cli(int argc,char **argv) } } if (aa.length() == 0) aa = "-"; - std::string name = n["name"]; - if (name.length() == 0) name = "-"; - out << "200 listnetworks " << n["nwid"].get() << " " << name << " " << n["mac"].get() << " " << n["status"].get() << " " << n["type"].get() << " " << n["portDeviceName"].get() << " " << aa << ZT_EOL_S; + printf("200 listnetworks %s %s %s %s %s %s %s" ZT_EOL_S, + OSUtils::jsonString(n["nwid"],"-").c_str(), + OSUtils::jsonString(n["name"],"-").c_str(), + OSUtils::jsonString(n["mac"],"-").c_str(), + OSUtils::jsonString(n["status"],"-").c_str(), + OSUtils::jsonString(n["type"],"-").c_str(), + OSUtils::jsonString(n["portDeviceName"],"-").c_str(), + aa.c_str()); } } } } - printf("%s",out.str().c_str()); return 0; } else { printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); -- cgit v1.2.3