From: Gunnar Beutner Date: Mon, 30 Apr 2012 06:22:30 +0000 (+0200) Subject: Bugfix: Exception for invalid messages wasn't properly dealt with. X-Git-Tag: v0.0.1~567 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e4788720d2803402bd20a89978f0a10de7ddd02;p=icinga2 Bugfix: Exception for invalid messages wasn't properly dealt with. --- diff --git a/base/configobject.cpp b/base/configobject.cpp index 2189348fe..c0dfbe96e 100644 --- a/base/configobject.cpp +++ b/base/configobject.cpp @@ -27,7 +27,7 @@ ConfigObject::ConfigObject(const string& type, const string& name) void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive) { if (m_Hive.lock()) - throw InvalidArgumentException(); + throw InvalidArgumentException("Config object already has a parent hive."); m_Hive = hive; OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this()); diff --git a/base/dictionary.cpp b/base/dictionary.cpp index 6db6d6a59..4e8a25b70 100644 --- a/base/dictionary.cpp +++ b/base/dictionary.cpp @@ -76,7 +76,7 @@ bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value) dictionary = dynamic_pointer_cast(data.GetObject()); if (dictionary == NULL) - throw InvalidArgumentException(); + throw InvalidArgumentException("Property is not a dictionary."); *value = dictionary; diff --git a/icinga/endpointmanager.cpp b/icinga/endpointmanager.cpp index dd05c96e7..e1ebfac96 100644 --- a/icinga/endpointmanager.cpp +++ b/icinga/endpointmanager.cpp @@ -128,7 +128,7 @@ void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRe string method; if (!request.GetMethod(&method)) - throw InvalidArgumentException(); + throw InvalidArgumentException("Message is missing the 'method' property."); for (list::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++) { diff --git a/jsonrpc/jsonrpcclient.cpp b/jsonrpc/jsonrpcclient.cpp index 8db0a1cb8..e7f0f4c00 100644 --- a/jsonrpc/jsonrpcclient.cpp +++ b/jsonrpc/jsonrpcclient.cpp @@ -19,26 +19,22 @@ void JsonRpcClient::SendMessage(const Message& message) int JsonRpcClient::DataAvailableHandler(const EventArgs& ea) { - Message message; - bool message_read; - while (true) { try { - message_read = Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message); + Message message; + + if (Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message)) { + NewMessageEventArgs nea; + nea.Source = shared_from_this(); + nea.Message = message; + OnNewMessage(nea); + } } catch (const Exception& ex) { - cerr << "Exception while reading from JSON-RPC client: " << ex.GetMessage() << endl; + Application::Log("Exception while processing message from JSON-RPC client: " + ex.GetMessage()); Close(); return 1; } - - if (!message_read) - break; - - NewMessageEventArgs nea; - nea.Source = shared_from_this(); - nea.Message = message; - OnNewMessage(nea); } return 0;