"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "apt-private/private-json-hooks.cc" between
apt-2.2.3.tar.gz and apt-2.2.4.tar.gz

About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.

private-json-hooks.cc  (apt-2.2.3):private-json-hooks.cc  (apt-2.2.4)
skipping to change at line 14 skipping to change at line 14
* Copyright (c) 2018 Canonical Ltd * Copyright (c) 2018 Canonical Ltd
* *
* SPDX-License-Identifier: GPL-2.0+ * SPDX-License-Identifier: GPL-2.0+
*/ */
#include <apt-pkg/debsystem.h> #include <apt-pkg/debsystem.h>
#include <apt-pkg/fileutl.h> #include <apt-pkg/fileutl.h>
#include <apt-pkg/macros.h> #include <apt-pkg/macros.h>
#include <apt-pkg/strutl.h> #include <apt-pkg/strutl.h>
#include <apt-private/private-json-hooks.h> #include <apt-private/private-json-hooks.h>
#include <apt-private/private-output.h>
#include <iomanip>
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <stack> #include <stack>
#include <signal.h> #include <signal.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
/** /**
* @brief Simple JSON writer * @brief Simple JSON writer
* *
* This performs no error checking, or string escaping, be careful. * This performs no error checking, so be careful.
*/ */
class APT_HIDDEN JsonWriter class APT_HIDDEN JsonWriter
{ {
std::ostream &os; std::ostream &os;
std::locale old_locale; std::locale old_locale;
enum write_state enum write_state
{ {
empty, empty,
in_array_first_element, in_array_first_element,
skipping to change at line 81 skipping to change at line 83
void pushState(write_state state) void pushState(write_state state)
{ {
old_states.push(this->state); old_states.push(this->state);
this->state = state; this->state = state;
} }
void popState() void popState()
{ {
this->state = old_states.top(); this->state = old_states.top();
old_states.pop();
} }
public: public:
explicit JsonWriter(std::ostream &os) : os(os), old_locale{os.imbue(std::loca le::classic())} {} explicit JsonWriter(std::ostream &os) : os(os), old_locale{os.imbue(std::loca le::classic())} {}
~JsonWriter() { os.imbue(old_locale); } ~JsonWriter() { os.imbue(old_locale); }
JsonWriter &beginArray() JsonWriter &beginArray()
{ {
maybeComma(); maybeComma();
pushState(in_array_first_element); pushState(in_array_first_element);
os << '['; os << '[';
skipping to change at line 112 skipping to change at line 115
pushState(in_object_first_key); pushState(in_object_first_key);
os << '{'; os << '{';
return *this; return *this;
} }
JsonWriter &endObject() JsonWriter &endObject()
{ {
popState(); popState();
os << '}'; os << '}';
return *this; return *this;
} }
std::ostream &encodeString(std::ostream &out, std::string const &str)
{
out << '"';
for (std::string::const_iterator c = str.begin(); c != str.end(); c++)
{
if (*c <= 0x1F || *c == '"' || *c == '\\')
ioprintf(out, "\\u%04X", *c);
else
out << *c;
}
out << '"';
return out;
}
JsonWriter &name(std::string const &name) JsonWriter &name(std::string const &name)
{ {
maybeComma(); maybeComma();
os << '"' << name << '"' << ':'; encodeString(os, name) << ':';
return *this; return *this;
} }
JsonWriter &value(std::string const &value) JsonWriter &value(std::string const &value)
{ {
maybeComma(); maybeComma();
os << '"' << value << '"'; encodeString(os, value);
return *this; return *this;
} }
JsonWriter &value(const char *value) JsonWriter &value(const char *value)
{ {
maybeComma(); maybeComma();
os << '"' << value << '"'; if (value == nullptr)
os << "null";
else
encodeString(os, value);
return *this; return *this;
} }
JsonWriter &value(int value) JsonWriter &value(int value)
{ {
maybeComma(); maybeComma();
os << value; os << value;
return *this; return *this;
} }
JsonWriter &value(long value) JsonWriter &value(long value)
{ {
skipping to change at line 318 skipping to change at line 339
std::string HelloData = BuildHelloMessage(); std::string HelloData = BuildHelloMessage();
std::string ByeData = BuildByeMessage(); std::string ByeData = BuildByeMessage();
bool result = true; bool result = true;
Configuration::Item const *Opts = _config->Tree(option.c_str()); Configuration::Item const *Opts = _config->Tree(option.c_str());
if (Opts == 0 || Opts->Child == 0) if (Opts == 0 || Opts->Child == 0)
return true; return true;
Opts = Opts->Child; Opts = Opts->Child;
// Flush output before calling hooks
std::clog.flush();
std::cerr.flush();
std::cout.flush();
c2out.flush();
c1out.flush();
sighandler_t old_sigpipe = signal(SIGPIPE, SIG_IGN); sighandler_t old_sigpipe = signal(SIGPIPE, SIG_IGN);
sighandler_t old_sigint = signal(SIGINT, SIG_IGN); sighandler_t old_sigint = signal(SIGINT, SIG_IGN);
sighandler_t old_sigquit = signal(SIGQUIT, SIG_IGN); sighandler_t old_sigquit = signal(SIGQUIT, SIG_IGN);
unsigned int Count = 1; unsigned int Count = 1;
for (; Opts != 0; Opts = Opts->Next, Count++) for (; Opts != 0; Opts = Opts->Next, Count++)
{ {
if (Opts->Value.empty() == true) if (Opts->Value.empty() == true)
continue; continue;
 End of changes. 9 change blocks. 
4 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)