]> granicus.if.org Git - icinga2/commitdiff
Cli: Fix NetString::ReadStringFromStream() usage
authorMichael Friedrich <michael.friedrich@netways.de>
Sun, 15 Feb 2015 13:42:53 +0000 (14:42 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Sun, 15 Feb 2015 13:42:53 +0000 (14:42 +0100)
refs #6109

lib/cli/troubleshootcollectcommand.cpp
lib/cli/variableutility.cpp

index d9bfad56fe304582a9d8ac9908ed815c8f32185f..f9c27ac3423d2c692eaeb50113d06d547236d0be 100644 (file)
@@ -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");
 
index 51305e320fbab447c368e160186d4de2a334a222..be37869c5012b20eb2409de0897a13efaa5a0ca8 100644 (file)
@@ -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++;