Query::Query(const std::vector<String>& lines)
: m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1)
{
+ if (lines.size() == 0) {
+ m_Verb = "ERROR";
+ m_ErrorCode = LivestatusErrorQuery;
+ m_ErrorMessage = "Empty Query. Aborting.";
+ return;
+ }
+
String line = lines[0];
size_t sp_index = line.FindFirstOf(" ");
m_Table = target;
} else {
m_Verb = "ERROR";
- m_ErrorCode = 452;
+ m_ErrorCode = LivestatusErrorQuery;
m_ErrorMessage = "Unknown livestatus verb: " + m_Verb;
return;
}
if (!filter) {
m_Verb = "ERROR";
- m_ErrorCode = 452;
+ m_ErrorCode = LivestatusErrorQuery;
m_ErrorMessage = "Invalid filter specification: " + line;
return;
}
if (tokens.size() < 2) {
m_Verb = "ERROR";
- m_ErrorCode = 452;
+ m_ErrorCode = LivestatusErrorQuery;
m_ErrorMessage = "Missing aggregator column name: " + line;
return;
}
if (!filter) {
m_Verb = "ERROR";
- m_ErrorCode = 452;
+ m_ErrorCode = LivestatusErrorQuery;
m_ErrorMessage = "Invalid filter specification: " + line;
return;
}
Table::Ptr table = Table::GetByName(m_Table);
if (!table) {
- SendResponse(stream, 404, "Table '" + m_Table + "' does not exist.");
+ SendResponse(stream, LivestatusErrorNotFound, "Table '" + m_Table + "' does not exist.");
return;
}
std::ostringstream result;
PrintResultSet(result, columns, rs);
- SendResponse(stream, 200, result.str());
+ SendResponse(stream, LivestatusErrorOK, result.str());
}
void Query::ExecuteCommandHelper(const Stream::Ptr& stream)
{
Log(LogInformation, "livestatus", "Executing command: " + m_Command);
ExternalCommandProcessor::Execute(m_Command);
- SendResponse(stream, 200, "");
+ SendResponse(stream, LivestatusErrorOK, "");
}
void Query::ExecuteErrorHelper(const Stream::Ptr& stream)
if (m_ResponseHeader == "fixed16")
PrintFixed16(stream, code, data);
- if (m_ResponseHeader == "fixed16" || code == 200)
+ if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK)
stream->Write(data.CStr(), data.GetLength());
}
std::ostringstream info;
st->Print(info);
Log(LogWarning, "livestatus", info.str());
- SendResponse(stream, 452, boost::diagnostic_information(ex));
+ SendResponse(stream, LivestatusErrorQuery, boost::diagnostic_information(ex));
}
if (!m_KeepAlive) {