Fix bug on regexp insertion for xml messages
[anna.git] / example / diameter / launcher / Launcher.cpp
index 2ad9a59..30637be 100644 (file)
@@ -189,7 +189,8 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool bindRes
   // We will register a scope per stack id registered. The counters will be dynamically registered at count method.
   anna::diameter::comm::ApplicationMessageOamModule & appMsgOamModule = anna::diameter::comm::ApplicationMessageOamModule::instantiate();
   appMsgOamModule.enableCounters(); // this special module is disabled by default (the only)
-  static int scope_id = 3;
+  static int scope_id = 3 + appMsgOamModule.scopes();
+
   unsigned int id_value;
   std::string codecEngineName;
 
@@ -1200,7 +1201,7 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons
     if(getOperatedHost()->logEnabled()) {
       anna::diameter::comm::Server *usedServer = getOperatedEntity()->getLastUsedResource();
       anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL;
-      std::string detail = usedClientSession ? usedClientSession->asString() : "<null client session>"; // shouldn't happen
+      std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // shouldn't happen
       getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail);
     }
   } else if((opType == "sendxml2c") || (opType == "sendhex2c")) {
@@ -1229,7 +1230,7 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons
     // Detailed log:
     if(getOperatedHost()->logEnabled()) {
       anna::diameter::comm::ServerSession *usedServerSession = getOperatedServer()->getLastUsedResource();
-      std::string detail = usedServerSession ? usedServerSession->asString() : "<null server session>"; // shouldn't happen
+      std::string detail = usedServerSession ? usedServerSession->asString() : "[null server session]"; // shouldn't happen
       getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail);
     }
   } else if(opType == "answerxml2e") {
@@ -1440,12 +1441,12 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons
         limit = atoi(param2.c_str());
         testManager.setInProgressLimit(limit);
         opt_response = "new in-progress limit: ";
-        opt_response += (limit != UINT_MAX) ? anna::functions::asString(limit) : "<no limit>";
+        opt_response += (limit != UINT_MAX) ? anna::functions::asString(limit) : "[no limit]";
       }
       else {
         opt_response = "in-progress limit amount: ";
         limit = testManager.getInProgressLimit();
-        opt_response += (limit != UINT_MAX) ? anna::functions::asString(limit) : "<no limit>";
+        opt_response += (limit != UINT_MAX) ? anna::functions::asString(limit) : "[no limit]";
         opt_response += "; currently there are ";
         opt_response += anna::functions::asString(testManager.getInProgressCount());
         opt_response += " test cases running";
@@ -1819,18 +1820,22 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons
           std::string::size_type pos, pos_1, pos_2;
 
           pos = regexp.find("end-to-end-id=", 0u);
-          pos = regexp.find("\"", pos);
-          pos_1 = pos;
-          pos = regexp.find("\"", pos+1);
-          pos_2 = pos;
-          regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          if (pos != std::string::npos) {
+            pos = regexp.find("\"", pos);
+            pos_1 = pos;
+            pos = regexp.find("\"", pos+1);
+            pos_2 = pos;
+            regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          }
 
           pos = regexp.find("hop-by-hop-id=", 0u);
-          pos = regexp.find("\"", pos);
-          pos_1 = pos;
-          pos = regexp.find("\"", pos+1);
-          pos_2 = pos;
-          regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          if (pos != std::string::npos) {
+            pos = regexp.find("\"", pos);
+            pos_1 = pos;
+            pos = regexp.find("\"", pos+1);
+            pos_2 = pos;
+            regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          }
 
           // For this representation: <avp name="Origin-State-Id" data="1428633668"/>
           //pos = regexp.find("Origin-State-Id", 0u);
@@ -1842,13 +1847,15 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons
           //regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
           // But we have this one: <avp data="1428633668" name="Origin-State-Id"/>
           pos = regexp.find("Origin-State-Id", 0u);
-          pos = regexp.rfind("\"", pos);
-          pos = regexp.rfind("\"", pos-1);
-          pos = regexp.rfind("\"", pos-1);
-          pos_1 = pos;
-          pos = regexp.find("\"", pos+1);
-          pos_2 = pos;
-          regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          if (pos != std::string::npos) {
+            pos = regexp.rfind("\"", pos);
+            pos = regexp.rfind("\"", pos-1);
+            pos = regexp.rfind("\"", pos-1);
+            pos_1 = pos;
+            pos = regexp.find("\"", pos+1);
+            pos_2 = pos;
+            regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+          }
 
           //regexp.insert(0, "^");
           //regexp += "$";