Fix bug on regexp insertion for xml messages
authorEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Mon, 18 May 2020 12:55:03 +0000 (14:55 +0200)
committerEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Mon, 18 May 2020 12:55:03 +0000 (14:55 +0200)
We must check that the elements are found before
replacing items by [0-9]+.
This is because Origin-State-Id is not always sent.

example/diameter/launcher/EventOperation.cpp
example/diameter/launcher/Launcher.cpp

index 4d80410..f21f729 100644 (file)
@@ -754,18 +754,22 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i
       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);
@@ -777,13 +781,15 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i
       //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 += "$";
index 487c632..30637be 100644 (file)
@@ -1820,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);
@@ -1843,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 += "$";