[icinga-checkins] icinga.org: icinga2/feature/livestatus-bygroup-7361: Cli: Fix NetString:: ReadStringFromStream() usage

git at icinga.org git at icinga.org
Sun Feb 15 17:04:28 CET 2015


Module: icinga2
Branch: feature/livestatus-bygroup-7361
Commit: f201886865d7a02763edd8f3c4af7d14d7b5b66c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=f201886865d7a02763edd8f3c4af7d14d7b5b66c

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sun Feb 15 14:42:53 2015 +0100

Cli: Fix NetString::ReadStringFromStream() usage

refs #6109

---

 lib/cli/troubleshootcollectcommand.cpp |   10 +++++++++-
 lib/cli/variableutility.cpp            |   18 ++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/lib/cli/troubleshootcollectcommand.cpp b/lib/cli/troubleshootcollectcommand.cpp
index d9bfad5..f9c27ac 100644
--- a/lib/cli/troubleshootcollectcommand.cpp
+++ b/lib/cli/troubleshootcollectcommand.cpp
@@ -244,10 +244,18 @@ static void CheckObjectFile(const String& objectfile, std::ostream& os)
 	StdioStream::Ptr sfp = new StdioStream(&fp, false);
 
 	int typeL = 0, countTotal = 0;
+
 	String message;
 	StreamReadContext src;
+	for (;;) {
+		StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src);
+
+		if (srs == StatusEof)
+			break;
+
+		if (srs != StatusNewItem)
+			continue;
 
-	while (NetString::ReadStringFromStream(sfp, &message, src) == StatusNewItem) {
 		Dictionary::Ptr object = JsonDecode(message);
 		Dictionary::Ptr properties = object->Get("properties");
 
diff --git a/lib/cli/variableutility.cpp b/lib/cli/variableutility.cpp
index 51305e3..be37869 100644
--- a/lib/cli/variableutility.cpp
+++ b/lib/cli/variableutility.cpp
@@ -40,8 +40,15 @@ Value VariableUtility::GetVariable(const String& name)
 
 	String message;
 	StreamReadContext src;
+	for (;;) {
+		StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src);
+
+		if (srs == StatusEof)
+			break;
+
+		if (srs != StatusNewItem)
+			continue;
 
-	while (NetString::ReadStringFromStream(sfp, &message, src) == StatusNewItem) {
 		Dictionary::Ptr variable = JsonDecode(message);
 
 		if (variable->Get("name") == name) {
@@ -64,8 +71,15 @@ void VariableUtility::PrintVariables(std::ostream& outfp)
 
 	String message;
 	StreamReadContext src;
+	for (;;) {
+		StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src);
+
+		if (srs == StatusEof)
+			break;
+
+		if (srs != StatusNewItem)
+			continue;
 
-	while (NetString::ReadStringFromStream(sfp, &message, src) == StatusNewItem) {
 		Dictionary::Ptr variable = JsonDecode(message);
 		outfp << variable->Get("name") << " = " << variable->Get("value") << "\n";
 		variables_count++;



More information about the icinga-checkins mailing list