From 82cfe5ba5f0ff723b7b024b526ddce8b3e1a92d4 Mon Sep 17 00:00:00 2001 From: "Eduardo Ramos Testillano (eramedu)" Date: Mon, 18 May 2020 14:55:03 +0200 Subject: [PATCH] Fix bug on regexp insertion for xml messages 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 | 40 +++++++++++--------- example/diameter/launcher/Launcher.cpp | 40 +++++++++++--------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/example/diameter/launcher/EventOperation.cpp b/example/diameter/launcher/EventOperation.cpp index 4d80410..f21f729 100644 --- a/example/diameter/launcher/EventOperation.cpp +++ b/example/diameter/launcher/EventOperation.cpp @@ -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: //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: 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 += "$"; diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 487c632..30637be 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -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: //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: 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 += "$"; -- 2.20.1