X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FMyHandler.cpp;h=1a7fdc5ee453820009ee8568652a609419687ab3;hb=refs%2Fheads%2Fmaster;hp=7d312ef098e8be69d6526a2742112380c80dc811;hpb=e688b5354af3a5fe0add859710cae41ffe123f65;p=anna.git diff --git a/example/diameter/launcher/MyHandler.cpp b/example/diameter/launcher/MyHandler.cpp index 7d312ef..1a7fdc5 100644 --- a/example/diameter/launcher/MyHandler.cpp +++ b/example/diameter/launcher/MyHandler.cpp @@ -49,7 +49,7 @@ void MyHandler::sendResponse(anna::comm::ClientSocket& clientSocket, anna::http: } void MyHandler::evRequest(anna::comm::ClientSocket& clientSocket, const anna::http::Request& request) -throw(anna::RuntimeException) { +noexcept(false) { const anna::DataBlock& body = request.getBody(); anna::http::Method::Type::_v method = request.getMethod(); @@ -368,31 +368,6 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str auto it = j.find("condition"); if (it != j.end() && it->is_object()) { -/* - auto j2 = it->get(); - - // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId] - auto it_code = j2.find("code"); - auto it_bitR = j2.find("bitR"); - auto it_hopByHop = j2.find("hopByHop"); - auto it_applicationId = j2.find("applicationId"); - auto it_sessionId = j2.find("sessionId"); - auto it_resultCode = j2.find("resultCode"); - auto it_msisdn = j2.find("msisdn"); - auto it_imsi = j2.find("imsi"); - auto it_serviceContextId = j2.find("serviceContextId"); - - std::string p1 = (it_code != j2.end() && it_code->is_string()) ? *it_code : ""; - std::string p2 = (it_bitR != j2.end() && it_bitR->is_string()) ? *it_bitR : ""; - std::string p3 = (it_hopByHop != it->end() && it_hopByHop->is_string()) ? *it_hopByHop : ""; - std::string p4 = (it_applicationId != it->end() && it_applicationId->is_string()) ? *it_applicationId : ""; - std::string p5 = (it_sessionId != it->end() && it_sessionId->is_string()) ? *it_sessionId : ""; - std::string p6 = (it_resultCode != it->end() && it_resultCode->is_string()) ? *it_resultCode : ""; - std::string p7 = (it_msisdn != it->end() && it_msisdn->is_string()) ? *it_msisdn : ""; - std::string p8 = (it_imsi != it->end() && it_imsi->is_string()) ? *it_imsi : ""; - std::string p9 = (it_serviceContextId != it->end() && it_serviceContextId->is_string()) ? *it_serviceContextId : ""; -*/ - // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId] auto it_code = it->find("code"); auto it_bitR = it->find("bitR"); @@ -477,19 +452,16 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str } else if (opType == "/test-reset") { auto it = j.find("type"); - if (it != j.end() && it->is_string()) { + std::string type = (it != j.end() && it->is_string()) ? *it : "soft"; - auto itI = j.find("id"); - int id = (itI != j.end() && itI->is_number_integer()) ? itI->get() : -2; // default is: apply to all the tests + auto itI = j.find("id"); + int id = (itI != j.end() && itI->is_number_integer()) ? itI->get() : -1; // default is: apply to all the tests - if ((*it == "soft") || (*it == "hard")) { - result = eop.test__reset(response, (*it == "soft"), id); - } - else - response += "invalid 'type' string field (allowed: soft|hard)"; + if ((type == "soft") || (type == "hard")) { + result = eop.test__reset(response, (type == "soft"), id); } else - response += "missing 'type' string field"; + response += "invalid 'type' string field (allowed: [soft]|hard)"; } else if (opType == "/test-repeats") { auto it = j.find("amount"); @@ -518,14 +490,14 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str result = eop.test__finished(response); } else if (opType == "/test-clear") { - result = eop.test__clear(response); + auto it = j.find("id"); + int id = (it != j.end() && it->is_number_integer()) ? it->get() : -1; // default is: all + result = eop.test__clear(response, id); } else if (opType == "/test-junit") { auto it = j.find("targetFile"); - if (it != j.end() && it->is_string()) - result = eop.test__junit(response, *it); - else - response += "missing 'targetFile' string field"; + std::string targetFile = (it != j.end() && it->is_string()) ? *it : "/tmp/junit.xml"; + result = eop.test__junit(response, targetFile); } else if (opType == "/test-summary-counts") { result = eop.test__summary_counts(response); @@ -549,7 +521,7 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str else response += "invalid 'action' string field (allowed: enable|disable)"; } - else if ((opType == "/test-report-hex")||(opType == "/test-dump_stdout")) { + else if ((opType == "/test-report-hex")||(opType == "/test-dump-stdout")) { auto itA = j.find("action"); std::string action = (itA != j.end() && itA->is_string()) ? *itA : "enable"; // default is: enable @@ -566,6 +538,16 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str response += "invalid 'action' string field (allowed: enable|disable)"; } + // Dynamic procedure + else if ((opType == "/dynamic")) { + auto it = j.find("arguments"); + if (it != j.end() && it->is_object()) { + result = eop.test__dynamic(response, *it); + } + else + response += "missing 'arguments' object field"; + } + return result; }