From 137941982c1438b1dd6ef6519f86cb4acf15a32f Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 7 Jun 2015 18:39:40 +0200 Subject: [PATCH] fix for query string keys without value, added required option to JSON --- ChangeLog.md | 3 ++- src/ebusd/mainloop.cpp | 59 ++++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 21 deletions(-) mode change 100644 => 100755 src/ebusd/mainloop.cpp diff --git a/ChangeLog.md b/ChangeLog.md index 125f8465..3baf9bc1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,11 +2,12 @@ ## Bug fixes * fix for numeric parsing of empty string +* allow HTTP port query string keys without value ## Features * new "read" option "-n" for retrieving name/value pairs in numeric form * new "find" option "-e" for exactly matching name and optional circuit (ignoring case) -* added numeric and verbose options to JSON and use "null" for unset or replacement value +* added numeric, verbose, and required options to JSON and use "null" for unset or replacement value * allow static ".json" files being served by HTTP port * allow passing raw value when writing name/value pairs diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp old mode 100644 new mode 100755 index fbdf750c..def8efc6 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -868,7 +868,7 @@ string MainLoop::executeHelp() string MainLoop::executeGet(vector &args, bool& connected) { result_t ret = RESULT_OK; - bool verbose = false, numeric = false; + bool verbose = false, numeric = false, required = false; size_t argPos = 1; string uri = args[argPos++]; ostringstream result; @@ -891,23 +891,28 @@ string MainLoop::executeGet(vector &args, bool& connected) string token; while (getline(stream, token, '&') != 0) { pos = token.find('='); + string qname, value; if (pos != string::npos) { - string qname = token.substr(0, pos); - string value = token.substr(pos+1); - if (strcmp(qname.c_str(), "since") == 0) { - since = parseInt(value.c_str(), 10, 0, 0xffffffff, ret); - } else if (strcmp(qname.c_str(), "poll") == 0) { - pollPriority = (unsigned char)parseInt(value.c_str(), 10, 1, 9, ret); - } else if (strcmp(qname.c_str(), "exact") == 0) { - exact = value.length()==0 || strcmp(value.c_str(), "1") == 0; - } else if (strcmp(qname.c_str(), "verbose") == 0) { - verbose = value.length()==0 || strcmp(value.c_str(), "1") == 0; - } else if (strcmp(qname.c_str(), "numeric") == 0) { - numeric = value.length()==0 || strcmp(value.c_str(), "1") == 0; - } - if (ret != RESULT_OK) - break; + qname = token.substr(0, pos); + value = token.substr(pos+1); + } else { + qname = token; } + if (strcmp(qname.c_str(), "since") == 0) { + since = parseInt(value.c_str(), 10, 0, 0xffffffff, ret); + } else if (strcmp(qname.c_str(), "poll") == 0) { + pollPriority = (unsigned char)parseInt(value.c_str(), 10, 1, 9, ret); + } else if (strcmp(qname.c_str(), "exact") == 0) { + exact = value.length()==0 || strcmp(value.c_str(), "1") == 0; + } else if (strcmp(qname.c_str(), "verbose") == 0) { + verbose = value.length()==0 || strcmp(value.c_str(), "1") == 0; + } else if (strcmp(qname.c_str(), "numeric") == 0) { + numeric = value.length()==0 || strcmp(value.c_str(), "1") == 0; + } else if (strcmp(qname.c_str(), "required") == 0) { + required = value.length()==0 || strcmp(value.c_str(), "1") == 0; + } + if (ret != RESULT_OK) + break; } } deque messages = m_messages->findAll(clazz, name, -1, exact, true, false, true); @@ -924,10 +929,24 @@ string MainLoop::executeGet(vector &args, bool& connected) if (pollPriority > 0 && message->setPollPriority(pollPriority)) m_messages->addPollMessage(message); time_t lastup = message->getLastUpdateTime(); - if (since > 0 && lastup <= since) - continue; - if (lastup > maxLastUp) - maxLastUp = lastup; + if (lastup == 0 && required) { + // read directly from bus + SymbolString master(true); + SymbolString slave(false); + result_t ret = readFromBus(message, master, "", slave); + if (ret == RESULT_OK) { + ostringstream temp; + ret = message->decode(pt_slaveData, slave, temp); + } + if (ret != RESULT_OK) + break; + lastup = message->getLastUpdateTime(); + } else { + if (since > 0 && lastup <= since) + continue; + if (lastup > maxLastUp) + maxLastUp = lastup; + } if (message->getCircuit() != lastCircuit) { if (lastCircuit.length() > 0) result << "\n },";