add define query
This commit is contained in:
+18
-2
@@ -921,8 +921,6 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
|||||||
Message* message;
|
Message* message;
|
||||||
result_t ret;
|
result_t ret;
|
||||||
if (newDefinition) {
|
if (newDefinition) {
|
||||||
time_t now;
|
|
||||||
time(&now);
|
|
||||||
string errorDescription;
|
string errorDescription;
|
||||||
istringstream defstr("#\n" + args[argPos]); // ensure first line is not used for determining col names
|
istringstream defstr("#\n" + args[argPos]); // ensure first line is not used for determining col names
|
||||||
m_newlyDefinedMessages->clear();
|
m_newlyDefinedMessages->clear();
|
||||||
@@ -2004,6 +2002,7 @@ bool parseBoolQuery(const string& value) {
|
|||||||
result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostringstream* ostream) {
|
result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostringstream* ostream) {
|
||||||
bool required = false, full = false, withWrite = false, raw = false;
|
bool required = false, full = false, withWrite = false, raw = false;
|
||||||
bool withDefinition = false;
|
bool withDefinition = false;
|
||||||
|
string newDefinition;
|
||||||
OutputFormat verbosity = OF_NAMES;
|
OutputFormat verbosity = OF_NAMES;
|
||||||
time_t maxAge = -1;
|
time_t maxAge = -1;
|
||||||
size_t argPos = 1;
|
size_t argPos = 1;
|
||||||
@@ -2072,6 +2071,18 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
|
|||||||
raw = parseBoolQuery(value);
|
raw = parseBoolQuery(value);
|
||||||
} else if (qname == "def") {
|
} else if (qname == "def") {
|
||||||
withDefinition = parseBoolQuery(value);
|
withDefinition = parseBoolQuery(value);
|
||||||
|
} else if (qname == "define") {
|
||||||
|
if (!m_newlyDefinedMessages || circuit.empty() || name.empty() || value.empty()) {
|
||||||
|
ret = RESULT_ERR_INVALID_ARG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
size_t comma = value.find(',');
|
||||||
|
if (comma == string::npos || comma == 0
|
||||||
|
|| value.find(circuit+","+name+",") != comma+1) { // ensure same circuit+name
|
||||||
|
ret = RESULT_ERR_INVALID_ARG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
newDefinition = value;
|
||||||
} else if (qname == "user") {
|
} else if (qname == "user") {
|
||||||
user = value;
|
user = value;
|
||||||
} else if (qname == "secret") {
|
} else if (qname == "secret") {
|
||||||
@@ -2091,6 +2102,11 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
|
|||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
time_t maxLastUp = 0;
|
time_t maxLastUp = 0;
|
||||||
|
if (ret == RESULT_OK && !newDefinition.empty()) {
|
||||||
|
string errorDescription;
|
||||||
|
istringstream defstr("#\n" + newDefinition); // ensure first line is not used for determining col names
|
||||||
|
ret = m_messages->readFromStream(&defstr, "temporary", now, true, nullptr, &errorDescription, true);
|
||||||
|
}
|
||||||
if (ret == RESULT_OK) {
|
if (ret == RESULT_OK) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
verbosity |= OF_JSON | (full ? OF_ALL_ATTRS : OF_NONE) | (withDefinition ? OF_DEFINITION : OF_NONE);
|
verbosity |= OF_JSON | (full ? OF_ALL_ATTRS : OF_NONE) | (withDefinition ? OF_DEFINITION : OF_NONE);
|
||||||
|
|||||||
Reference in New Issue
Block a user