}
catch(anna::RuntimeException &ex) {
ex.trace();
- LOGINFORMATION(anna::Logger::information("XXXXXXXXXXXX EXCEPCION PENDIENTE DE CATCHEAR ABAJO !!! XXXXXXXXXXXXXXXXX", ANNA_FILE_LOCATION));
+ LOGINFORMATION(anna::Logger::information("doPOST exception: TODO control in inner method. Check traces", ANNA_FILE_LOCATION));
}
}
// Node management
if (opType == "/node") {
auto it = j.find("name");
- if (it != j.end())
+ if (it != j.end() && it->is_string())
result = eop.node(response, *it);
else
response += "missing 'name' string field";
// Parsing operations
else if (opType == "/code") {
auto it = j.find("diameterJson");
- if (it != j.end())
+ if (it != j.end() && it->is_object())
result = eop.code(response, it->dump(4)); // get the object as string (always indentation = 4)
else
response += "missing 'diameterJson' object field";
}
else if (opType == "/decode") {
auto it = j.find("diameterHex");
- if (it != j.end())
+ if (it != j.end() && it->is_string())
result = eop.decode(response, *it);
else
response += "missing 'diameterHex' string field";
}
else if (opType == "/loadmsg") {
auto it = j.find("diameterJson");
- if (it != j.end())
+ if (it != j.end() && it->is_object())
result = eop.loadmsg(response, it->dump(4)); // get the object as string (always indentation = 4)
else
response += "missing 'diameterJson' object field";
// Hot changes
else if (opType == "/services") {
auto it = j.find("servicesJson");
- if (it != j.end()) {
+ if (it != j.end() && it->is_object()) {
result = eop.services(response, it->dump(4)); // get the object as string (always indentation = 4)
}
else
}
else if (opType == "/diameterServerSessions") {
auto it = j.find("sessions");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.diameterServerSessions(response, it->get<int>());
else
response += "missing 'session' integer field";
}
else if (opType == "/change-dir") {
auto it = j.find("directory");
- std::string directory = (it != j.end()) ? *it : ""; // default is: restore initial directory
+ std::string directory = (it != j.end() && it->is_string()) ? *it : ""; // default is: restore initial directory
result = eop.change_dir(response, directory);
}
// Client sessions visibility
else if (opType == "/visibility") {
auto it = j.find("action");
- if (it != j.end()) {
+ if (it != j.end() && it->is_string()) {
std::string action = *it;
it = j.find("addressPort");
- std::string addressPort = (it != j.end()) ? *it : "";
+ std::string addressPort = (it != j.end() && it->is_string()) ? *it : "";
it = j.find("socket");
- int socket = (it != j.end()) ? it->get<int>() : -1;
+ int socket = (it != j.end() && it->is_number_integer()) ? it->get<int>() : -1;
result = eop.visibility(response, action, addressPort, socket);
}
}
else if (opType == "/context") {
auto it = j.find("targetFile");
- std::string targetFile = (it != j.end()) ? *it : "";
+ std::string targetFile = (it != j.end() && it->is_string()) ? *it : "";
result = eop.context(response, targetFile);
}
else if (opType == "/forceCountersRecord") {
}
else if (opType == "/log-statistics-samples") {
auto it = j.find("list");
- if (it != j.end())
- result = eop.log_statistics_samples(response, *it);
- else
- response += "missing 'list' string field";
+ std::string list = (it != j.end() && it->is_string()) ? *it : "list";
+ result = eop.log_statistics_samples(response, list);
}
// Flow operations
else if ((opType == "/sendmsg2e")||(opType == "/sendmsg2c")) {
- auto it = j.find("diameterJson");
- if (it != j.end())
+ auto itJ = j.find("diameterJson");
+ if (itJ != j.end() && itJ->is_object()) {
if (opType == "/sendmsg2e")
- result = eop.sendmsg2e(response, it->dump(4)); // get the object as string (always indentation = 4)
+ result = eop.sendmsg_hex_2e(response, itJ->dump(4), true); // get the object as string (always indentation = 4)
else
- result = eop.sendmsg2c(response, it->dump(4)); // get the object as string (always indentation = 4)
+ result = eop.sendmsg_hex_2c(response, itJ->dump(4), true); // get the object as string (always indentation = 4)
+ }
else
response += "missing 'diameterJson' object field";
}
+ else if ((opType == "/sendhex2e")||(opType == "/sendhex2c")) {
+ auto itH = j.find("diameterHex");
+ if (itH != j.end() && itH->is_string())
+ if (opType == "/sendhex2e")
+ result = eop.sendmsg_hex_2e(response, *itH, false);
+ else
+ result = eop.sendmsg_hex_2c(response, *itH, false);
+ else
+ response += "missing 'diameterHex' string field";
+ }
else if ((opType == "/answermsg2e")||(opType == "/answermsg2c")) {
auto itJ = j.find("diameterJson");
auto itA = j.find("action");
- bool hasJ = (itJ != j.end());
- bool hasA = (itA != j.end());
+ bool hasJ = (itJ != j.end() && itJ->is_object());
+ bool hasA = (itA != j.end() && itA->is_string());
if (hasJ != hasA) { // XOR
-
- if (opType == "/answermsg2e") {
- if (hasJ)
- result = eop.answermsg2e(response, itJ->dump(4)); // get the object as string (always indentation = 4)
- else
- result = eop.answermsg2e_action(response, *itA);
- }
- else {
- if (hasJ)
- result = eop.answermsg2c(response, itJ->dump(4)); // get the object as string (always indentation = 4)
- else
- result = eop.answermsg2c_action(response, *itA);
+ std::string action;
+ if (hasA) {
+ action = *itA;
+ if (action == "") action = "list"; // default if missing
}
+
+ if (opType == "/answermsg2e")
+ result = eop.answermsg_action_2e(response, (hasJ ? itJ->dump(4) : action), hasJ); // itJ: get the object as string (always indentation = 4)
+ else
+ result = eop.answermsg_action_2c(response, (hasJ ? itJ->dump(4) : action), hasJ); // itJ: get the object as string (always indentation = 4)
}
else
response += "missing 'diameterJson' object or 'action' string field (only one accepted)";
}
- else if ((opType == "/sendhex2e")||(opType == "/sendhex2c")) {
- auto it = j.find("diameterHex");
- if (it != j.end())
- if (opType == "/sendhex2e")
- result = eop.sendhex2e(response, *it);
- else
- result = eop.sendhex2c(response, *it);
- else
- response += "missing 'diameterHex' string field";
- }
// FSM testing
// test_id__<command>
else if (opType == "/testid-description") {
auto it = j.find("description");
- if (it != j.end())
+ if (it != j.end() && it->is_string())
result = eop.test_id__description(response, atoi(param1.c_str()), *it);
else
response += "missing 'description' string field";
}
else if (opType == "/testid-ip-limit") {
auto it = j.find("amount");
- int amount = (it != j.end()) ? it->get<int>() : 1;
+ int amount = (it != j.end() && it->is_number_integer()) ? it->get<int>() : 1;
result = eop.test_id__ip_limit(response, atoi(param1.c_str()), amount);
}
else if (opType == "/testid-timeout") {
auto it = j.find("msecs");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test_id__timeout(response, atoi(param1.c_str()), it->get<int>());
else
response += "missing 'msecs' integer field";
}
else if ((opType == "/testid-sendmsg2e")||(opType == "/testid-sendmsg2c")) {
auto it = j.find("diameterJson");
- if (it != j.end()) {
+ if (it != j.end() && it->is_object()) {
auto itS = j.find("stepNumber");
- int stepNumber = (itS != j.end()) ? itS->get<int>() : -1;
+ int stepNumber = (itS != j.end() && itS->is_number_integer()) ? itS->get<int>() : -1;
- if (opType == "/testid-sendmsg2e")
- result = eop.test_id__sendmsg2e(response, atoi(param1.c_str()), it->dump(4), stepNumber); // get the object as string (always indentation = 4)
- else
- result = eop.test_id__sendmsg2c(response, atoi(param1.c_str()), it->dump(4), stepNumber); // get the object as string (always indentation = 4)
+ result = eop.test_id__sendmsg2e_2c(response, atoi(param1.c_str()),
+ (opType == "/testid-sendmsg2e"), it->dump(4), stepNumber); // get the object as string (always indentation = 4)
}
else
response += "missing 'diameterJson' object field";
}
else if (opType == "/testid-delay") {
auto it = j.find("msecs");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test_id__delay(response, atoi(param1.c_str()), it->get<int>());
else
response += "missing 'msecs' integer field";
}
else if (opType == "/testid-sh-command") {
auto it = j.find("script");
- if (it != j.end())
+ if (it != j.end() && it->is_string())
result = eop.test_id__sh_command(response, atoi(param1.c_str()), *it);
else
response += "missing 'script' string field";
}
else if ((opType == "/testid-waitfe-hex")||(opType == "/testid-waitfc-hex")) {
auto it = j.find("hex");
- if (it != j.end()) {
+ if (it != j.end() && it->is_string()) {
auto itS = j.find("strict");
- bool strict = (itS != j.end()) ? (*itS == "true") : false;
+ bool strict = (itS != j.end() && itS->is_string()) ? (*itS == "true") : false;
- if (opType == "/testid-waitfe-hex")
- result = eop.test_id__waitfe_hex(response, atoi(param1.c_str()), *it, strict);
- else
- result = eop.test_id__waitfc_hex(response, atoi(param1.c_str()), *it, strict);
+ result = eop.test_id__waitfefc_hex(response, atoi(param1.c_str()), (opType == "/testid-waitfe-hex"), *it, strict);
}
else
response += "missing 'hex' string field";
}
else if ((opType == "/testid-waitfe-msg")||(opType == "/testid-waitfc-msg")) {
auto it = j.find("diameterJson");
- if (it != j.end()) {
+ if (it != j.end() && it->is_object()) {
auto itS = j.find("strict");
- bool strict = (itS != j.end()) ? (*itS == "true") : false;
+ bool strict = (itS != j.end() && itS->is_string()) ? (*itS == "true") : false;
- if (opType == "/testid-waitfe-msg")
- result = eop.test_id__waitfe_msg(response, atoi(param1.c_str()), it->dump(4), strict); // get the object as string (always indentation = 4)
- else
- result = eop.test_id__waitfc_msg(response, atoi(param1.c_str()), it->dump(4), strict); // get the object as string (always indentation = 4)
+ result = eop.test_id__waitfefc_msg(response, atoi(param1.c_str()), (opType == "/testid-waitfe-msg"), it->dump(4), strict); // get the object as string (always indentation = 4)
}
else
response += "missing 'diameterJson' object field";
}
else if ((opType == "/testid-waitfe")||(opType == "/testid-waitfc")) {
auto it = j.find("condition");
- if (it != j.end()) {
+ if (it != j.end() && it->is_object()) {
+
+/*
+ auto j2 = it->get<nlohmann::json::object_t>();
+
+ // [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");
auto it_imsi = it->find("imsi");
auto it_serviceContextId = it->find("serviceContextId");
- std::string condition;
- condition += (it_code != it->end()) ? *it_code : ""; condition += "|";
- condition += (it_bitR != it->end()) ? *it_bitR : ""; condition += "|";
- condition += (it_hopByHop != it->end()) ? *it_hopByHop : ""; condition += "|";
- condition += (it_applicationId != it->end()) ? *it_applicationId : ""; condition += "|";
- condition += (it_sessionId != it->end()) ? *it_sessionId : ""; condition += "|";
- condition += (it_resultCode != it->end()) ? *it_resultCode : ""; condition += "|";
- condition += (it_msisdn != it->end()) ? *it_msisdn : ""; condition += "|";
- condition += (it_imsi != it->end()) ? *it_imsi : ""; condition += "|";
- condition += (it_serviceContextId != it->end()) ? *it_serviceContextId : "";
-
- if (opType == "/testid-waitfe")
- result = eop.test_id__waitfe(response, atoi(param1.c_str()), condition);
- else
- result = eop.test_id__waitfc(response, atoi(param1.c_str()), condition);
+ std::string p1 = (it_code != it->end() && it_code->is_string()) ? *it_code : "";
+ std::string p2 = (it_bitR != it->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 : "";
+
+ result = eop.test_id__waitfefc(response, atoi(param1.c_str()), (opType == "/testid-waitfe"), p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
else
response += "missing 'condition' object field";
// test__<command>
else if (opType == "/test-ttps") {
auto it = j.find("amount");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test__ttps(response, it->get<int>());
else
response += "missing 'amount' integer field";
}
else if (opType == "/test-next") {
auto it = j.find("syncAmount");
- int syncAmount = (it != j.end()) ? it->get<int>() : 1;
+ int syncAmount = (it != j.end() && it->is_number_integer()) ? it->get<int>() : 1;
result = eop.test__next(response, syncAmount);
}
else if (opType == "/test-ip-limit") {
auto it = j.find("amount");
- int amount = (it != j.end()) ? it->get<int>() : -2; // default is: show current ip-limit and in-progress test cases amount
+ int amount = (it != j.end() && it->is_number_integer()) ? it->get<int>() : -2; // default is: show current ip-limit and in-progress test cases amount
result = eop.test__ip_limit(response, amount);
}
else if (opType == "/test-goto") {
auto it = j.find("id");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test__goto(response, it->get<int>());
else
response += "missing 'id' integer field";
}
else if (opType == "/test-run") {
auto it = j.find("id");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test__run(response, it->get<int>());
else
response += "missing 'id' integer field";
}
else if (opType == "/test-look") {
auto it = j.find("id");
- int id = (it != j.end()) ? it->get<int>() : -1; // default is: current
+ int id = (it != j.end() && it->is_number_integer()) ? it->get<int>() : -1; // default is: current
result = eop.test__look(response, id);
}
else if (opType == "/test-state") {
auto it = j.find("id");
- int id = (it != j.end()) ? it->get<int>() : -1; // default is: current
+ int id = (it != j.end() && it->is_number_integer()) ? it->get<int>() : -1; // default is: current
result = eop.test__state(response, id);
}
else if (opType == "/test-interact") {
auto it = j.find("amount");
- if (it != j.end()) {
+ if (it != j.end() && it->is_number_integer()) {
auto itI = j.find("id");
- int id = (itI != j.end()) ? itI->get<int>() : -1; // default is: current
+ int id = (itI != j.end() && itI->is_number_integer()) ? itI->get<int>() : -1; // default is: current
result = eop.test__interact(response, it->get<int>(), id);
}
}
else if (opType == "/test-reset") {
auto it = j.find("type");
- if (it != j.end()) {
+ std::string type = (it != j.end() && it->is_string()) ? *it : "soft";
- auto itI = j.find("id");
- int id = (itI != j.end()) ? itI->get<int>() : -2; // default is: apply to all the tests
+ auto itI = j.find("id");
+ int id = (itI != j.end() && itI->is_number_integer()) ? itI->get<int>() : -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");
- if (it != j.end())
+ if (it != j.end() && it->is_number_integer())
result = eop.test__repeats(response, it->get<int>());
else
response += "missing 'amount' integer field";
}
else if (opType == "/test-auto-reset") {
auto it = j.find("type");
- if (it != j.end()) {
+ if (it != j.end() && it->is_string()) {
if ((*it == "soft") || (*it == "hard")) {
result = eop.test__auto_reset(response, (*it == "soft"));
}
else if (opType == "/test-junit") {
auto it = j.find("targetFile");
- std::string targetFile = (it != j.end()) ? *it : ""; // default is: get junit on response instead dumping on file
+ 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") {
}
else if (opType == "/test-report") {
auto it = j.find("state");
- std::string state = (it != j.end()) ? *it : "all"; // initialized|in-progress|failed|success|[all]|none
+ std::string state = (it != j.end() && it->is_string()) ? *it : "all"; // initialized|in-progress|failed|success|[all]|none
auto itA = j.find("action");
- std::string action = (itA != j.end()) ? *itA : "enable"; // default is: enable
+ std::string action = (itA != j.end() && itA->is_string()) ? *itA : "enable"; // default is: enable
if ((action == "enable") || (action == "disable")) {
result = eop.test__report(response, state, (action == "enable"));
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 : "enable"; // default is: enable
+ std::string action = (itA != j.end() && itA->is_string()) ? *itA : "enable"; // default is: enable
if ((action == "enable") || (action == "disable")) {
bool enable = (action == "enable");