Report IPMI session IDs for active IPMI sessions

The Get Session Info command failed to return the session ID for the
session requested. Instead it always returned the value of the last
record processed.

This commit returns the correct session ID for the requested record.

Tested:
Created multiple 'ipmitool shell' or 'ipmitool sol' sessions
Used 'ipmitool raw 6 0x3d <rec-num>' to iterate over each session.
  0 to <rec-num>
Used 'ipmitool session info all' to get a human friendly output.

Prior to this commit 'session info all' returned a single session ID
value for all records:
session handle                : 1

Now the session handle reports the value created by the BMC:
session handle                : 129
The session handle is unique for each active 'shell'/'sol'

Change-Id: Ied35f021a18ca302b5285d56bf9b51b3ebc52543
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/apphandler.cpp b/apphandler.cpp
index 6591afa..fe74bb0 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -1226,6 +1226,7 @@
     uint8_t totalSessionCount = getTotalSessionCount();
     uint8_t activeSessionCount = 0;
     uint8_t sessionHandle = session::defaultSessionHandle;
+    uint8_t activeSessionHandle = 0;
     std::optional<SessionDetails> maybeDetails;
     uint8_t index = 0;
     for (auto& objectTreeItr : objectTree)
@@ -1261,28 +1262,26 @@
             activeSessionCount++;
         }
 
-        if (index != sessionIndex && reqSessionId != sessionId &&
-            reqSessionHandle != sessionHandle)
+        if (index == sessionIndex || reqSessionId == sessionId ||
+            reqSessionHandle == sessionHandle)
         {
-            continue;
-        }
+            SessionDetails details{};
+            completionCode = getSessionDetails(ctx, service, objectPath,
+                                               sessionHandle, state, details);
 
-        SessionDetails details{};
-        completionCode = getSessionDetails(ctx, service, objectPath,
-                                           sessionHandle, state, details);
-
-        if (completionCode)
-        {
-            return ipmi::response(completionCode);
+            if (completionCode)
+            {
+                return ipmi::response(completionCode);
+            }
+            activeSessionHandle = sessionHandle;
+            maybeDetails = std::move(details);
         }
-        maybeDetails = std::move(details);
-        break;
     }
 
     if (state == static_cast<uint8_t>(session::State::active) ||
         state == static_cast<uint8_t>(session::State::tearDownInProgress))
     {
-        return ipmi::responseSuccess(sessionHandle, totalSessionCount,
+        return ipmi::responseSuccess(activeSessionHandle, totalSessionCount,
                                      activeSessionCount, maybeDetails);
     }