Przeglądaj źródła

HPCC-17977 Add session ID to ESP session xml tag

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 7 lat temu
rodzic
commit
22ebbc039d

+ 8 - 7
esp/bindings/http/platform/httpservice.cpp

@@ -1306,7 +1306,7 @@ EspAuthState CEspHttpServer::authExistingSession(EspAuthRequest& authReq, unsign
         }
     }
 
-    VStringBuffer xpath("%s[@port=\"%d\"]/%s[%s='%u']", PathSessionApplication, authReq.authBinding->getPort(), PathSessionSession, PropSessionID, sessionID);
+    VStringBuffer xpath("%s[@port=\"%d\"]/%s%u", PathSessionApplication, authReq.authBinding->getPort(), PathSessionSession, sessionID);
     IPropertyTree* sessionTree = espSessions->queryBranch(xpath.str());
     if (!authReq.serviceName.isEmpty() && !authReq.methodName.isEmpty() && strieq(authReq.serviceName.str(), "esp"))
     {
@@ -1378,7 +1378,7 @@ void CEspHttpServer::logoutSession(EspAuthRequest& authReq, unsigned sessionID,
     if (sessionTree)
     {
         ICopyArrayOf<IPropertyTree> toRemove;
-        path.setf("%s[%s='%d']", PathSessionSession, PropSessionID, sessionID);
+        path.setf("%s%u", PathSessionSession, sessionID);
         Owned<IPropertyTreeIterator> it = sessionTree->getElements(path.str());
         ForEach(*it)
             toRemove.append(it->query());
@@ -1453,15 +1453,15 @@ unsigned CEspHttpServer::createHTTPSession(EspHttpBinding* authBinding, const ch
     now.setNow();
     time_t createTime = now.getSimple();
 
-    StringBuffer peer, sessionIDStr;
+    StringBuffer peer, sessionIDStr, sessionTag;
     VStringBuffer idStr("%s_%ld", m_request->getPeer(peer).str(), createTime);
     unsigned sessionID = hashc((unsigned char *)idStr.str(), idStr.length(), 0);
     sessionIDStr.append(sessionID);
 
-    VStringBuffer xpath("%s[%s='%u']", PathSessionSession, PropSessionID, sessionID);
+    sessionTag.appendf("%s%u", PathSessionSession, sessionID);
     Owned<IRemoteConnection> conn = getSDSConnection(authBinding->querySessionSDSPath(), RTM_LOCK_WRITE, SESSION_SDS_LOCK_TIMEOUT);
     IPropertyTree* domainSessions = conn->queryRoot();
-    IPropertyTree* sessionTree = domainSessions->queryBranch(xpath.str());
+    IPropertyTree* sessionTree = domainSessions->queryBranch(sessionTag.str());
     if (sessionTree)
     {
         sessionTree->setPropInt64(PropSessionLastAccessed, createTime);
@@ -1471,7 +1471,7 @@ unsigned CEspHttpServer::createHTTPSession(EspHttpBinding* authBinding, const ch
     }
     ESPLOG(LogMax, "New sessionID <%d> at <%ld> in createHTTPSession()", sessionID, createTime);
 
-    IPropertyTree* ptree = domainSessions->addPropTree(PathSessionSession);
+    IPropertyTree* ptree = domainSessions->addPropTree(sessionTag.str());
     ptree->setProp(PropSessionNetworkAddress, peer.str());
     ptree->setPropInt64(PropSessionID, sessionID);
     ptree->setPropInt64(PropSessionExternalID, hashc((unsigned char *)sessionIDStr.str(), sessionIDStr.length(), 0));
@@ -1490,11 +1490,12 @@ void CEspHttpServer::timeoutESPSessions(EspHttpBinding* authBinding, IPropertyTr
     now.setNow();
     time_t timeNow = now.getSimple();
 
+    VStringBuffer xpath("%s*", PathSessionSession);
     Owned<IPropertyTreeIterator> iter1 = espSessions->getElements(PathSessionApplication);
     ForEach(*iter1)
     {
         ICopyArrayOf<IPropertyTree> toRemove;
-        Owned<IPropertyTreeIterator> iter2 = iter1->query().getElements(PathSessionSession);
+        Owned<IPropertyTreeIterator> iter2 = iter1->query().getElements(xpath.str());
         ForEach(*iter2)
         {
             IPropertyTree& item = iter2->query();

+ 10 - 9
esp/platform/espcontext.hpp

@@ -46,7 +46,7 @@ static const char* const DEFAULT_UNRESTRICTED_RESOURCES = "/favicon.ico,/esp/fil
 static const char* const PathSessionRoot="Sessions";
 static const char* const PathSessionProcess="Process";
 static const char* const PathSessionApplication="Application";
-static const char* const PathSessionSession="Session";
+static const char* const PathSessionSession="Session_";
 static const char* const PropSessionID = "@id";
 static const char* const PropSessionExternalID = "@externalid";
 static const char* const PropSessionUserID = "@userid";
@@ -61,28 +61,29 @@ static const char* const PropSessionLoginURL = "@loginurl";
 <Sessions>
  <Process name="myesp">
    <Application port="8010">
-    <Session createtime="1497376914"
+    <Session_3831947145 createtime="1497376914"
              id="3831947145"
              lastaccessed="1497377015"
+             timeoutAt="1497477015"
              loginurl="/"
              netaddr="10.176.152.200"
-             state="1"
-             userid="TheAdmin"/>
-    <Session createtime="1497377427"
+             userid="user1"/>
+    <Session_4106750941 createtime="1497377427"
              id="4106750941"
              lastaccessed="1497377427"
+             timeoutAt="1497477427"
              loginurl="/"
              netaddr="10.176.152.200"
-             state="0"/>
+             userid="user2"/>
    </Application>
    <Application port="8002">
-    <Session createtime="1497376989"
+    <Session_3680948651 createtime="1497376989"
              id="3680948651"
              lastaccessed="1497377003"
+             timeoutAt="1497477003"
              loginurl="/"
              netaddr="10.176.152.200"
-             state="1"
-             userid="TheAdmin"/>
+             userid="user1"/>
    </Application>
  </Process>
 </Sessions>

+ 4 - 4
esp/services/espcontrol/ws_espcontrolservice.cpp

@@ -176,7 +176,7 @@ bool CWSESPControlEx::onSessionInfo(IEspContext& context, IEspSessionInfoRequest
             port = req.getPort();
 
         Owned<IRemoteConnection> globalLock;
-        VStringBuffer xpath("/%s/%s[@name='%s']/%s[@port='%d']/%s[%s='%s']", PathSessionRoot, PathSessionProcess, espProcess.get(),
+        VStringBuffer xpath("/%s/%s[@name='%s']/%s[@port='%d']/%s*[%s='%s']", PathSessionRoot, PathSessionProcess, espProcess.get(),
             PathSessionApplication, port, PathSessionSession, PropSessionExternalID, id.str());
         try
         {
@@ -288,11 +288,11 @@ const char* CWSESPControlEx::setSessionXPath(bool allSessions, const char* id, c
     }
 
     if (!isEmptyString(userID))
-        xPath.setf("%s[%s='%s']", PathSessionSession, PropSessionUserID, userID);
+        xPath.setf("%s*[%s='%s']", PathSessionSession, PropSessionUserID, userID);
     else if (!isEmptyString(fromIP))
-        xPath.setf("%s[%s='%s']", PathSessionSession, PropSessionNetworkAddress, fromIP);
+        xPath.setf("%s*[%s='%s']", PathSessionSession, PropSessionNetworkAddress, fromIP);
     else if (!isEmptyString(id))
-        xPath.setf("%s[%s='%s']", PathSessionSession, PropSessionExternalID, id);
+        xPath.setf("%s*[%s='%s']", PathSessionSession, PropSessionExternalID, id);
     else
         xPath.set("*");
     return xPath.str();