corrected uniqueness of json keys, added write as option to json get
This commit is contained in:
+18
-5
@@ -1616,7 +1616,7 @@ result_t MainLoop::executeHelp(ostringstream* ostream) {
|
||||
}
|
||||
|
||||
result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostringstream* ostream) {
|
||||
bool numeric = false, valueName = false, required = false, full = false;
|
||||
bool numeric = false, valueName = false, required = false, full = false, withWrite = false;
|
||||
OutputFormat verbosity = OF_NAMES;
|
||||
size_t argPos = 1;
|
||||
string uri = args[argPos++];
|
||||
@@ -1671,6 +1671,8 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
|
||||
full = value.length() == 0 || value == "1" || value == "true";
|
||||
} else if (qname == "required") {
|
||||
required = value.length() == 0 || value == "1" || value == "true";
|
||||
} else if (qname == "write") {
|
||||
withWrite = value.length() == 0 || value == "1" || value == "true";
|
||||
} else if (qname == "user") {
|
||||
user = value;
|
||||
} else if (qname == "secret") {
|
||||
@@ -1691,9 +1693,12 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
|
||||
if (ret == RESULT_OK) {
|
||||
bool first = true;
|
||||
verbosity |= (valueName ? OF_VALUENAME : numeric ? OF_NUMERIC : 0) | OF_JSON | (full ? OF_ALL_ATTRS : 0);
|
||||
deque<Message *> messages;
|
||||
m_messages->findAll(circuit, name, getUserLevels(user), exact, true, false, true, true, true, 0, 0, &messages);
|
||||
for (const auto message : messages) {
|
||||
deque<Message*> messages;
|
||||
m_messages->findAll(circuit, name, getUserLevels(user), exact, true, withWrite, true, true, true, 0, 0,
|
||||
&messages);
|
||||
string lastName;
|
||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
||||
Message* message = *it;
|
||||
symbol_t dstAddress = message->getDstAddress();
|
||||
if (dstAddress == SYN) {
|
||||
continue;
|
||||
@@ -1728,8 +1733,16 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
|
||||
if (full && m_messages->decodeCircuit(lastCircuit, verbosity, ostream)) { // add circuit specific values
|
||||
first = false;
|
||||
}
|
||||
lastName = "";
|
||||
}
|
||||
message->decode(!first, verbosity, ostream);
|
||||
name = message->getName();
|
||||
bool same = name == lastName;
|
||||
if (!same && !lastName.empty() && it+1 != messages.end()) {
|
||||
Message* next = *(it+1);
|
||||
same = next->getCircuit() == lastCircuit && next->getName() == name;
|
||||
}
|
||||
message->decode(!first, same, verbosity, ostream);
|
||||
lastName = name;
|
||||
first = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -927,11 +927,21 @@ void Message::dumpField(const string& fieldName, bool withConditions, ostream* o
|
||||
dumpAttribute(false, fieldName, output);
|
||||
}
|
||||
|
||||
void Message::decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const {
|
||||
void Message::decode(bool leadingSeparator, bool appendDirection, OutputFormat outputFormat, ostringstream* output)
|
||||
const {
|
||||
if (leadingSeparator) {
|
||||
*output << ",";
|
||||
}
|
||||
*output << "\n \"" << getName() << "\": {" // TODO include read/write/passive for overlapping names
|
||||
*output << "\n \"" << getName();
|
||||
if (appendDirection) {
|
||||
if (isPassive()) {
|
||||
*output << "-u";
|
||||
} else if (isWrite()) {
|
||||
*output << "-w";
|
||||
}
|
||||
}
|
||||
*output << "\": {"
|
||||
<< "\n \"name\": \"" << getName() << "\""
|
||||
<< "\n \"lastup\": " << setw(0) << dec << static_cast<unsigned>(getLastUpdateTime());
|
||||
if (getLastUpdateTime() != 0) {
|
||||
*output << ",\n \"zz\": \"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(getDstAddress()) << "\"";
|
||||
|
||||
@@ -549,12 +549,14 @@ class Message : public AttributedItem {
|
||||
virtual void dumpField(const string& fieldName, bool withConditions, ostream* output) const;
|
||||
|
||||
/**
|
||||
* Decode the message from the last stored data.
|
||||
* Decode the message from the last stored data in JSON format.
|
||||
* @param leadingSeparator whether to prepend a separator before the first value.
|
||||
* @param appendDirection whether to append the direction to the name key (for passive and write).
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
*/
|
||||
virtual void decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const;
|
||||
virtual void decode(bool leadingSeparator, bool appendDirection, OutputFormat outputFormat, ostringstream* output)
|
||||
const;
|
||||
|
||||
protected:
|
||||
/** the optional circuit name. */
|
||||
|
||||
Reference in New Issue
Block a user